--- trunk/xvidcore/src/image/image.c 2005/09/09 12:18:10 1631 +++ trunk/xvidcore/src/image/image.c 2006/11/11 05:07:25 1760 @@ -19,7 +19,7 @@ * 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.32 2005-09-09 12:18:10 suxen_drol Exp $ + * $Id: image.c,v 1.40 2006-11-11 05:07:25 chl Exp $ * ****************************************************************************/ @@ -34,6 +34,7 @@ #include "interpolate8x8.h" #include "../utils/mem_align.h" #include "../motion/sad.h" +#include "../utils/emms.h" #include "font.h" /* XXX: remove later */ @@ -236,12 +237,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, @@ -249,19 +249,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 = refv; n_ptr -= offset; h_ptr -= offset; @@ -290,8 +285,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; @@ -307,7 +302,7 @@ } } else { - hv_ptr = refhv->y; + hv_ptr = refhv; hv_ptr -= offset; for (y = 0; y < (edged_height - EDGE_SIZE); y += 8) { @@ -333,123 +328,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); - */ } @@ -595,6 +473,14 @@ interlacing?abgri_to_yv12_c:abgr_to_yv12_c, 4); break; + case XVID_CSP_RGB: + 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?rgbi_to_yv12 :rgb_to_yv12, + interlacing?rgbi_to_yv12_c:rgb_to_yv12_c, 3); + break; + case XVID_CSP_RGBA : safe_packed_conv( src[0], src_stride[0], image->y, image->u, image->v, @@ -771,6 +657,14 @@ interlacing?yv12_to_abgri_c:yv12_to_abgr_c, 4); return 0; + case XVID_CSP_RGB: + 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_rgbi :yv12_to_rgb, + interlacing?yv12_to_rgbi_c:yv12_to_rgb_c, 4); + return 0; + case XVID_CSP_RGBA: safe_packed_conv( dst[0], dst_stride[0], image->y, image->u, image->v, @@ -1137,3 +1031,70 @@ p += edged_width/2; } } + +/****************************************************************************/ + +static void (*deintl_core)(uint8_t *, int width, int height, const int stride) = 0; +extern void xvid_deinterlace_sse(uint8_t *, int width, int height, const int stride); + +#define CLIP_255(x) ( ((x)&~255) ? ((-(x)) >> (8*sizeof((x))-1))&0xff : (x) ) + +static void deinterlace_c(uint8_t *pix, int width, int height, const int bps) +{ + pix += bps; + while(width-->0) + { + int p1 = pix[-bps]; + int p2 = pix[0]; + int p0 = p2; + int j = (height>>1) - 1; + int V; + unsigned char *P = pix++; + while(j-->0) + { + const int p3 = P[ bps]; + const int p4 = P[2*bps]; + V = ((p1+p3+1)>>1) + ((p2 - ((p0+p4+1)>>1)) >> 2); + P[0] = CLIP_255( V ); + p0 = p2; + p1 = p3; + p2 = p4; + P += 2*bps; + } + V = ((p1+p1+1)>>1) + ((p2 - ((p0+p2+1)>>1)) >> 2); + P[0] = CLIP_255( V ); + } +} +#undef CLIP_255 + +int xvid_image_deinterlace(xvid_image_t* img, int width, int height, int bottom_first) +{ + if (height&1) + return 0; + if (img->csp!=XVID_CSP_PLANAR && img->csp!=XVID_CSP_I420 && img->csp!=XVID_CSP_YV12) + return 0; /* not yet supported */ + if (deintl_core==0) { + deintl_core = deinterlace_c; +#ifdef ARCH_IS_IA32 + { + int cpu_flags = check_cpu_features(); + if (cpu_flags & XVID_CPU_MMX) + deintl_core = xvid_deinterlace_sse; + } +#endif + } + if (!bottom_first) { + deintl_core(img->plane[0], width, height, img->stride[0]); + deintl_core(img->plane[1], width>>1, height>>1, img->stride[1]); + deintl_core(img->plane[2], width>>1, height>>1, img->stride[2]); + } + else { + deintl_core((uint8_t *)img->plane[0] + ( height -1)*img->stride[0], width, height, -img->stride[0]); + deintl_core((uint8_t *)img->plane[1] + ((height>>1)-1)*img->stride[1], width>>1, height>>1, -img->stride[1]); + deintl_core((uint8_t *)img->plane[2] + ((height>>1)-1)*img->stride[2], width>>1, height>>1, -img->stride[2]); + } + emms(); + + return 1; +} +