[cvs] / xvidcore / src / image / image.c Repository:
ViewVC logotype

Diff of /xvidcore/src/image/image.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.26, Sat Feb 15 15:22:18 2003 UTC revision 1.26.2.8, Mon Aug 25 15:01:51 2003 UTC
# Line 1  Line 1 
1  /**************************************************************************  /**************************************************************************
2   *   *
3   *      XVID MPEG-4 VIDEO CODEC   *      XVID MPEG-4 VIDEO CODEC
4   *      image stuff   *  - Image management functions -
5   *   *
6   *      This program is an implementation of a part of one or more MPEG-4   *  Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
  *      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.  
7   *   *
8   *      This program is free software; you can redistribute it and/or modify   *      This program is free software; you can redistribute it and/or modify
9   *      it under the terms of the GNU General Public License as published by   *      it under the terms of the GNU General Public License as published by
# Line 24  Line 17 
17   *   *
18   *      You should have received a copy of the GNU General Public License   *      You should have received a copy of the GNU General Public License
19   *      along with this program; if not, write to the Free Software   *      along with this program; if not, write to the Free Software
20   *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21   *   *
22   *************************************************************************/   * $Id$
   
 /**************************************************************************  
  *  
  *      History:  
  *  
  *  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 <pross@cs.rmit.edu.au>  
23   *   *
24   *************************************************************************/   ****************************************************************************/
25    
26  #include <stdlib.h>  #include <stdlib.h>
27  #include <string.h>                             // memcpy, memset  #include <string.h>                             /* memcpy, memset */
28  #include <math.h>  #include <math.h>
29    
30  #include "../portab.h"  #include "../portab.h"
31  #include "../global.h"                  // XVID_CSP_XXX's  #include "../global.h"                  /* XVID_CSP_XXX's */
32  #include "../xvid.h"                    // XVID_CSP_XXX's  #include "../xvid.h"                    /* XVID_CSP_XXX's */
33  #include "image.h"  #include "image.h"
34  #include "colorspace.h"  #include "colorspace.h"
35  #include "interpolate8x8.h"  #include "interpolate8x8.h"
36  #include "reduced.h"  #include "reduced.h"
 #include "../divx4.h"  
