[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.2.14, Fri Jan 30 18:53:50 2004 UTC revision 1.33, Sat Dec 17 11:24:32 2005 UTC
# Line 3  Line 3 
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - Image management functions -   *  - Image management functions -
5   *   *
6   *  Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>   *  Copyright(C) 2001-2004 Peter Ross <pross@xvid.org>
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 26  Line 26 
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  #include "../portab.h"  #include "../portab.h"
30  #include "../global.h"                  /* XVID_CSP_XXX's */  #include "../global.h"                  /* XVID_CSP_XXX's */
31  #include "../xvid.h"                    /* XVID_CSP_XXX's */  #include "../xvid.h"                    /* XVID_CSP_XXX's */
32  #include "image.h"  #include "image.h"
33  #include "colorspace.h"  #include "colorspace.h"
34  #include "interpolate8x8.h"  #include "interpolate8x8.h"
 #include "reduced.h"  
35  #include "../utils/mem_align.h"  #include "../utils/mem_align.h"
36    #include "../motion/sad.h"
37    
38  #include "font.h"               /* XXX: remove later */  #include "font.h"               /* XXX: remove later */
39    
# Line 127  Line 126 
126          memcpy(image1->v, image2->v, edged_width * height / 4);          memcpy(image1->v, image2->v, edged_width * height / 4);
127  }  }
128    
129    /* setedges bug was fixed in this BS version */
130    #define SETEDGES_BUG_BEFORE             18
131    
132  void  void
133  image_setedges(IMAGE * image,  image_setedges(IMAGE * image,
134                             uint32_t edged_width,                             uint32_t edged_width,
135                             uint32_t edged_height,                             uint32_t edged_height,
136                             uint32_t width,                             uint32_t width,
137                             uint32_t height)                             uint32_t height,
138                               int bs_version)
139  {  {
140          const uint32_t edged_width2 = edged_width / 2;          const uint32_t edged_width2 = edged_width / 2;
141          uint32_t width2;          uint32_t width2;
# Line 141  Line 143 
143          uint8_t *dst;          uint8_t *dst;
144          uint8_t *src;          uint8_t *src;
145    
   
146          dst = image->y - (EDGE_SIZE + EDGE_SIZE * edged_width);          dst = image->y - (EDGE_SIZE + EDGE_SIZE * edged_width);
147          src = image->y;          src = image->y;
148    
149          /* According to the Standard Clause 7.6.4, padding is done starting at 16          /* According to the Standard Clause 7.6.4, padding is done starting at 16
150           * pixel width and height multiples */           * pixel width and height multiples. This was not respected in old xvids */
151            if (bs_version == 0 || bs_version >= SETEDGES_BUG_BEFORE) {
152          width  = (width+15)&~15;          width  = (width+15)&~15;
153          height = (height+15)&~15;          height = (height+15)&~15;
154            }
155    
156          width2 = width/2;          width2 = width/2;
157    
158          for (i = 0; i < EDGE_SIZE; i++) {          for (i = 0; i < EDGE_SIZE; i++) {
# Line 245  Line 249 
249  {  {
250          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 */
251          const uint32_t stride_add = 7 * edged_width;          const uint32_t stride_add = 7 * edged_width;
252  #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  
253          uint8_t *n_ptr, *h_ptr, *v_ptr, *hv_ptr;          uint8_t *n_ptr, *h_ptr, *v_ptr, *hv_ptr;
254          uint32_t x, y;          uint32_t x, y;
255    
# Line 329  Line 328 
328                          n_ptr += stride_add;                          n_ptr += stride_add;
329                  }                  }
330          }          }
 /*  
 #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);  
          */  
331  }  }
332    
333    
# Line 617  Line 499 
499    
500          case XVID_CSP_YVYU:             /* u/v swapped */          case XVID_CSP_YVYU:             /* u/v swapped */
501                  safe_packed_conv(                  safe_packed_conv(
502                          src[0], src_stride[0], image->y, image->v, image->y,                          src[0], src_stride[0], image->y, image->v, image->u,
503                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
504                          interlacing?yuyvi_to_yv12  :yuyv_to_yv12,                          interlacing?yuyvi_to_yv12  :yuyv_to_yv12,
505                          interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2);                          interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2);
# Line 631  Line 513 
513                          interlacing?uyvyi_to_yv12_c:uyvy_to_yv12_c, 2);                          interlacing?uyvyi_to_yv12_c:uyvy_to_yv12_c, 2);
514                  break;                  break;
515    
516          case XVID_CSP_YV12:     /* YCrCb == internal colorspace for MPEG */          case XVID_CSP_I420:     /* YCbCr == YUV == internal colorspace for MPEG */
517                  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,
518                          src[0], src[0] + src_stride[0]*height, src[0] + src_stride[0]*height + (src_stride[0]/2)*height2,                          src[0], src[0] + src_stride[0]*height, src[0] + src_stride[0]*height + (src_stride[0]/2)*height2,
519                          src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP));                          src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP));
520                  break;                  break;
521    
522          case XVID_CSP_I420: /* YCbCr == U and V plane swapped */          case XVID_CSP_YV12: /* YCrCb == YVA == U and V plane swapped */
523                  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,
524                          src[0], src[0] + src_stride[0]*height, src[0] + src_stride[0]*height + (src_stride[0]/2)*height2,                          src[0], src[0] + src_stride[0]*height, src[0] + src_stride[0]*height + (src_stride[0]/2)*height2,
525                          src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP));                          src_stride[0], src_stride[0]/2, width, height, (csp & XVID_CSP_VFLIP));
# Line 713  Line 595 
595                           int height,                           int height,
596                           uint32_t edged_width,                           uint32_t edged_width,
597                           uint8_t * dst[4],                           uint8_t * dst[4],
598                           uint32_t dst_stride[4],                           int dst_stride[4],
599                           int csp,                           int csp,
600                           int interlacing)                           int interlacing)
601  {  {
# Line 807  Line 689 
689                          interlacing?yv12_to_uyvyi_c:yv12_to_uyvy_c, 2);                          interlacing?yv12_to_uyvyi_c:yv12_to_uyvy_c, 2);
690                  return 0;                  return 0;
691    
692          case XVID_CSP_YV12: /* YCbCr == internal colorspace for MPEG */          case XVID_CSP_I420: /* YCbCr == YUV == internal colorspace for MPEG */
693                  yv12_to_yv12(dst[0], dst[0] + dst_stride[0]*height, dst[0] + dst_stride[0]*height + (dst_stride[0]/2)*height2,                  yv12_to_yv12(dst[0], dst[0] + dst_stride[0]*height, dst[0] + dst_stride[0]*height + (dst_stride[0]/2)*height2,
694                          dst_stride[0], dst_stride[0]/2,                          dst_stride[0], dst_stride[0]/2,
695                          image->y, image->u, image->v, edged_width, edged_width2,                          image->y, image->u, image->v, edged_width, edged_width2,
696                          width, height, (csp & XVID_CSP_VFLIP));                          width, height, (csp & XVID_CSP_VFLIP));
697                  return 0;                  return 0;
698    
699          case XVID_CSP_I420:     /* YCrCb == U and V plane swapped */          case XVID_CSP_YV12:     /* YCrCb == YVU == U and V plane swapped */
700                  yv12_to_yv12(dst[0], dst[0] + dst_stride[0]*height, dst[0] + dst_stride[0]*height + (dst_stride[0]/2)*height2,                  yv12_to_yv12(dst[0], dst[0] + dst_stride[0]*height, dst[0] + dst_stride[0]*height + (dst_stride[0]/2)*height2,
701                          dst_stride[0], dst_stride[0]/2,                          dst_stride[0], dst_stride[0]/2,
702                          image->y, image->v, image->u, edged_width, edged_width2,                          image->y, image->v, image->u, edged_width, edged_width2,
# Line 894  Line 776 
776                     uint16_t width,                     uint16_t width,
777                     uint16_t height)                     uint16_t height)
778  {  {
779          int diff, x, y;          int y, bwidth, bheight;
780          long sse=0;          long sse=0;
781    
782          for (y = 0; y < height; y++) {          bwidth  = width  & (~0x07);
783            bheight = height & (~0x07);
784    
785            /* Compute the 8x8 integer part */
786            for (y = 0; y<bheight; y += 8) {
787                    int x;
788    
789                    /* Compute sse for the band */
790                    for (x = 0; x<bwidth; x += 8)
791                            sse += sse8_8bit(orig  + x, recon + x, stride);
792    
793                    /* remaining pixels of the 8 pixels high band */
794                    for (x = bwidth; x < width; x++) {
795                            int diff;
796                            diff = *(orig + 0*stride + x) - *(recon + 0*stride + x);
797                            sse += diff * diff;
798                            diff = *(orig + 1*stride + x) - *(recon + 1*stride + x);
799                            sse += diff * diff;
800                            diff = *(orig + 2*stride + x) - *(recon + 2*stride + x);
801                            sse += diff * diff;
802                            diff = *(orig + 3*stride + x) - *(recon + 3*stride + x);
803                            sse += diff * diff;
804                            diff = *(orig + 4*stride + x) - *(recon + 4*stride + x);
805                            sse += diff * diff;
806                            diff = *(orig + 5*stride + x) - *(recon + 5*stride + x);
807                            sse += diff * diff;
808                            diff = *(orig + 6*stride + x) - *(recon + 6*stride + x);
809                            sse += diff * diff;
810                            diff = *(orig + 7*stride + x) - *(recon + 7*stride + x);
811                            sse += diff * diff;
812                    }
813    
814                    orig  += 8*stride;
815                    recon += 8*stride;
816            }
817    
818            /* Compute the down rectangle sse */
819            for (y = bheight; y < height; y++) {
820                    int x;
821                  for (x = 0; x < width; x++) {                  for (x = 0; x < width; x++) {
822                            int diff;
823                          diff = *(orig + x) - *(recon + x);                          diff = *(orig + x) - *(recon + x);
824                          sse += diff * diff;                          sse += diff * diff;
825                  }                  }
826                  orig += stride;                  orig += stride;
827                  recon += stride;                  recon += stride;
828          }          }
829          return sse;  
830            return (sse);
831  }  }
832    
833  #if 0  #if 0
# Line 1034  Line 956 
956  }  }
957    
958  void  void
959  output_slice(IMAGE * cur, int std, int width, xvid_image_t* out_frm, int mbx, int mby,int mbl) {  output_slice(IMAGE * cur, int stride, int width, xvid_image_t* out_frm, int mbx, int mby,int mbl) {
960    uint8_t *dY,*dU,*dV,*sY,*sU,*sV;    uint8_t *dY,*dU,*dV,*sY,*sU,*sV;
961    int std2 = std >> 1;    int stride2 = stride >> 1;
962    int w = mbl << 4, w2,i;    int w = mbl << 4, w2,i;
963    
964    if(w > width)    if(w > width)
# Line 1046  Line 968 
968    dY = (uint8_t*)out_frm->plane[0] + (mby << 4) * out_frm->stride[0] + (mbx << 4);    dY = (uint8_t*)out_frm->plane[0] + (mby << 4) * out_frm->stride[0] + (mbx << 4);
969    dU = (uint8_t*)out_frm->plane[1] + (mby << 3) * out_frm->stride[1] + (mbx << 3);    dU = (uint8_t*)out_frm->plane[1] + (mby << 3) * out_frm->stride[1] + (mbx << 3);
970    dV = (uint8_t*)out_frm->plane[2] + (mby << 3) * out_frm->stride[2] + (mbx << 3);    dV = (uint8_t*)out_frm->plane[2] + (mby << 3) * out_frm->stride[2] + (mbx << 3);
971    sY = cur->y + (mby << 4) * std + (mbx << 4);    sY = cur->y + (mby << 4) * stride + (mbx << 4);
972    sU = cur->u + (mby << 3) * std2 + (mbx << 3);    sU = cur->u + (mby << 3) * stride2 + (mbx << 3);
973    sV = cur->v + (mby << 3) * std2 + (mbx << 3);    sV = cur->v + (mby << 3) * stride2 + (mbx << 3);
974    
975    for(i = 0 ; i < 16 ; i++) {    for(i = 0 ; i < 16 ; i++) {
976      memcpy(dY,sY,w);      memcpy(dY,sY,w);
977      dY += out_frm->stride[0];      dY += out_frm->stride[0];
978      sY += std;      sY += stride;
979    }    }
980    for(i = 0 ; i < 8 ; i++) {    for(i = 0 ; i < 8 ; i++) {
981      memcpy(dU,sU,w2);      memcpy(dU,sU,w2);
982      dU += out_frm->stride[1];      dU += out_frm->stride[1];
983      sU += std2;      sU += stride2;
984    }    }
985    for(i = 0 ; i < 8 ; i++) {    for(i = 0 ; i < 8 ; i++) {
986      memcpy(dV,sV,w2);      memcpy(dV,sV,w2);
987      dV += out_frm->stride[2];      dV += out_frm->stride[2];
988      sV += std2;      sV += stride2;
989    }    }
990  }  }
991    
# Line 1093  Line 1015 
1015                  p += edged_width/2;                  p += edged_width/2;
1016          }          }
1017  }  }
   
   
 /* 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);  
                         }  
                 }  
   
   
 }  
   

Legend:
Removed from v.1.26.2.14  
changed lines
  Added in v.1.33

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