diff options
author | Baptiste Coudurier <baptiste.coudurier@gmail.com> | 2006-03-10 13:55:48 +0000 |
---|---|---|
committer | Baptiste Coudurier <baptiste.coudurier@gmail.com> | 2006-03-10 13:55:48 +0000 |
commit | f2651e7a6c7a9f492158a36af635eb4fb8ebac36 (patch) | |
tree | 20534ab9cae169e3c02019196bacf72fdf5d6efe /libavcodec/imgconvert.c | |
parent | 4c4a4e9afefc98699f0c720f363e1ce66d8a745d (diff) | |
download | ffmpeg-f2651e7a6c7a9f492158a36af635eb4fb8ebac36.tar.gz |
Fix cropping, depending on enc pix fmt
Originally committed as revision 5134 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/imgconvert.c')
-rw-r--r-- | libavcodec/imgconvert.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c index 850f9b04f4..e03706d440 100644 --- a/libavcodec/imgconvert.c +++ b/libavcodec/imgconvert.c @@ -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, |