--- branches/dev-api-4/xvidcore/src/image/image.c 2003/05/17 13:37:49 1032 +++ branches/dev-api-4/xvidcore/src/image/image.c 2003/09/29 00:30:31 1157 @@ -1,68 +1,42 @@ /************************************************************************** * - * XVID MPEG-4 VIDEO CODEC - * image stuff + * XVID MPEG-4 VIDEO CODEC + * - Image management functions - * - * This program is an implementation of a part of one or more MPEG-4 - * Video tools as specified in ISO/IEC 14496-2 standard. Those intending - * to use this software module in hardware or software products are - * advised that its use may infringe existing patents or copyrights, and - * any such use would be at such party's own risk. The original - * developer of this software module and his/her company, and subsequent - * editors and their companies, will have no liability for use of this - * software or modifications or derivatives thereof. + * Copyright(C) 2001-2003 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * 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 + * the Free Software Foundation ; either version 2 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY ; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * You should have received a copy of the GNU General Public License + * along with this program ; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - *************************************************************************/ - -/************************************************************************** - * - * History: + * $Id: image.c,v 1.26.2.9 2003-09-29 00:30:31 edgomez Exp $ * - * 05.10.2002 support for interpolated images in qpel mode - Isibaar - * 01.05.2002 BFRAME image-based u,v interpolation - * 22.04.2002 added some B-frame support - * 14.04.2002 added image_dump_yuvpgm(), added image_mad() - * XVID_CSP_USER input support - * 09.04.2002 PSNR calculations - Isibaar - * 06.04.2002 removed interlaced edging from U,V blocks (as per spec) - * 26.03.2002 interlacing support (field-based edging in set_edges) - * 26.01.2002 rgb555, rgb565 - * 07.01.2001 commented u,v interpolation (not required for uv-block-based) - * 23.12.2001 removed #ifdefs, added function pointers + init_common() - * 22.12.2001 cpu #ifdefs - * 19.12.2001 image_dump(); useful for debugging - * 6.12.2001 inital version; (c)2001 peter ross - * - *************************************************************************/ + ****************************************************************************/ #include -#include // memcpy, memset +#include /* memcpy, memset */ #include #include "../portab.h" -#include "../global.h" // XVID_CSP_XXX's -#include "../xvid.h" // XVID_CSP_XXX's +#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 "font.h" // XXX: remove later +#include "font.h" /* XXX: remove later */ #define SAFETY 64 #define EDGE_SIZE2 (EDGE_SIZE/2) @@ -75,29 +49,31 @@ { const uint32_t edged_width2 = edged_width / 2; const uint32_t edged_height2 = edged_height / 2; - uint32_t i; image->y = xvid_malloc(edged_width * (edged_height + 1) + SAFETY, CACHE_LINE); if (image->y == NULL) { return -1; } - - for (i = 0; i < edged_width * edged_height + SAFETY; i++) { - image->y[i] = 0; - } + memset(image->y, 0, edged_width * (edged_height + 1) + SAFETY); image->u = xvid_malloc(edged_width2 * edged_height2 + SAFETY, CACHE_LINE); if (image->u == NULL) { xvid_free(image->y); + image->y = NULL; return -1; } + memset(image->u, 0, edged_width2 * edged_height2 + SAFETY); + image->v = xvid_malloc(edged_width2 * edged_height2 + SAFETY, CACHE_LINE); if (image->v == NULL) { xvid_free(image->u); + image->u = NULL; xvid_free(image->y); + image->y = NULL; return -1; } + memset(image->v, 0, edged_width2 * edged_height2 + SAFETY); image->y += EDGE_SIZE * edged_width + EDGE_SIZE; image->u += EDGE_SIZE2 * edged_width2 + EDGE_SIZE2; @@ -117,12 +93,15 @@ if (image->y) { xvid_free(image->y - (EDGE_SIZE * edged_width + EDGE_SIZE)); + image->y = NULL; } if (image->u) { xvid_free(image->u - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2)); + image->u = NULL; } if (image->v) { xvid_free(image->v - (EDGE_SIZE2 * edged_width2 + EDGE_SIZE2)); + image->v = NULL; } } @@ -157,7 +136,7 @@ uint32_t height) { const uint32_t edged_width2 = edged_width / 2; - const uint32_t width2 = width / 2; + uint32_t width2; uint32_t i; uint8_t *dst; uint8_t *src; @@ -166,6 +145,12 @@ 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; + width2 = width/2; + for (i = 0; i < EDGE_SIZE; i++) { memset(dst, *src, EDGE_SIZE); memcpy(dst + EDGE_SIZE, src, width); @@ -191,7 +176,7 @@ } -//U + /* U */ dst = image->u - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2); src = image->u; @@ -219,7 +204,7 @@ } -// V + /* V */ dst = image->v - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2); src = image->v; @@ -247,7 +232,7 @@ } } -// bframe encoding requires image-based u,v interpolation +/* bframe encoding requires image-based u,v interpolation */ void image_interpolate(const IMAGE * refn, IMAGE * refh, @@ -258,16 +243,14 @@ uint32_t quarterpel, uint32_t rounding) { - const uint32_t offset = EDGE_SIZE2 * (edged_width + 1); // we only interpolate half of the edge area + 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; -/* -#ifdef BFRAMES +#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; @@ -501,7 +484,7 @@ #undef IMG_V } - DPRINTF(XVID_DEBUG_DEBUG,"chroma_optimized_pixels = %i/%i", pixels, width*height/4); + DPRINTF(XVID_DEBUG_DEBUG,"chroma_optimized_pixels = %i/%i\n", pixels, width*height/4); } @@ -561,7 +544,9 @@ const int edged_width2 = edged_width/2; const int width2 = width/2; const int height2 = height/2; - //const int height_signed = (csp & XVID_CSP_VFLIP) ? -height : height; +#if 0 + const int height_signed = (csp & XVID_CSP_VFLIP) ? -height : height; +#endif switch (csp & ~XVID_CSP_VFLIP) { case XVID_CSP_RGB555: @@ -790,7 +775,7 @@ interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2); return 0; - case XVID_CSP_YVYU: // u,v swapped + case XVID_CSP_YVYU: /* u,v swapped */ safe_packed_conv( dst[0], dst_stride[0], image->y, image->v, image->u, edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP), @@ -813,14 +798,14 @@ width, height, (csp & XVID_CSP_VFLIP)); return 0; - case XVID_CSP_YV12: // u,v swapped + case XVID_CSP_YV12: /* u,v 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 : // u,v swapped + case XVID_CSP_USER : /* u,v swapped */ yv12_to_yv12(dst[0], dst[1], dst[2], dst_stride[0], dst_stride[1], /* v: dst_stride[2] */ image->y, image->v, image->u, edged_width, edged_width2, @@ -883,7 +868,7 @@ if (sse==0) return 99.99F; - return 48.131F - 10*(float)log10((float)sse/(float)(pixels)); // log10(255*255)=4.8131 + return 48.131F - 10*(float)log10((float)sse/(float)(pixels)); /* log10(255*255)=4.8131 */ } @@ -907,7 +892,7 @@ return sse; } -/* +#if 0 #include #include @@ -931,7 +916,7 @@ } -// dump image+edges to yuv pgm files +/* dump image+edges to yuv pgm files */ int image_dump(IMAGE * image, uint32_t edged_width, uint32_t edged_height, char * path, int number) { @@ -954,7 +939,7 @@ return 0; } -*/ +#endif