--- image.c 2003/12/12 08:19:13 1.26.2.12 +++ image.c 2004/12/05 13:56:13 1.30 @@ -3,7 +3,7 @@ * XVID MPEG-4 VIDEO CODEC * - Image management functions - * - * Copyright(C) 2001-2003 Peter Ross + * Copyright(C) 2001-2004 Peter Ross * * This program is free software ; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,22 +19,21 @@ * along with this program ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: image.c,v 1.26.2.12 2003/12/12 08:19:13 chl Exp $ + * $Id: image.c,v 1.30 2004/12/05 13:56:13 syskin Exp $ * ****************************************************************************/ #include #include /* memcpy, memset */ #include - #include "../portab.h" #include "../global.h" /* XVID_CSP_XXX's */ #include "../xvid.h" /* XVID_CSP_XXX's */ #include "image.h" #include "colorspace.h" #include "interpolate8x8.h" -#include "reduced.h" #include "../utils/mem_align.h" +#include "../motion/sad.h" #include "font.h" /* XXX: remove later */ @@ -127,13 +126,16 @@ memcpy(image1->v, image2->v, edged_width * height / 4); } +/* setedges bug was fixed in this BS version */ +#define SETEDGES_BUG_BEFORE 18 void image_setedges(IMAGE * image, uint32_t edged_width, uint32_t edged_height, uint32_t width, - uint32_t height) + uint32_t height, + int bs_version) { const uint32_t edged_width2 = edged_width / 2; uint32_t width2; @@ -141,14 +143,16 @@ uint8_t *dst; uint8_t *src; - dst = image->y - (EDGE_SIZE + EDGE_SIZE * edged_width); src = image->y; /* According to the Standard Clause 7.6.4, padding is done starting at 16 - * pixel width and height multiples */ - width = (width+15)&~15; - height = (height+15)&~15; + * pixel width and height multiples. This was not respected in old xvids */ + if (bs_version == 0 || bs_version >= SETEDGES_BUG_BEFORE) { + width = (width+15)&~15; + height = (height+15)&~15; + } + width2 = width/2; for (i = 0; i < EDGE_SIZE; i++) { @@ -598,6 +602,14 @@ interlacing?rgbai_to_yv12 :rgba_to_yv12, interlacing?rgbai_to_yv12_c:rgba_to_yv12_c, 4); break; + + case XVID_CSP_ARGB: + safe_packed_conv( + src[0], src_stride[0], image->y, image->u, image->v, + edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), + interlacing?argbi_to_yv12 : argb_to_yv12, + interlacing?argbi_to_yv12_c: argb_to_yv12_c, 4); + break; case XVID_CSP_YUY2: safe_packed_conv( @@ -609,7 +621,7 @@ case XVID_CSP_YVYU: /* u/v swapped */ safe_packed_conv( - src[0], src_stride[0], image->y, image->v, image->y, + src[0], src_stride[0], image->y, image->v, image->u, edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), interlacing?yuyvi_to_yv12 :yuyv_to_yv12, interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2); @@ -623,19 +635,19 @@ interlacing?uyvyi_to_yv12_c:uyvy_to_yv12_c, 2); break; - case XVID_CSP_I420: /* YCrCb == internal colorspace for MPEG */ + case XVID_CSP_I420: /* YCbCr == YUV == internal colorspace for MPEG */ yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2, src[0], src[0] + src_stride[0]*height, src[0] + src_stride[0]*height + (src_stride[0]/2)*height2, src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP)); break; - - case XVID_CSP_YV12: /* YCbCr == U and V plane swapped */ + + case XVID_CSP_YV12: /* YCrCb == YVA == U and V plane swapped */ yv12_to_yv12(image->y, image->v, image->u, edged_width, edged_width2, src[0], src[0] + src_stride[0]*height, src[0] + src_stride[0]*height + (src_stride[0]/2)*height2, src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP)); break; - case XVID_CSP_USER : /* YCrCb with arbitrary pointers and different strides for Y and UV */ + case XVID_CSP_PLANAR: /* YCbCr with arbitrary pointers and different strides for Y and UV */ yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2, src[0], src[1], src[2], src_stride[0], src_stride[1], /* v: dst_stride[2] not yet supported */ width, height, (csp & XVID_CSP_VFLIP)); @@ -767,6 +779,14 @@ interlacing?yv12_to_rgbai_c:yv12_to_rgba_c, 4); return 0; + case XVID_CSP_ARGB: + safe_packed_conv( + dst[0], dst_stride[0], image->y, image->u, image->v, + edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), + interlacing?yv12_to_argbi :yv12_to_argb, + interlacing?yv12_to_argbi_c:yv12_to_argb_c, 4); + return 0; + case XVID_CSP_YUY2: safe_packed_conv( dst[0], dst_stride[0], image->y, image->u, image->v, @@ -791,21 +811,21 @@ interlacing?yv12_to_uyvyi_c:yv12_to_uyvy_c, 2); return 0; - case XVID_CSP_I420: /* YCrCb == internal colorspace for MPEG */ + case XVID_CSP_I420: /* YCbCr == YUV == internal colorspace for MPEG */ yv12_to_yv12(dst[0], dst[0] + dst_stride[0]*height, dst[0] + dst_stride[0]*height + (dst_stride[0]/2)*height2, dst_stride[0], dst_stride[0]/2, image->y, image->u, image->v, edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP)); return 0; - case XVID_CSP_YV12: /* YCbCr == U and V plane swapped */ + case XVID_CSP_YV12: /* YCrCb == YVU == U and V plane swapped */ yv12_to_yv12(dst[0], dst[0] + dst_stride[0]*height, dst[0] + dst_stride[0]*height + (dst_stride[0]/2)*height2, dst_stride[0], dst_stride[0]/2, image->y, image->v, image->u, edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP)); return 0; - case XVID_CSP_USER : /* YCrCb with arbitrary pointers and different strides for Y and UV */ + case XVID_CSP_PLANAR: /* YCbCr with arbitrary pointers and different strides for Y and UV */ yv12_to_yv12(dst[0], dst[1], dst[2], dst_stride[0], dst_stride[1], /* v: dst_stride[2] not yet supported */ image->y, image->u, image->v, edged_width, edged_width2, @@ -872,24 +892,64 @@ } -long plane_sse(uint8_t * orig, - uint8_t * recon, - uint16_t stride, - uint16_t width, - uint16_t height) +long plane_sse(uint8_t *orig, + uint8_t *recon, + uint16_t stride, + uint16_t width, + uint16_t height) { - int diff, x, y; - long sse=0; + int y, bwidth, bheight; + long sse = 0; - for (y = 0; y < height; y++) { + bwidth = width & (~0x07); + bheight = height & (~0x07); + + /* Compute the 8x8 integer part */ + for (y = 0; yy + (j*block - 1)*edged_width + i*block, - img->y + (j*block + 0)*edged_width + i*block, nblocks); - } - } - - for (j = 0; j < mb_height*2; j++) /* vertical deblocking */ - for (i = 1; i < mb_width*2; i++) - { - if (mbs[(j/2)*mb_stride + (i-1)/2].mode != MODE_NOT_CODED || - mbs[(j/2)*mb_stride + (i+0)/2].mode != MODE_NOT_CODED) - { - vfilter_31(img->y + (j*block)*edged_width + i*block - 1, - img->y + (j*block)*edged_width + i*block + 0, - edged_width, nblocks); - } - } - - - - /* chroma */ - - for (j = 1; j < mb_height; j++) /* horizontal deblocking */ - for (i = 0; i < mb_width; i++) - { - if (mbs[(j-1)*mb_stride + i].mode != MODE_NOT_CODED || - mbs[(j+0)*mb_stride + i].mode != MODE_NOT_CODED) - { - hfilter_31(img->u + (j*block - 1)*edged_width2 + i*block, - img->u + (j*block + 0)*edged_width2 + i*block, nblocks); - hfilter_31(img->v + (j*block - 1)*edged_width2 + i*block, - img->v + (j*block + 0)*edged_width2 + i*block, nblocks); - } - } - - for (j = 0; j < mb_height; j++) /* vertical deblocking */ - for (i = 1; i < mb_width; i++) - { - if (mbs[j*mb_stride + i - 1].mode != MODE_NOT_CODED || - mbs[j*mb_stride + i + 0].mode != MODE_NOT_CODED) - { - vfilter_31(img->u + (j*block)*edged_width2 + i*block - 1, - img->u + (j*block)*edged_width2 + i*block + 0, - edged_width2, nblocks); - vfilter_31(img->v + (j*block)*edged_width2 + i*block - 1, - img->v + (j*block)*edged_width2 + i*block + 0, - edged_width2, nblocks); - } - } - - -} -