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

Diff of /xvidcore/src/quant/adapt_quant.c

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

revision 1.3, Wed Jun 12 20:38:40 2002 UTC revision 1.4, Wed Jun 19 08:46:57 2002 UTC
# Line 68  Line 68 
68          static float *quant;          static float *quant;
69          unsigned char *ptr;          unsigned char *ptr;
70          float *val;          float *val;
71          float global = 0.;          float global = 0., maxval = 0.;
         uint32_t mid_range = 0;  
72    
73          const float DarkAmpl = 14 / 2;          const float DarkThres = 0.25;
74          const float BrightAmpl = 10 / 2;          const float DarkAmpl = 7.0;
         const float DarkThres = 70;  
         const float BrightThres = 200;  
   
         const float GlobalDarkThres = 60;  
         const float GlobalBrightThres = 170;  
   
         const float MidRangeThres = 20;  
         const float UpperLimit = 200;  
         const float LowerLimit = 25;  
75    
76            const float BrightThres = 4.0;
77            const float BrightAmpl = 5.0;
78    
79            const char LowestVal = 10;
80    
81            const float GlobalBrightThres = 220.0;
82            const float GlobalDarkThres = 20.0;
83            float global_quant = 1.0;
84    
85          if (!quant)          if (!quant)
86                  if (!(quant = (float *) malloc(mb_width * mb_height * sizeof(float))))                  if (!(quant = (float *) malloc(mb_width * mb_height * sizeof(float))))
# Line 102  Line 100 
100    
101                          for (i = 0; i < 16; i++)                          for (i = 0; i < 16; i++)
102                                  for (j = 0; j < 16; j++)                                  for (j = 0; j < 16; j++)
103                                    {
104                                            if( ptr[i * stride + j] < LowestVal )
105                                                    ptr[i * stride + j] = 0;
106                                          val[k * mb_width + l] += ptr[i * stride + j];                                          val[k * mb_width + l] += ptr[i * stride + j];
107                                    }
108                          val[k * mb_width + l] /= 256.;                          val[k * mb_width + l] /= 256.;
109                          global +=val[k * mb_width + l];                          global +=val[k * mb_width + l];
110                            if( val[k * mb_width + l] > maxval )
111                          if ((val[k * mb_width + l] > LowerLimit) &&                                  maxval = val[k * mb_width + l];
                                 (val[k * mb_width + l] < UpperLimit))  
                                 mid_range++;  
112                  }                  }
113          }          }
114    
115          global /=mb_width * mb_height;          global /=mb_width * mb_height;
116            maxval /= global;
117            if( global < GlobalDarkThres )
118                    global_quant *= -1.0;
119            else if ( global < GlobalBrightThres )
120                    global_quant = 0.0;
121    
         if (((global <GlobalBrightThres) &&(global >GlobalDarkThres))  
                 || (mid_range < MidRangeThres)) {  
122                  for (k = 0; k < mb_height; k++) {                  for (k = 0; k < mb_height; k++) {
123                          for (l = 0; l < mb_width; l++)  // do this for all macroblocks individually                          for (l = 0; l < mb_width; l++)  // do this for all macroblocks individually
124                          {                          {
125                            val[k * mb_width + l] /= global;
126                                  if (val[k * mb_width + l] < DarkThres)                                  if (val[k * mb_width + l] < DarkThres)
127                                          quant[k * mb_width + l] +=                                  quant[k * mb_width + l] += global_quant +
128                                                  DarkAmpl * (DarkThres -                                          DarkAmpl * (DarkThres - val[k * mb_width + l]) / DarkThres;
                                                                         val[k * mb_width + l]) / DarkThres;  
129                                  else if (val[k * mb_width + l] > BrightThres)                                  else if (val[k * mb_width + l] > BrightThres)
130                                          quant[k * mb_width + l] +=                                  quant[k * mb_width + l] += global_quant +
131                                                  BrightAmpl * (val[k * mb_width + l] -                                          BrightAmpl * (val[k * mb_width + l] - BrightThres) / (maxval - BrightThres);
                                                                           BrightThres) / (255 - BrightThres);  
                         }  
132                  }                  }
133          }          }
134          free(val);          free(val);

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

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