37  #include "../utils/mem_align.h"  #include "../utils/mem_align.h"
38    
39  #include "font.h"               // XXX: remove later  #include "font.h"               /* XXX: remove later */
40    
41  #define SAFETY  64  #define SAFETY  64
42  #define EDGE_SIZE2  (EDGE_SIZE/2)  #define EDGE_SIZE2  (EDGE_SIZE/2)
# Line 132  Line 105 
105  image_swap(IMAGE * image1,  image_swap(IMAGE * image1,
106                     IMAGE * image2)                     IMAGE * image2)
107  {  {
108          uint8_t *tmp;      SWAP(uint8_t*, image1->y, image2->y);
109        SWAP(uint8_t*, image1->u, image2->u);
110          tmp = image1->y;      SWAP(uint8_t*, image1->v, image2->v);
         image1->y = image2->y;  
         image2->y = tmp;  
   
         tmp = image1->u;  
         image1->u = image2->u;  
         image2->u = tmp;  
   
         tmp = image1->v;  
         image1->v = image2->v;  
         image2->v = tmp;  
111  }  }
112    
113    
# Line 168  Line 131 
131                             uint32_t height)                             uint32_t height)
132  {  {
133          const uint32_t edged_width2 = edged_width / 2;          const uint32_t edged_width2 = edged_width / 2;
134          const uint32_t width2 = width / 2;          uint32_t width2;
135          uint32_t i;          uint32_t i;
136          uint8_t *dst;          uint8_t *dst;
137          uint8_t *src;          uint8_t *src;
# Line 177  Line 140 
140          dst = image->y - (EDGE_SIZE + EDGE_SIZE * edged_width);          dst = image->y - (EDGE_SIZE + EDGE_SIZE * edged_width);
141          src = image->y;          src = image->y;
142    
143            /* According to the Standard Clause 7.6.4, padding is done starting at 16
144             * pixel width and height multiples */
145            width  = (width+15)&~15;
146            height = (height+15)&~15;
147            width2 = width/2;
148    
149          for (i = 0; i < EDGE_SIZE; i++) {          for (i = 0; i < EDGE_SIZE; i++) {
150                  memset(dst, *src, EDGE_SIZE);                  memset(dst, *src, EDGE_SIZE);
151                  memcpy(dst + EDGE_SIZE, src, width);                  memcpy(dst + EDGE_SIZE, src, width);
# Line 202  Line 171 
171          }          }
172    
173    
174  //U          /* U */
175          dst = image->u - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2);          dst = image->u - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2);
176          src = image->u;          src = image->u;
177    
# Line 230  Line 199 
199          }          }
200    
201    
202  // V          /* V */
203          dst = image->v - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2);          dst = image->v - (EDGE_SIZE2 + EDGE_SIZE2 * edged_width2);
204          src = image->v;          src = image->v;
205    
# Line 258  Line 227 
227          }          }
228  }  }
229    
230  // bframe encoding requires image-based u,v interpolation  /* bframe encoding requires image-based u,v interpolation */
231  void  void
232  image_interpolate(const IMAGE * refn,  image_interpolate(const IMAGE * refn,
233                                    IMAGE * refh,                                    IMAGE * refh,
# Line 269  Line 238 
238                                    uint32_t quarterpel,                                    uint32_t quarterpel,
239                                    uint32_t rounding)                                    uint32_t rounding)
240  {  {
241          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 */
242          const uint32_t stride_add = 7 * edged_width;          const uint32_t stride_add = 7 * edged_width;
243  /*  #if 0
 #ifdef BFRAMES  
244          const uint32_t edged_width2 = edged_width / 2;          const uint32_t edged_width2 = edged_width / 2;
245          const uint32_t edged_height2 = edged_height / 2;          const uint32_t edged_height2 = edged_height / 2;
246          const uint32_t offset2 = EDGE_SIZE2 * (edged_width2 + 1);          const uint32_t offset2 = EDGE_SIZE2 * (edged_width2 + 1);
247          const uint32_t stride_add2 = 7 * edged_width2;          const uint32_t stride_add2 = 7 * edged_width2;
248  #endif  #endif
 */  
249          uint8_t *n_ptr, *h_ptr, *v_ptr, *hv_ptr;          uint8_t *n_ptr, *h_ptr, *v_ptr, *hv_ptr;
250          uint32_t x, y;          uint32_t x, y;
251    
# Line 512  Line 479 
479  #undef IMG_V  #undef IMG_V
480          }          }
481    
482          DPRINTF(DPRINTF_DEBUG,"chroma_optimized_pixels = %i/%i", pixels, width*height/4);          DPRINTF(XVID_DEBUG_DEBUG,"chroma_optimized_pixels = %i/%i\n", pixels, width*height/4);
483  }  }
484    
485    
# Line 564  Line 531 
531                          uint32_t width,                          uint32_t width,
532                          int height,                          int height,
533                          uint32_t edged_width,                          uint32_t edged_width,
534                          uint8_t * src,                          uint8_t * src[4],
535                          int src_stride,                          int src_stride[4],
536                          int csp,                          int csp,
537                          int interlacing)                          int interlacing)
538  {  {
539          const int edged_width2 = edged_width/2;          const int edged_width2 = edged_width/2;
540          const int width2 = width/2;          const int width2 = width/2;
541          const int height2 = height/2;          const int height2 = height/2;
542          //const int height_signed = (csp & XVID_CSP_VFLIP) ? -height : height;  #if 0
543            const int height_signed = (csp & XVID_CSP_VFLIP) ? -height : height;
544    #endif
         //      int src_stride = width;  
   
         // --- xvid 2.1 compatiblity patch ---  
         // --- remove when xvid_dec_frame->stride equals real stride  
         /*  
         if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB555 ||  
                 (csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB565 ||  
                 (csp & ~XVID_CSP_VFLIP) == XVID_CSP_YUY2 ||  
                 (csp & ~XVID_CSP_VFLIP) == XVID_CSP_YVYU ||  
                 (csp & ~XVID_CSP_VFLIP) == XVID_CSP_UYVY)  
         {  
                 src_stride *= 2;  
         }  
         else if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB24)  
         {  
                 src_stride *= 3;  
         }  
         else if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB32 ||  
                 (csp & ~XVID_CSP_VFLIP) == XVID_CSP_ABGR ||  
                 (csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGBA)  
         {  
                 src_stride *= 4;  
         }  
         */  
         // ^--- xvid 2.1 compatiblity fix ---^  
545    
546          switch (csp & ~XVID_CSP_VFLIP) {          switch (csp & ~XVID_CSP_VFLIP) {
547          case XVID_CSP_RGB555:          case XVID_CSP_RGB555:
548                  safe_packed_conv(                  safe_packed_conv(
549                          src, src_stride, image->y, image->u, image->v,                          src[0], src_stride[0], image->y, image->u, image->v,
550                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
551                          interlacing?rgb555i_to_yv12  :rgb555_to_yv12,                          interlacing?rgb555i_to_yv12  :rgb555_to_yv12,
552                          interlacing?rgb555i_to_yv12_c:rgb555_to_yv12_c, 2);                          interlacing?rgb555i_to_yv12_c:rgb555_to_yv12_c, 2);
# Line 612  Line 554 
554    
555          case XVID_CSP_RGB565:          case XVID_CSP_RGB565:
556                  safe_packed_conv(                  safe_packed_conv(
557                          src, src_stride, image->y, image->u, image->v,                          src[0], src_stride[0], image->y, image->u, image->v,
558                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
559                          interlacing?rgb565i_to_yv12  :rgb565_to_yv12,                          interlacing?rgb565i_to_yv12  :rgb565_to_yv12,
560                          interlacing?rgb565i_to_yv12_c:rgb565_to_yv12_c, 2);                          interlacing?rgb565i_to_yv12_c:rgb565_to_yv12_c, 2);
561                  break;                  break;
562    
563    
564          case XVID_CSP_RGB24:          case XVID_CSP_BGR:
565                  safe_packed_conv(                  safe_packed_conv(
566                          src, src_stride, image->y, image->u, image->v,                          src[0], src_stride[0], image->y, image->u, image->v,
567                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
568                          interlacing?bgri_to_yv12  :bgr_to_yv12,                          interlacing?bgri_to_yv12  :bgr_to_yv12,
569                          interlacing?bgri_to_yv12_c:bgr_to_yv12_c, 3);                          interlacing?bgri_to_yv12_c:bgr_to_yv12_c, 3);
570                  break;                  break;
571    
572          case XVID_CSP_RGB32:          case XVID_CSP_BGRA:
573                  safe_packed_conv(                  safe_packed_conv(
574                          src, src_stride, image->y, image->u, image->v,                          src[0], src_stride[0], image->y, image->u, image->v,
575                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
576                          interlacing?bgrai_to_yv12  :bgra_to_yv12,                          interlacing?bgrai_to_yv12  :bgra_to_yv12,
577                          interlacing?bgrai_to_yv12_c:bgra_to_yv12_c, 4);                          interlacing?bgrai_to_yv12_c:bgra_to_yv12_c, 4);
# Line 637  Line 579 
579    
580          case XVID_CSP_ABGR :          case XVID_CSP_ABGR :
581                  safe_packed_conv(                  safe_packed_conv(
582                          src, src_stride, image->y, image->u, image->v,                          src[0], src_stride[0], image->y, image->u, image->v,
583                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
584                          interlacing?abgri_to_yv12  :abgr_to_yv12,                          interlacing?abgri_to_yv12  :abgr_to_yv12,
585                          interlacing?abgri_to_yv12_c:abgr_to_yv12_c, 4);                          interlacing?abgri_to_yv12_c:abgr_to_yv12_c, 4);
# Line 645  Line 587 
587    
588          case XVID_CSP_RGBA :          case XVID_CSP_RGBA :
589                  safe_packed_conv(                  safe_packed_conv(
590                          src, src_stride, image->y, image->u, image->v,                          src[0], src_stride[0], image->y, image->u, image->v,
591                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
592                          interlacing?rgbai_to_yv12  :rgba_to_yv12,                          interlacing?rgbai_to_yv12  :rgba_to_yv12,
593                          interlacing?rgbai_to_yv12_c:rgba_to_yv12_c, 4);                          interlacing?rgbai_to_yv12_c:rgba_to_yv12_c, 4);
# Line 653  Line 595 
595    
596          case XVID_CSP_YUY2:          case XVID_CSP_YUY2:
597                  safe_packed_conv(                  safe_packed_conv(
598                          src, src_stride, image->y, image->u, image->v,                          src[0], src_stride[0], image->y, image->u, image->v,
599                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
600                          interlacing?yuyvi_to_yv12  :yuyv_to_yv12,                          interlacing?yuyvi_to_yv12  :yuyv_to_yv12,
601                          interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2);                          interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2);
# Line 661  Line 603 
603    
604          case XVID_CSP_YVYU:             /* u/v swapped */          case XVID_CSP_YVYU:             /* u/v swapped */
605                  safe_packed_conv(                  safe_packed_conv(
606                          src, src_stride, image->y, image->v, image->y,                          src[0], src_stride[0], image->y, image->v, image->y,
607                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
608                          interlacing?yuyvi_to_yv12  :yuyv_to_yv12,                          interlacing?yuyvi_to_yv12  :yuyv_to_yv12,
609                          interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2);                          interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2);
# Line 669  Line 611 
611    
612          case XVID_CSP_UYVY:          case XVID_CSP_UYVY:
613                  safe_packed_conv(                  safe_packed_conv(
614                          src, src_stride, image->y, image->u, image->v,                          src[0], src_stride[0], image->y, image->u, image->v,
615                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
616                          interlacing?uyvyi_to_yv12  :uyvy_to_yv12,                          interlacing?uyvyi_to_yv12  :uyvy_to_yv12,
617                          interlacing?uyvyi_to_yv12_c:uyvy_to_yv12_c, 2);                          interlacing?uyvyi_to_yv12_c:uyvy_to_yv12_c, 2);
# Line 677  Line 619 
619    
620          case XVID_CSP_I420:          case XVID_CSP_I420:
621                  yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2,                  yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2,
622                          src, src + src_stride*height, src + src_stride*height + (src_stride/2)*height2,                          src[0], src[0] + src_stride[0]*height, src[0] + src_stride[0]*height + (src_stride[0]/2)*height2,
623                          src_stride, src_stride/2, width, height, (csp & XVID_CSP_VFLIP));                          src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP));
624                  break                  break
625                          ;                          ;
626          case XVID_CSP_YV12:             /* u/v swapped */          case XVID_CSP_YV12:             /* u/v swapped */
627                  yv12_to_yv12(image->y, image->v, image->u, edged_width, edged_width2,                  yv12_to_yv12(image->y, image->v, image->u, edged_width, edged_width2,
628                          src, src + src_stride*height, src + src_stride*height + (src_stride/2)*height2,                          src[0], src[0] + src_stride[0]*height, src[0] + src_stride[0]*height + (src_stride[0]/2)*height2,
629                          src_stride, src_stride/2, width, height, (csp & XVID_CSP_VFLIP));                          src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP));
630                  break;                  break;
631    
632          case XVID_CSP_USER:          case XVID_CSP_USER:
633                  {          /*XXX: support for different u & v strides */
                         DEC_PICTURE * pic = (DEC_PICTURE*)src;  
634                          yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2,                          yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2,
635                                  pic->y, pic->u, pic->v, pic->stride_y, pic->stride_y,                          src[0], src[1], src[2], src_stride[0], src_stride[1],
636                                  width, height, (csp & XVID_CSP_VFLIP));                                  width, height, (csp & XVID_CSP_VFLIP));
                 }  
