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

Diff of /xvidcore/src/plugins/plugin_lumimasking.c

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

revision 1.1.2.5, Thu Oct 2 13:54:27 2003 UTC revision 1.6, Sat May 6 04:37:15 2006 UTC
# Line 27  Line 27 
27  #include <stdlib.h>  #include <stdlib.h>
28    
29  #include "../xvid.h"  #include "../xvid.h"
30    #include "../global.h"
31  #include "../portab.h"  #include "../portab.h"
32    #include "../utils/emms.h"
33    
34  /*****************************************************************************  /*****************************************************************************
35   * Private data type   * Private data type
# Line 46  Line 48 
48  static int lumi_plg_info(xvid_plg_info_t *info);  static int lumi_plg_info(xvid_plg_info_t *info);
49  static int lumi_plg_create(xvid_plg_create_t *create, lumi_data_t **handle);  static int lumi_plg_create(xvid_plg_create_t *create, lumi_data_t **handle);
50  static int lumi_plg_destroy(lumi_data_t *handle, xvid_plg_destroy_t * destroy);  static int lumi_plg_destroy(lumi_data_t *handle, xvid_plg_destroy_t * destroy);
51  static int lumi_plg_before(lumi_data_t *handle, xvid_plg_data_t *data);  static int lumi_plg_frame(lumi_data_t *handle, xvid_plg_data_t *data);
52  static int lumi_plg_after(lumi_data_t *handle, xvid_plg_data_t *data);  static int lumi_plg_after(lumi_data_t *handle, xvid_plg_data_t *data);
53    
54  /*****************************************************************************  /*****************************************************************************
# Line 64  Line 66 
66          case XVID_PLG_DESTROY:          case XVID_PLG_DESTROY:
67                  return(lumi_plg_destroy((lumi_data_t *)handle, (xvid_plg_destroy_t*)param1));                  return(lumi_plg_destroy((lumi_data_t *)handle, (xvid_plg_destroy_t*)param1));
68          case XVID_PLG_BEFORE :          case XVID_PLG_BEFORE :
69                  return(lumi_plg_before((lumi_data_t *)handle, (xvid_plg_data_t *)param1));                  return 0;
70            case XVID_PLG_FRAME :
71                    return(lumi_plg_frame((lumi_data_t *)handle, (xvid_plg_data_t *)param1));
72          case XVID_PLG_AFTER :          case XVID_PLG_AFTER :
73                  return(lumi_plg_after((lumi_data_t *)handle, (xvid_plg_data_t *)param1));                  return(lumi_plg_after((lumi_data_t *)handle, (xvid_plg_data_t *)param1));
74          }          }
# Line 154  Line 158 
158                                                                           int max_quant);                                                                           int max_quant);
159    
160  static int  static int
161  lumi_plg_before(lumi_data_t *handle, xvid_plg_data_t *data)  lumi_plg_frame(lumi_data_t *handle, xvid_plg_data_t *data)
162  {  {
163          int i, j;          int i, j;
164    
165          float global = 0.0f;          float global = 0.0f;
         uint32_t mid_range = 0;  
166    
167          const float DarkAmpl = 14 / 2;          const float DarkAmpl = 14 / 4;
168          const float BrightAmpl = 10 / 2;          const float BrightAmpl = 10 / 3;
169          const float DarkThres = 70;          float DarkThres = 90;
170          const float BrightThres = 200;          float BrightThres = 200;
171    
172          const float GlobalDarkThres = 60;          const float GlobalDarkThres = 60;
173          const float GlobalBrightThres = 170;          const float GlobalBrightThres = 170;
174    
175          const float MidRangeThres = 20;          if (data->type == XVID_TYPE_BVOP) return 0;
         const float UpperLimit = 200;  
         const float LowerLimit = 25;  
176    
177          /* Do this for all macroblocks individually  */          /* Do this for all macroblocks individually  */
178          for (j = 0; j < data->mb_height; j++) {          for (j = 0; j < data->mb_height; j++) {
179                  for (i = 0; i < data->mb_width; i++) {                  for (i = 0; i < data->mb_width; i++) {
180                          int k, l;                          int k, l, sum = 0;
181                          unsigned char *ptr;                          unsigned char *ptr;
182    
183                          /* Initialize the current quant value to the frame quant */                          /* Initialize the current quant value to the frame quant */
184                          handle->quant[j*data->mb_width + i] = (float)data->quant;                          handle->quant[j*data->mb_width + i] = (float)data->quant;
185    
                         /* Reset the val value */  
                         handle->val[j*data->mb_width + i] = 0.0f;  
   
186                          /* Next steps compute the luminance-masking */                          /* Next steps compute the luminance-masking */
187    
188                          /* Get the MB address */                          /* Get the MB address */
# Line 194  Line 192 
192                          /* Accumulate luminance */                          /* Accumulate luminance */
193                          for (k = 0; k < 16; k++)                          for (k = 0; k < 16; k++)
194                                  for (l = 0; l < 16; l++)                                  for (l = 0; l < 16; l++)
195                                          handle->val[j*data->mb_width + i] += ptr[k*data->current.stride[0] + l];                                           sum += ptr[k*data->current.stride[0] + l];
196    
197                          /* Normalize its value */                          handle->val[j*data->mb_width + i] = (float)sum/256.0f;
                         handle->val[j*data->mb_width + i] /= 256.0f;  
198    
199                          /* Accumulate the global frame luminance */                          /* Accumulate the global frame luminance */
200                          global += handle->val[j*data->mb_width + i];                          global += (float)sum/256.0f;
   
                         /* Count the number of middle luminance blocks */  
                         if ((handle->val[j*data->mb_width + i] > LowerLimit) &&  
                                 (handle->val[j*data->mb_width + i] < UpperLimit))  
                                 mid_range++;  
201                  }                  }
202          }          }
203    
204          /* Normalize the global luminance accumulator */          /* Normalize the global luminance accumulator */
205          global /= data->mb_width*data->mb_height;          global /= data->mb_width*data->mb_height;
206    
207            DarkThres = DarkThres*global/127.0f;
208            BrightThres = BrightThres*global/127.0f;
209    
210    
211          /* Apply luminance masking only to frames where the global luminance is          /* Apply luminance masking only to frames where the global luminance is
212           * higher than DarkThreshold and lower than Bright Threshold, or where           * higher than DarkThreshold and lower than Bright Threshold */
213           * "middle" luminance blocks are lower than its corresponding threshold */           if ((global < GlobalBrightThres) && (global > GlobalDarkThres)) {
          if (((global < GlobalBrightThres) && (global > GlobalDarkThres)) ||  
                 (mid_range < MidRangeThres)) {  
214    
215                  /* Apply the luminance masking formulas to all MBs */                  /* Apply the luminance masking formulas to all MBs */
216                  for (i = 0; i < data->mb_height; i++) {                  for (i = 0; i < data->mb_height; i++) {
217                          for (j = 0; j < data->mb_width; j++) {                          for (j = 0; j < data->mb_width; j++) {
218                                  if (handle->val[i*data->mb_width + j] < DarkThres)                                  if (handle->val[i*data->mb_width + j] < DarkThres)
219                                          handle->quant[i*data->mb_width + j] += DarkAmpl * (DarkThres - handle->val[i*data->mb_width + j]) / DarkThres;                                          handle->quant[i*data->mb_width + j] *= 1 + DarkAmpl * (DarkThres - handle->val[i*data->mb_width + j]) / DarkThres;
220                                  else if (handle->val[i*data->mb_width + j] > BrightThres)                                  else if (handle->val[i*data->mb_width + j] > BrightThres)
221                                          handle->quant[i*data->mb_width + j] += BrightAmpl * (handle->val[i*data->mb_width + j] - BrightThres) / (255 - BrightThres);                                          handle->quant[i*data->mb_width + j] *= 1 + BrightAmpl * (handle->val[i*data->mb_width + j] - BrightThres) / (255 - BrightThres);
222                          }                          }
223                  }                  }
224          }          }
# Line 234  Line 228 
228                                                                                           data->dquant,                                                                                           data->dquant,
229                                                                                           data->mb_width*data->mb_height,                                                                                           data->mb_width*data->mb_height,
230                                                                                           data->quant,                                                                                           data->quant,
231                                                                                           data->quant*2);                                                                                           MAX(2,data->quant + data->quant/2));
232    
233           /* Plugin job finished */           /* Plugin job finished */
234           return(0);           return(0);

Legend:
Removed from v.1.1.2.5  
changed lines
  Added in v.1.6

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