[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.20.2.7, Thu Nov 7 10:28:15 2002 UTC revision 1.20.2.11, Sat Dec 14 06:07:03 2002 UTC
# Line 59  Line 59 
59  #include "image.h"  #include "image.h"
60  #include "colorspace.h"  #include "colorspace.h"
61  #include "interpolate8x8.h"  #include "interpolate8x8.h"
62    #include "reduced.h"
63  #include "../divx4.h"  #include "../divx4.h"
64  #include "../utils/mem_align.h"  #include "../utils/mem_align.h"
65    
# Line 323  Line 324 
324                                  h_ptr += 8;                                  h_ptr += 8;
325                          }                          }
326    
327                          hv_ptr += EDGE_SIZE2;                          hv_ptr += EDGE_SIZE;
328                          h_ptr += EDGE_SIZE2;                          h_ptr += EDGE_SIZE;
329    
330                          hv_ptr += stride_add;                          hv_ptr += stride_add;
331                          h_ptr += stride_add;                          h_ptr += stride_add;
# Line 475  Line 476 
476  }  }
477    
478    
479    /*
480    chroma optimize filter, invented by mf
481    a chroma pixel is average from the surrounding pixels, when the
482    correpsonding luma pixels are pure black or white.
483    */
484    
485    void
486    image_chroma_optimize(IMAGE * img, int width, int height, int edged_width)
487    {
488            int x,y;
489            int pixels = 0;
490    
491            for (y = 1; y < height/2 - 1; y++)
492            for (x = 1; x < width/2 - 1; x++)
493            {
494    #define IS_PURE(a)  ((a)<=16||(a)>=235)
495    #define IMG_Y(Y,X)      img->y[(Y)*edged_width + (X)]
496    #define IMG_U(Y,X)      img->u[(Y)*edged_width/2 + (X)]
497    #define IMG_V(Y,X)      img->v[(Y)*edged_width/2 + (X)]
498    
499                    if (IS_PURE(IMG_Y(y*2  ,x*2  )) &&
500                            IS_PURE(IMG_Y(y*2  ,x*2+1)) &&
501                            IS_PURE(IMG_Y(y*2+1,x*2  )) &&
502                            IS_PURE(IMG_Y(y*2+1,x*2+1)))
503                    {
504                            IMG_U(y,x) = (IMG_U(y,x-1) + IMG_U(y-1, x) + IMG_U(y, x+1) + IMG_U(y+1, x)) / 4;
505                            IMG_V(y,x) = (IMG_V(y,x-1) + IMG_V(y-1, x) + IMG_V(y, x+1) + IMG_V(y+1, x)) / 4;
506                            pixels++;
507                    }
508    
509    #undef IS_PURE
510    #undef IMG_Y
511    #undef IMG_U
512    #undef IMG_V
513            }
514    
515            DPRINTF(DPRINTF_DEBUG,"chroma_optimized_pixels = %i/%i", pixels, width*height/4);
516    }
517    
518    
519    
520    
521    
522  /*  /*
523    perform safe packed colorspace conversion, by splitting    perform safe packed colorspace conversion, by splitting
# Line 1055  Line 1098 
1098      sV += std2;      sV += std2;
1099    }    }
1100  }  }
1101    
1102    
1103    void
1104    image_clear(IMAGE * img, int width, int height, int edged_width,
1105                                            int y, int u, int v)
1106    {
1107            uint8_t * p;
1108            int i;
1109    
1110            p = img->y;
1111            for (i = 0; i < height; i++) {
1112                    memset(p, y, width);
1113                    p += edged_width;
1114            }
1115    
1116            p = img->u;
1117            for (i = 0; i < height/2; i++) {
1118                    memset(p, u, width/2);
1119                    p += edged_width/2;
1120            }
1121    
1122            p = img->v;
1123            for (i = 0; i < height/2; i++) {
1124                    memset(p, v, width/2);
1125                    p += edged_width/2;
1126            }
1127    }
1128    
1129    
1130    /* reduced resolution deblocking filter
1131            block = block size (16=rrv, 8=full resolution)
1132            flags = XVID_DEC_YDEBLOCK|XVID_DEC_UVDEBLOCK
1133    */
1134    void
1135    image_deblock_rrv(IMAGE * img, int edged_width,
1136                                    const MACROBLOCK * mbs, int mb_width, int mb_height, int mb_stride,
1137                                    int block, int flags)
1138    {
1139            const int edged_width2 = edged_width /2;
1140            const int nblocks = block / 8;  /* skals code uses 8pixel block uints */
1141            int i,j;
1142    
1143            /* luma: j,i in block units */
1144            if ((flags & XVID_DEC_DEBLOCKY))
1145            {
1146                    for (j = 1; j < mb_height*2; j++)               /* horizontal deblocking */
1147                    for (i = 0; i < mb_width*2; i++)
1148                    {
1149                            if (mbs[(j-1)/2*mb_stride + (i/2)].mode != MODE_NOT_CODED ||
1150                                    mbs[(j+0)/2*mb_stride + (i/2)].mode != MODE_NOT_CODED)
1151                            {
1152                                    xvid_HFilter_31_C(img->y + (j*block - 1)*edged_width + i*block,
1153                                                                      img->y + (j*block + 0)*edged_width + i*block, nblocks);
1154                            }
1155                    }
1156    
1157                    for (j = 0; j < mb_height*2; j++)               /* vertical deblocking */
1158                    for (i = 1; i < mb_width*2; i++)
1159                    {
1160                            if (mbs[(j/2)*mb_stride + (i-1)/2].mode != MODE_NOT_CODED ||
1161                                    mbs[(j/2)*mb_stride + (i+0)/2].mode != MODE_NOT_CODED)
1162                            {
1163                                    vfilter_31(img->y + (j*block)*edged_width + i*block - 1,
1164                                                       img->y + (j*block)*edged_width + i*block + 0,
1165                                                       edged_width, nblocks);
1166                            }
1167                    }
1168            }
1169    
1170    
1171            /* chroma */
1172            if ((flags & XVID_DEC_DEBLOCKUV))
1173            {
1174                    for (j = 0; j < mb_height; j++)                 /* horizontal deblocking */
1175                    for (i = 1; i < mb_width; i++)
1176                    {
1177                            if (mbs[j*mb_stride + i - 1].mode != MODE_NOT_CODED ||
1178                                    mbs[j*mb_stride + i + 0].mode != MODE_NOT_CODED)
1179                            {
1180                                    vfilter_31(img->u + (j*block)*edged_width2 + i*block - 1,
1181                                                       img->u + (j*block)*edged_width2 + i*block + 0,
1182                                                       edged_width2, nblocks);
1183                                    vfilter_31(img->v + (j*block)*edged_width2 + i*block - 1,
1184                                                       img->v + (j*block)*edged_width2 + i*block + 0,
1185                                                       edged_width2, nblocks);
1186                            }
1187                    }
1188    
1189                    for (j = 1; j < mb_height; j++)         /* vertical deblocking */
1190                    for (i = 0; i < mb_width; i++)
1191                    {
1192                            if (mbs[(j-1)*mb_stride + i].mode != MODE_NOT_CODED ||
1193                                    mbs[(j+0)*mb_stride + i].mode != MODE_NOT_CODED)
1194                            {
1195                                    hfilter_31(img->u + (j*block - 1)*edged_width2 + i*block,
1196                                                       img->u + (j*block + 0)*edged_width2 + i*block, nblocks);
1197                                    hfilter_31(img->v + (j*block - 1)*edged_width2 + i*block,
1198                                                       img->v + (j*block + 0)*edged_width2 + i*block, nblocks);
1199                            }
1200                    }
1201            }
1202    
1203    }

Legend:
Removed from v.1.20.2.7  
changed lines
  Added in v.1.20.2.11

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