Commit f2651e7a authored by Baptiste Coudurier's avatar Baptiste Coudurier

Fix cropping, depending on enc pix fmt

Originally committed as revision 5134 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 4c4a4e9a
......@@ -847,20 +847,10 @@ static void do_video_out(AVFormatContext *s,
}
}
} else if (ost->video_crop) {
picture_crop_temp.data[0] = formatted_picture->data[0] +
(ost->topBand * formatted_picture->linesize[0]) + ost->leftBand;
picture_crop_temp.data[1] = formatted_picture->data[1] +
((ost->topBand >> 1) * formatted_picture->linesize[1]) +
(ost->leftBand >> 1);
picture_crop_temp.data[2] = formatted_picture->data[2] +
((ost->topBand >> 1) * formatted_picture->linesize[2]) +
(ost->leftBand >> 1);
picture_crop_temp.linesize[0] = formatted_picture->linesize[0];
picture_crop_temp.linesize[1] = formatted_picture->linesize[1];
picture_crop_temp.linesize[2] = formatted_picture->linesize[2];
if (img_crop((AVPicture *)&picture_crop_temp, (AVPicture *)formatted_picture, enc->pix_fmt, ost->topBand, ost->leftBand) < 0) {
av_log(NULL, AV_LOG_ERROR, "error cropping picture\n");
goto the_end;
}
final_picture = &picture_crop_temp;
} else if (ost->video_pad) {
final_picture = &ost->pict_tmp;
......
......@@ -2555,6 +2555,9 @@ int is_adx(const unsigned char *buf,size_t bufsize);
void img_copy(AVPicture *dst, const AVPicture *src,
int pix_fmt, int width, int height);
int img_crop(AVPicture *dst, const AVPicture *src,
int pix_fmt, int top_band, int left_band);
/* av_log API */
#include <stdarg.h>
......
......@@ -1951,6 +1951,31 @@ static inline int is_yuv_planar(PixFmtInfo *ps)
ps->pixel_type == FF_PIXEL_PLANAR;
}
/**
* Crop image top and left side
*/
int img_crop(AVPicture *dst, const AVPicture *src,
int pix_fmt, int top_band, int left_band)
{
int y_shift;
int x_shift;
if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB || !is_yuv_planar(&pix_fmt_info[pix_fmt]))
return -1;
y_shift = pix_fmt_info[pix_fmt].y_chroma_shift;
x_shift = pix_fmt_info[pix_fmt].x_chroma_shift;
dst->data[0] = src->data[0] + (top_band * src->linesize[0]) + left_band;
dst->data[1] = src->data[1] + ((top_band >> y_shift) * src->linesize[1]) + (left_band >> x_shift);
dst->data[2] = src->data[2] + ((top_band >> y_shift) * src->linesize[2]) + (left_band >> x_shift);
dst->linesize[0] = src->linesize[0];
dst->linesize[1] = src->linesize[1];
dst->linesize[2] = src->linesize[2];
return 0;
}
/* XXX: always use linesize. Return -1 if not supported */
int img_convert(AVPicture *dst, int dst_pix_fmt,
const AVPicture *src, int src_pix_fmt,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment