From e40a51fa08304f6d0f109563c9a3ef5f1f2c41d2 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 5 Nov 2004 14:58:50 +0000 Subject: [PATCH] gst/ffmpegcolorspace/: More stride fixes. Original commit message from CVS: * gst/ffmpegcolorspace/gstffmpegcodecmap.c: (gst_ffmpegcsp_avpicture_fill): * gst/ffmpegcolorspace/imgconvert.c: (avpicture_get_size), (yuv422p_to_yuv422), (yuv420p_to_yuv422), (shrink12), (img_convert), (deinterlace_line), (deinterlace_line_inplace): More stride fixes. --- ChangeLog | 9 ++++++++ gst/ffmpegcolorspace/gstffmpegcodecmap.c | 19 +++++++++++------ gst/ffmpegcolorspace/imgconvert.c | 36 ++++++++++++++++++++++++++++++-- 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0cdd4c8..92e1906 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2004-11-05 Wim Taymans + * gst/ffmpegcolorspace/gstffmpegcodecmap.c: + (gst_ffmpegcsp_avpicture_fill): + * gst/ffmpegcolorspace/imgconvert.c: (avpicture_get_size), + (yuv422p_to_yuv422), (yuv420p_to_yuv422), (shrink12), + (img_convert), (deinterlace_line), (deinterlace_line_inplace): + More stride fixes. + +2004-11-05 Wim Taymans + * gst/alpha/gstalpha.c: (gst_alpha_set_property), (gst_alpha_add), (gst_alpha_chroma_key), (gst_alpha_init_params), (gst_alpha_chain): * gst/videomixer/videomixer.c: (gst_videomixer_blend_ayuv_i420), diff --git a/gst/ffmpegcolorspace/gstffmpegcodecmap.c b/gst/ffmpegcolorspace/gstffmpegcodecmap.c index 0e5d5a3..48ddf17 100644 --- a/gst/ffmpegcolorspace/gstffmpegcodecmap.c +++ b/gst/ffmpegcolorspace/gstffmpegcodecmap.c @@ -671,7 +671,12 @@ static PixFmtInfo pix_fmt_info[PIX_FMT_NB] = { }, }; -#define ROUND_UP_4(x) (((x) + 3) & ~3) +#define GEN_MASK(x) ((1<<(x))-1) +#define ROUND_UP_X(v,x) (((v) + GEN_MASK(x)) & ~GEN_MASK(x)) +#define ROUND_UP_2(x) ROUND_UP_X (x, 1) +#define ROUND_UP_4(x) ROUND_UP_X (x, 2) +#define ROUND_UP_8(x) ROUND_UP_X (x, 3) +#define DIV_ROUND_UP_X(v,x) (((v) + GEN_MASK(x)) >> (x)) int gst_ffmpegcsp_avpicture_fill (AVPicture * picture, @@ -682,8 +687,7 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture, PixFmtInfo *pinfo; pinfo = &pix_fmt_info[pix_fmt]; - stride = ROUND_UP_4 (width); - size = stride * height; + switch (pix_fmt) { case PIX_FMT_YUV420P: case PIX_FMT_YUV422P: @@ -694,10 +698,11 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture, case PIX_FMT_YUVJ422P: case PIX_FMT_YUVJ444P: stride = ROUND_UP_4 (width); - size = stride * height; - w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift; + h2 = ROUND_UP_X (height, pinfo->y_chroma_shift); + size = stride * h2; + w2 = DIV_ROUND_UP_X (width, pinfo->x_chroma_shift); stride2 = ROUND_UP_4 (w2); - h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift; + h2 = DIV_ROUND_UP_X (height, pinfo->y_chroma_shift); size2 = stride2 * h2; picture->data[0] = ptr; picture->data[1] = picture->data[0] + size; @@ -736,6 +741,8 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture, return size; case PIX_FMT_UYVY411: /* FIXME, probably not the right stride */ + stride = ROUND_UP_4 (width); + size = stride * height; picture->data[0] = ptr; picture->data[1] = NULL; picture->data[2] = NULL; diff --git a/gst/ffmpegcolorspace/imgconvert.c b/gst/ffmpegcolorspace/imgconvert.c index bb8a5d8..c3945be 100644 --- a/gst/ffmpegcolorspace/imgconvert.c +++ b/gst/ffmpegcolorspace/imgconvert.c @@ -760,6 +760,10 @@ yuv422p_to_yuv422 (AVPicture * dst, const AVPicture * src, cb++; cr++; } + if (w) { + p[0] = lum[0]; + p[1] = cb[0]; + } p1 += dst->linesize[0]; lum1 += src->linesize[0]; cb1 += src->linesize[1]; @@ -866,12 +870,37 @@ yuv420p_to_yuv422 (AVPicture * dst, const AVPicture * src, *line2++ = *lum2++; *line1++ = *line2++ = *cr1++; } + /* odd width */ + if (w) { + *line1++ = *lum1++; + *line2++ = *lum2++; + *line1++ = *line2++ = *cb1++; + } linesrc += dst->linesize[0] * 2; lumsrc += src->linesize[0] * 2; cb2 += src->linesize[1]; cr2 += src->linesize[2]; } + /* odd height */ + if (h) { + line1 = linesrc; + lum1 = lumsrc; + cb1 = cb2; + cr1 = cr2; + + for (w = width / 2; w--;) { + *line1++ = *lum1++; + *line1++ = *cb1++; + *line1++ = *lum1++; + *line1++ = *cr1++; + } + /* odd width */ + if (w) { + *line1++ = *lum1++; + *line1++ = *cb1++; + } + } } #define SCALEBITS 10 @@ -1938,11 +1967,14 @@ img_convert (AVPicture * dst, int dst_pix_fmt, img_copy_plane (dst->data[0], dst->linesize[0], src->data[0], src->linesize[0], dst_width, dst_height); +#define GEN_MASK(x) ((1<<(x))-1) +#define DIV_ROUND_UP_X(v,x) (((v) + GEN_MASK(x)) >> (x)) + for (i = 1; i <= 2; i++) resize_func (dst->data[i], dst->linesize[i], src->data[i], src->linesize[i], - dst_width >> dst_pix->x_chroma_shift, - dst_height >> dst_pix->y_chroma_shift); + DIV_ROUND_UP_X (dst_width, dst_pix->x_chroma_shift), + DIV_ROUND_UP_X (dst_height, dst_pix->y_chroma_shift)); /* if yuv color space conversion is needed, we do it here on the destination image */ if (dst_pix->color_type != src_pix->color_type) { -- 2.7.4