comparison imgconvert.c @ 3257:63f61b09dcee libavcodec

Baptiste COUDURIER's padding patch (reworked by me a little bit). Moves padding code to imgconvert.c, and enables padding colorspaces != YUV420P.
author lucabe
date Mon, 10 Apr 2006 07:45:29 +0000
parents c2c29be6282e
children 3b785e80ce3e
comparison
equal deleted inserted replaced
3256:aec4f27b1248 3257:63f61b09dcee
1996 dst->linesize[1] = src->linesize[1]; 1996 dst->linesize[1] = src->linesize[1];
1997 dst->linesize[2] = src->linesize[2]; 1997 dst->linesize[2] = src->linesize[2];
1998 return 0; 1998 return 0;
1999 } 1999 }
2000 2000
2001 /**
2002 * Pad image
2003 */
2004 int img_pad(AVPicture *dst, const AVPicture *src, int height, int width, int pix_fmt,
2005 int padtop, int padbottom, int padleft, int padright, int *color)
2006 {
2007 uint8_t *optr, *iptr;
2008 int y_shift;
2009 int x_shift;
2010 int yheight;
2011 int i, y;
2012
2013 if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB || !is_yuv_planar(&pix_fmt_info[pix_fmt]))
2014 return -1;
2015
2016 for (i = 0; i < 3; i++) {
2017 x_shift = i ? pix_fmt_info[pix_fmt].x_chroma_shift : 0;
2018 y_shift = i ? pix_fmt_info[pix_fmt].y_chroma_shift : 0;
2019
2020 if (padtop || padleft) {
2021 memset(dst->data[i], color[i], dst->linesize[i] * (padtop >> y_shift) + (padleft >> x_shift));
2022 }
2023
2024 if (padleft || padright || src) {
2025 if (src) { /* first line */
2026 iptr = src->data[i];
2027 optr = dst->data[i] + dst->linesize[i] * (padtop >> y_shift) + (padleft >> x_shift);
2028 memcpy(optr, iptr, src->linesize[i]);
2029 iptr += src->linesize[i];
2030 }
2031 optr = dst->data[i] + dst->linesize[i] * (padtop >> y_shift) + (dst->linesize[i] - (padright >> x_shift));
2032 yheight = (height - 1 - (padtop + padbottom)) >> y_shift;
2033 for (y = 0; y < yheight; y++) {
2034 memset(optr, color[i], (padleft + padright) >> x_shift);
2035 if (src) {
2036 memcpy(optr + ((padleft + padright) >> x_shift), iptr, src->linesize[i]);
2037 iptr += src->linesize[i];
2038 }
2039 optr += dst->linesize[i];
2040 }
2041 }
2042
2043 if (padbottom || padright) {
2044 optr = dst->data[i] + dst->linesize[i] * ((height - padbottom) >> y_shift) - (padright >> x_shift);
2045 memset(optr, color[i], dst->linesize[i] * (padbottom >> y_shift) + (padright >> x_shift));
2046 }
2047 }
2048 return 0;
2049 }
2050
2001 /* XXX: always use linesize. Return -1 if not supported */ 2051 /* XXX: always use linesize. Return -1 if not supported */
2002 int img_convert(AVPicture *dst, int dst_pix_fmt, 2052 int img_convert(AVPicture *dst, int dst_pix_fmt,
2003 const AVPicture *src, int src_pix_fmt, 2053 const AVPicture *src, int src_pix_fmt,
2004 int src_width, int src_height) 2054 int src_width, int src_height)
2005 { 2055 {