--- image.c 2004/02/07 10:01:27 1.26.2.16 +++ image.c 2005/12/17 12:04:52 1.34 @@ -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.16 2004/02/07 10:01:27 chl Exp $ + * $Id: image.c,v 1.34 2005/12/17 12:04:52 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++) { @@ -232,12 +236,11 @@ } } -/* bframe encoding requires image-based u,v interpolation */ void -image_interpolate(const IMAGE * refn, - IMAGE * refh, - IMAGE * refv, - IMAGE * refhv, +image_interpolate(const uint8_t * refn, + uint8_t * refh, + uint8_t * refv, + uint8_t * refhv, uint32_t edged_width, uint32_t edged_height, uint32_t quarterpel, @@ -245,19 +248,14 @@ { const uint32_t offset = EDGE_SIZE2 * (edged_width + 1); /* we only interpolate half of the edge area */ const uint32_t stride_add = 7 * edged_width; -#if 0 - const uint32_t edged_width2 = edged_width / 2; - const uint32_t edged_height2 = edged_height / 2; - const uint32_t offset2 = EDGE_SIZE2 * (edged_width2 + 1); - const uint32_t stride_add2 = 7 * edged_width2; -#endif - uint8_t *n_ptr, *h_ptr, *v_ptr, *hv_ptr; - uint32_t x, y; + uint8_t *n_ptr; + uint8_t *h_ptr, *v_ptr, *hv_ptr; + uint32_t x, y; - n_ptr = refn->y; - h_ptr = refh->y; - v_ptr = refv->y; + n_ptr = (uint8_t*)refn; + h_ptr = refh; + v_ptr = refhv; n_ptr -= offset; h_ptr -= offset; @@ -286,8 +284,8 @@ n_ptr += stride_add; } - h_ptr = refh->y + (edged_height - EDGE_SIZE - EDGE_SIZE2)*edged_width - EDGE_SIZE2; - hv_ptr = refhv->y + (edged_height - EDGE_SIZE - EDGE_SIZE2)*edged_width - EDGE_SIZE2; + h_ptr = refh + (edged_height - EDGE_SIZE - EDGE_SIZE2)*edged_width - EDGE_SIZE2; + hv_ptr = refhv + (edged_height - EDGE_SIZE - EDGE_SIZE2)*edged_width - EDGE_SIZE2; for (y = 0; y < (edged_height - EDGE_SIZE); y = y + 8) { hv_ptr -= stride_add; @@ -303,7 +301,7 @@ } } else { - hv_ptr = refhv->y; + hv_ptr = refhv; hv_ptr -= offset; for (y = 0; y < (edged_height - EDGE_SIZE); y += 8) { @@ -329,123 +327,6 @@ n_ptr += stride_add; } } -/* -#ifdef BFRAMES - n_ptr = refn->u; - h_ptr = refh->u; - v_ptr = refv->u; - hv_ptr = refhv->u; - - n_ptr -= offset2; - h_ptr -= offset2; - v_ptr -= offset2; - hv_ptr -= offset2; - - for (y = 0; y < edged_height2; y += 8) { - for (x = 0; x < edged_width2; x += 8) { - interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width2, rounding); - interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width2, rounding); - interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width2, rounding); - - n_ptr += 8; - h_ptr += 8; - v_ptr += 8; - hv_ptr += 8; - } - h_ptr += stride_add2; - v_ptr += stride_add2; - hv_ptr += stride_add2; - n_ptr += stride_add2; - } - - n_ptr = refn->v; - h_ptr = refh->v; - v_ptr = refv->v; - hv_ptr = refhv->v; - - n_ptr -= offset2; - h_ptr -= offset2; - v_ptr -= offset2; - hv_ptr -= offset2; - - for (y = 0; y < edged_height2; y = y + 8) { - for (x = 0; x < edged_width2; x = x + 8) { - interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width2, rounding); - interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width2, rounding); - interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width2, rounding); - - n_ptr += 8; - h_ptr += 8; - v_ptr += 8; - hv_ptr += 8; - } - h_ptr += stride_add2; - v_ptr += stride_add2; - hv_ptr += stride_add2; - n_ptr += stride_add2; - } -#endif -*/ - /* - interpolate_halfpel_h( - refh->y - offset, - refn->y - offset, - edged_width, edged_height, - rounding); - - interpolate_halfpel_v( - refv->y - offset, - refn->y - offset, - edged_width, edged_height, - rounding); - - interpolate_halfpel_hv( - refhv->y - offset, - refn->y - offset, - edged_width, edged_height, - rounding); - */ - - /* uv-image-based compensation - offset = EDGE_SIZE2 * (edged_width / 2 + 1); - - interpolate_halfpel_h( - refh->u - offset, - refn->u - offset, - edged_width / 2, edged_height / 2, - rounding); - - interpolate_halfpel_v( - refv->u - offset, - refn->u - offset, - edged_width / 2, edged_height / 2, - rounding); - - interpolate_halfpel_hv( - refhv->u - offset, - refn->u - offset, - edged_width / 2, edged_height / 2, - rounding); - - - interpolate_halfpel_h( - refh->v - offset, - refn->v - offset, - edged_width / 2, edged_height / 2, - rounding); - - interpolate_halfpel_v( - refv->v - offset, - refn->v - offset, - edged_width / 2, edged_height / 2, - rounding); - - interpolate_halfpel_hv( - refhv->v - offset, - refn->v - offset, - edged_width / 2, edged_height / 2, - rounding); - */ } @@ -713,7 +594,7 @@ int height, uint32_t edged_width, uint8_t * dst[4], - uint32_t dst_stride[4], + int dst_stride[4], int csp, int interlacing) { @@ -888,24 +769,64 @@ } -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; +long plane_sse(uint8_t *orig, + uint8_t *recon, + uint16_t stride, + uint16_t width, + uint16_t height) +{ + int y, bwidth, bheight; + long sse = 0; + + bwidth = width & (~0x07); + bheight = height & (~0x07); + + /* Compute the 8x8 integer part */ + for (y = 0; y> 1; + int stride2 = stride >> 1; int w = mbl << 4, w2,i; if(w > width) @@ -1046,24 +967,24 @@ dY = (uint8_t*)out_frm->plane[0] + (mby << 4) * out_frm->stride[0] + (mbx << 4); dU = (uint8_t*)out_frm->plane[1] + (mby << 3) * out_frm->stride[1] + (mbx << 3); dV = (uint8_t*)out_frm->plane[2] + (mby << 3) * out_frm->stride[2] + (mbx << 3); - sY = cur->y + (mby << 4) * std + (mbx << 4); - sU = cur->u + (mby << 3) * std2 + (mbx << 3); - sV = cur->v + (mby << 3) * std2 + (mbx << 3); + sY = cur->y + (mby << 4) * stride + (mbx << 4); + sU = cur->u + (mby << 3) * stride2 + (mbx << 3); + sV = cur->v + (mby << 3) * stride2 + (mbx << 3); for(i = 0 ; i < 16 ; i++) { memcpy(dY,sY,w); dY += out_frm->stride[0]; - sY += std; + sY += stride; } for(i = 0 ; i < 8 ; i++) { memcpy(dU,sU,w2); dU += out_frm->stride[1]; - sU += std2; + sU += stride2; } for(i = 0 ; i < 8 ; i++) { memcpy(dV,sV,w2); dV += out_frm->stride[2]; - sV += std2; + sV += stride2; } } @@ -1093,78 +1014,3 @@ p += edged_width/2; } } - - -/* reduced resolution deblocking filter - block = block size (16=rrv, 8=full resolution) - flags = XVID_DEC_YDEBLOCK|XVID_DEC_UVDEBLOCK -*/ -void -image_deblock_rrv(IMAGE * img, int edged_width, - const MACROBLOCK * mbs, int mb_width, int mb_height, int mb_stride, - int block, int flags) -{ - const int edged_width2 = edged_width /2; - const int nblocks = block / 8; /* skals code uses 8pixel block uints */ - int i,j; - - /* luma: j,i in block units */ - - for (j = 1; j < mb_height*2; j++) /* horizontal deblocking */ - for (i = 0; i < mb_width*2; i++) - { - if (mbs[(j-1)/2*mb_stride + (i/2)].mode != MODE_NOT_CODED || - mbs[(j+0)/2*mb_stride + (i/2)].mode != MODE_NOT_CODED) - { - hfilter_31(img->y + (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); - } - } - - -} -