637                  break;                  break;
638    
639          case XVID_CSP_NULL:          case XVID_CSP_NULL:
# Line 759  Line 699 
699                           uint32_t width,                           uint32_t width,
700                           int height,                           int height,
701                           uint32_t edged_width,                           uint32_t edged_width,
702                           uint8_t * dst,                           uint8_t * dst[4],
703                           uint32_t dst_stride,                           uint32_t dst_stride[4],
704                           int csp,                           int csp,
705                           int interlacing)                           int interlacing)
706  {  {
# Line 773  Line 713 
713          image_dump_yuvpgm(image, edged_width, width, height, "\\decode.pgm");          image_dump_yuvpgm(image, edged_width, width, height, "\\decode.pgm");
714  */  */
715    
   
         // --- xvid 2.1 compatiblity patch ---  
         // --- remove when xvid_dec_frame->stride equals real stride  
         /*  
         if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB555 ||  
                 (csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB565 ||  
                 (csp & ~XVID_CSP_VFLIP) == XVID_CSP_YUY2 ||  
                 (csp & ~XVID_CSP_VFLIP) == XVID_CSP_YVYU ||  
                 (csp & ~XVID_CSP_VFLIP) == XVID_CSP_UYVY)  
         {  
                 dst_stride *= 2;  
         }  
         else if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB24)  
         {  
                 dst_stride *= 3;  
         }  
         else if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB32 ||  
                 (csp & ~XVID_CSP_VFLIP) == XVID_CSP_ABGR ||  
                 (csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGBA)  
         {  
                 dst_stride *= 4;  
         }  
         */  
         // ^--- xvid 2.1 compatiblity fix ---^  
   
   
716          switch (csp & ~XVID_CSP_VFLIP) {          switch (csp & ~XVID_CSP_VFLIP) {
717          case XVID_CSP_RGB555:          case XVID_CSP_RGB555:
718                  safe_packed_conv(                  safe_packed_conv(
719                          dst, dst_stride, image->y, image->u, image->v,                          dst[0], dst_stride[0], image->y, image->u, image->v,
720                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
721                          interlacing?yv12_to_rgb555i  :yv12_to_rgb555,                          interlacing?yv12_to_rgb555i  :yv12_to_rgb555,
722                          interlacing?yv12_to_rgb555i_c:yv12_to_rgb555_c, 2);                          interlacing?yv12_to_rgb555i_c:yv12_to_rgb555_c, 2);
# Line 810  Line 724 
724    
725          case XVID_CSP_RGB565:          case XVID_CSP_RGB565:
726                  safe_packed_conv(                  safe_packed_conv(
727                          dst, dst_stride, image->y, image->u, image->v,                          dst[0], dst_stride[0], image->y, image->u, image->v,
728                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
729                          interlacing?yv12_to_rgb565i  :yv12_to_rgb565,                          interlacing?yv12_to_rgb565i  :yv12_to_rgb565,
730                          interlacing?yv12_to_rgb565i_c:yv12_to_rgb565_c, 2);                          interlacing?yv12_to_rgb565i_c:yv12_to_rgb565_c, 2);
731                  return 0;                  return 0;
732    
733          case XVID_CSP_RGB24:      case XVID_CSP_BGR:
734                  safe_packed_conv(                  safe_packed_conv(
735                          dst, dst_stride, image->y, image->u, image->v,                          dst[0], dst_stride[0], image->y, image->u, image->v,
736                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
737                          interlacing?yv12_to_bgri  :yv12_to_bgr,                          interlacing?yv12_to_bgri  :yv12_to_bgr,
738                          interlacing?yv12_to_bgri_c:yv12_to_bgr_c, 3);                          interlacing?yv12_to_bgri_c:yv12_to_bgr_c, 3);
739                  return 0;                  return 0;
740    
741          case XVID_CSP_RGB32:          case XVID_CSP_BGRA:
742                  safe_packed_conv(                  safe_packed_conv(
743                          dst, dst_stride, image->y, image->u, image->v,                          dst[0], dst_stride[0], image->y, image->u, image->v,
744                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
745                          interlacing?yv12_to_bgrai  :yv12_to_bgra,                          interlacing?yv12_to_bgrai  :yv12_to_bgra,
746                          interlacing?yv12_to_bgrai_c:yv12_to_bgra_c, 4);                          interlacing?yv12_to_bgrai_c:yv12_to_bgra_c, 4);
# Line 834  Line 748 
748    
749          case XVID_CSP_ABGR:          case XVID_CSP_ABGR:
750                  safe_packed_conv(                  safe_packed_conv(
751                          dst, dst_stride, image->y, image->u, image->v,                          dst[0], dst_stride[0], image->y, image->u, image->v,
752                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
753                          interlacing?yv12_to_abgri  :yv12_to_abgr,                          interlacing?yv12_to_abgri  :yv12_to_abgr,
754                          interlacing?yv12_to_abgri_c:yv12_to_abgr_c, 4);                          interlacing?yv12_to_abgri_c:yv12_to_abgr_c, 4);
# Line 842  Line 756 
756    
757          case XVID_CSP_RGBA:          case XVID_CSP_RGBA:
758                  safe_packed_conv(                  safe_packed_conv(
759                          dst, dst_stride, image->y, image->u, image->v,                          dst[0], dst_stride[0], image->y, image->u, image->v,
760                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
761                          interlacing?yv12_to_rgbai  :yv12_to_rgba,                          interlacing?yv12_to_rgbai  :yv12_to_rgba,
762                          interlacing?yv12_to_rgbai_c:yv12_to_rgba_c, 4);                          interlacing?yv12_to_rgbai_c:yv12_to_rgba_c, 4);
# Line 850  Line 764 
764    
765          case XVID_CSP_YUY2:          case XVID_CSP_YUY2:
766                  safe_packed_conv(                  safe_packed_conv(
767                          dst, dst_stride, image->y, image->u, image->v,                          dst[0], dst_stride[0], image->y, image->u, image->v,
768                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
769                          interlacing?yv12_to_yuyvi  :yv12_to_yuyv,                          interlacing?yv12_to_yuyvi  :yv12_to_yuyv,
770                          interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2);                          interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2);
771                  return 0;                  return 0;
772    
773          case XVID_CSP_YVYU:             // u,v swapped          case XVID_CSP_YVYU:             /* u,v swapped */
774                  safe_packed_conv(                  safe_packed_conv(
775                          dst, dst_stride, image->y, image->v, image->u,                          dst[0], dst_stride[0], image->y, image->v, image->u,
776                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
777                          interlacing?yv12_to_yuyvi  :yv12_to_yuyv,                          interlacing?yv12_to_yuyvi  :yv12_to_yuyv,
778                          interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2);                          interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2);
# Line 866  Line 780 
780    
781          case XVID_CSP_UYVY:          case XVID_CSP_UYVY:
782                  safe_packed_conv(                  safe_packed_conv(
783                          dst, dst_stride, image->y, image->u, image->v,                          dst[0], dst_stride[0], image->y, image->u, image->v,
784                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
785                          interlacing?yv12_to_uyvyi  :yv12_to_uyvy,                          interlacing?yv12_to_uyvyi  :yv12_to_uyvy,
786                          interlacing?yv12_to_uyvyi_c:yv12_to_uyvy_c, 2);                          interlacing?yv12_to_uyvyi_c:yv12_to_uyvy_c, 2);
787                  return 0;                  return 0;
788    
789          case XVID_CSP_I420:          case XVID_CSP_I420:
790                  yv12_to_yv12(dst, dst + dst_stride*height, dst + dst_stride*height + (dst_stride/2)*height2,                  yv12_to_yv12(dst[0], dst[0] + dst_stride[0]*height, dst[0] + dst_stride[0]*height + (dst_stride[0]/2)*height2,
791                          dst_stride, dst_stride/2,                          dst_stride[0], dst_stride[0]/2,
792                          image->y, image->u, image->v, edged_width, edged_width2,                          image->y, image->u, image->v, edged_width, edged_width2,
793                          width, height, (csp & XVID_CSP_VFLIP));                          width, height, (csp & XVID_CSP_VFLIP));
794                  return 0;                  return 0;
795    
796          case XVID_CSP_YV12:             // u,v swapped          case XVID_CSP_YV12:             /* u,v swapped */
797                  yv12_to_yv12(dst, dst + dst_stride*height, dst + dst_stride*height + (dst_stride/2)*height2,                  yv12_to_yv12(dst[0], dst[0] + dst_stride[0]*height, dst[0] + dst_stride[0]*height + (dst_stride[0]/2)*height2,
798                          dst_stride, dst_stride/2,                          dst_stride[0], dst_stride[0]/2,
799                          image->y, image->v, image->u, edged_width, edged_width2,                          image->y, image->v, image->u, edged_width, edged_width2,
800                          width, height, (csp & XVID_CSP_VFLIP));                          width, height, (csp & XVID_CSP_VFLIP));
801                  return 0;                  return 0;
802    
803          case XVID_CSP_USER:          case XVID_CSP_USER :            /* u,v swapped */
804                  {                  yv12_to_yv12(dst[0], dst[1], dst[2],
805                          DEC_PICTURE * pic = (DEC_PICTURE*)dst;                          dst_stride[0], dst_stride[1],   /* v: dst_stride[2] */
806                          pic->y = image->y;                          image->y, image->v, image->u, edged_width, edged_width2,
807                          pic->u = image->u;                          width, height, (csp & XVID_CSP_VFLIP));
808                          pic->v = image->v;                  return 0;
809                          pic->stride_y = edged_width;  
810                          pic->stride_uv = edged_width / 2;          case XVID_CSP_INTERNAL :
811                  }                  dst[0] = image->y;
812                    dst[1] = image->u;
813                    dst[2] = image->v;
814                    dst_stride[0] = edged_width;
815                    dst_stride[1] = edged_width/2;
816                    dst_stride[2] = edged_width/2;
817                  return 0;                  return 0;
818    
819          case XVID_CSP_NULL:          case XVID_CSP_NULL:
820          case XVID_CSP_EXTERN:          case XVID_CSP_SLICE:
821                  return 0;                  return 0;
822    
823          }          }
# Line 944  Line 863 
863          if (sse==0)          if (sse==0)
864                  return 99.99F;                  return 99.99F;
865    
866          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 */
867    
868  }  }
869    
# Line 968  Line 887 
887          return sse;          return sse;
888  }  }
889    
890  /*  #if 0
891    
892  #include <stdio.h>  #include <stdio.h>
893  #include <string.h>  #include <string.h>
# Line 992  Line 911 
911  }  }
912    
913    
914  // dump image+edges to yuv pgm files  /* dump image+edges to yuv pgm files */
915    
916  int image_dump(IMAGE * image, uint32_t edged_width, uint32_t edged_height, char * path, int number)  int image_dump(IMAGE * image, uint32_t edged_width, uint32_t edged_height, char * path, int number)
917  {  {
# Line 1015  Line 934 
934    
935          return 0;          return 0;
936  }  }
937  */  #endif
938    
939    
940    
# Line 1080  Line 999 
999    
1000          for (y = 0; y < height; y++)          for (y = 0; y < height; y++)
1001                  for (x = 0; x < width; x++)                  for (x = 0; x < width; x++)
1002                          sum += ABS(img1->y[x + y * stride] - img2->y[x + y * stride]);                          sum += abs(img1->y[x + y * stride] - img2->y[x + y * stride]);
1003    
1004          for (y = 0; y < height2; y++)          for (y = 0; y < height2; y++)
1005                  for (x = 0; x < width2; x++)                  for (x = 0; x < width2; x++)
1006                          sum += ABS(img1->u[x + y * stride2] - img2->u[x + y * stride2]);                          sum += abs(img1->u[x + y * stride2] - img2->u[x + y * stride2]);
1007    
1008          for (y = 0; y < height2; y++)          for (y = 0; y < height2; y++)
1009                  for (x = 0; x < width2; x++)                  for (x = 0; x < width2; x++)
1010                          sum += ABS(img1->v[x + y * stride2] - img2->v[x + y * stride2]);                          sum += abs(img1->v[x + y * stride2] - img2->v[x + y * stride2]);
1011    
1012          return (float) sum / (width * height * 3 / 2);          return (float) sum / (width * height * 3 / 2);
1013  }  }
1014    
1015  void  void
1016  output_slice(IMAGE * cur, int std, int width, XVID_DEC_PICTURE* out_frm, int mbx, int mby,int mbl) {  output_slice(IMAGE * cur, int std, int width, xvid_image_t* out_frm, int mbx, int mby,int mbl) {
1017    uint8_t *dY,*dU,*dV,*sY,*sU,*sV;    uint8_t *dY,*dU,*dV,*sY,*sU,*sV;
1018    int std2 = std >> 1;    int std2 = std >> 1;
1019    int w = mbl << 4, w2,i;    int w = mbl << 4, w2,i;
# Line 1103  Line 1022 
1022      w = width;      w = width;
1023    w2 = w >> 1;    w2 = w >> 1;
1024    
1025    dY = (uint8_t*)out_frm->y + (mby << 4) * out_frm->stride_y + (mbx << 4);    dY = (uint8_t*)out_frm->plane[0] + (mby << 4) * out_frm->stride[0] + (mbx << 4);
1026    dU = (uint8_t*)out_frm->u + (mby << 3) * out_frm->stride_u + (mbx << 3);    dU = (uint8_t*)out_frm->plane[1] + (mby << 3) * out_frm->stride[1] + (mbx << 3);
1027    dV = (uint8_t*)out_frm->v + (mby << 3) * out_frm->stride_v + (mbx << 3);    dV = (uint8_t*)out_frm->plane[2] + (mby << 3) * out_frm->stride[2] + (mbx << 3);
1028    sY = cur->y + (mby << 4) * std + (mbx << 4);    sY = cur->y + (mby << 4) * std + (mbx << 4);
1029    sU = cur->u + (mby << 3) * std2 + (mbx << 3);    sU = cur->u + (mby << 3) * std2 + (mbx << 3);
1030    sV = cur->v + (mby << 3) * std2 + (mbx << 3);    sV = cur->v + (mby << 3) * std2 + (mbx << 3);
1031    
1032    for(i = 0 ; i < 16 ; i++) {    for(i = 0 ; i < 16 ; i++) {
1033      memcpy(dY,sY,w);      memcpy(dY,sY,w);
1034      dY += out_frm->stride_y;      dY += out_frm->stride[0];
1035      sY += std;      sY += std;
1036    }    }
1037    for(i = 0 ; i < 8 ; i++) {    for(i = 0 ; i < 8 ; i++) {
1038      memcpy(dU,sU,w2);      memcpy(dU,sU,w2);
1039      dU += out_frm->stride_u;      dU += out_frm->stride[1];
1040      sU += std2;      sU += std2;
1041    }    }
1042    for(i = 0 ; i < 8 ; i++) {    for(i = 0 ; i < 8 ; i++) {
1043      memcpy(dV,sV,w2);      memcpy(dV,sV,w2);
1044      dV += out_frm->stride_v;      dV += out_frm->stride[2];
1045      sV += std2;      sV += std2;
1046    }    }
1047  }  }
# Line 1169  Line 1088 
1088          int i,j;          int i,j;
1089    
1090          /* luma: j,i in block units */          /* luma: j,i in block units */
1091          if ((flags & XVID_DEC_DEBLOCKY))  
         {  
1092                  for (j = 1; j < mb_height*2; j++)               /* horizontal deblocking */                  for (j = 1; j < mb_height*2; j++)               /* horizontal deblocking */
1093                  for (i = 0; i < mb_width*2; i++)                  for (i = 0; i < mb_width*2; i++)
1094                  {                  {
# Line 1193  Line 1111 
1111                                                     edged_width, nblocks);                                                     edged_width, nblocks);
1112                          }                          }
1113                  }                  }
1114          }  
1115    
1116    
1117          /* chroma */          /* chroma */
1118          if ((flags & XVID_DEC_DEBLOCKUV))  
         {  
1119                  for (j = 1; j < mb_height; j++)         /* horizontal deblocking */                  for (j = 1; j < mb_height; j++)         /* horizontal deblocking */
1120                  for (i = 0; i < mb_width; i++)                  for (i = 0; i < mb_width; i++)
1121                  {                  {
# Line 1226  Line 1143 
1143                                                     edged_width2, nblocks);                                                     edged_width2, nblocks);
1144                          }                          }
1145                  }                  }
1146          }  
1147    
1148  }  }
1149    

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.26.2.8

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4