diff options
author | Luca Abeni <lucabe72@email.it> | 2006-04-10 07:45:29 +0000 |
---|---|---|
committer | Luca Abeni <lucabe72@email.it> | 2006-04-10 07:45:29 +0000 |
commit | 5341c20954b8207de0b04658232db93c60bd3db8 (patch) | |
tree | 21c18509746e634eaaeaabacf8f1a079c4643b04 /libavcodec/imgconvert.c | |
parent | 7b98bcbd0f88009ea4cf4e985098cbac1f9a220e (diff) | |
download | ffmpeg-5341c20954b8207de0b04658232db93c60bd3db8.tar.gz |
Baptiste COUDURIER's padding patch (reworked by me a little bit).
Moves padding code to imgconvert.c, and enables padding colorspaces != YUV420P.
Originally committed as revision 5278 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/imgconvert.c')
-rw-r--r-- | libavcodec/imgconvert.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c index 5abbabc2a2..d066d40d35 100644 --- a/libavcodec/imgconvert.c +++ b/libavcodec/imgconvert.c @@ -1998,6 +1998,56 @@ int img_crop(AVPicture *dst, const AVPicture *src, return 0; } +/** + * Pad image + */ +int img_pad(AVPicture *dst, const AVPicture *src, int height, int width, int pix_fmt, + int padtop, int padbottom, int padleft, int padright, int *color) +{ + uint8_t *optr, *iptr; + int y_shift; + int x_shift; + int yheight; + int i, y; + + if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB || !is_yuv_planar(&pix_fmt_info[pix_fmt])) + return -1; + + for (i = 0; i < 3; i++) { + x_shift = i ? pix_fmt_info[pix_fmt].x_chroma_shift : 0; + y_shift = i ? pix_fmt_info[pix_fmt].y_chroma_shift : 0; + + if (padtop || padleft) { + memset(dst->data[i], color[i], dst->linesize[i] * (padtop >> y_shift) + (padleft >> x_shift)); + } + + if (padleft || padright || src) { + if (src) { /* first line */ + iptr = src->data[i]; + optr = dst->data[i] + dst->linesize[i] * (padtop >> y_shift) + (padleft >> x_shift); + memcpy(optr, iptr, src->linesize[i]); + iptr += src->linesize[i]; + } + optr = dst->data[i] + dst->linesize[i] * (padtop >> y_shift) + (dst->linesize[i] - (padright >> x_shift)); + yheight = (height - 1 - (padtop + padbottom)) >> y_shift; + for (y = 0; y < yheight; y++) { + memset(optr, color[i], (padleft + padright) >> x_shift); + if (src) { + memcpy(optr + ((padleft + padright) >> x_shift), iptr, src->linesize[i]); + iptr += src->linesize[i]; + } + optr += dst->linesize[i]; + } + } + + if (padbottom || padright) { + optr = dst->data[i] + dst->linesize[i] * ((height - padbottom) >> y_shift) - (padright >> x_shift); + memset(optr, color[i], dst->linesize[i] * (padbottom >> y_shift) + (padright >> x_shift)); + } + } + 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, |