[svn] / branches / dev-api-4 / xvidcore / src / image / postprocessing.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/src/image/postprocessing.c

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

revision 1253, Wed Dec 10 15:07:42 2003 UTC revision 1270, Wed Dec 17 17:07:38 2003 UTC
# Line 19  Line 19 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21   *   *
22   * $Id: postprocessing.c,v 1.1.4.2 2003-12-10 15:07:42 edgomez Exp $   * $Id: postprocessing.c,v 1.1.4.3 2003-12-17 17:07:38 Isibaar Exp $
23   *   *
24   ****************************************************************************/   ****************************************************************************/
25    
# Line 30  Line 30 
30  #include "../portab.h"  #include "../portab.h"
31  #include "../global.h"  #include "../global.h"
32  #include "image.h"  #include "image.h"
33    #include "../utils/emms.h"
34  #include "postprocessing.h"  #include "postprocessing.h"
35    
36  /* Filtering thresholds */  /* Filtering thresholds */
# Line 46  Line 47 
47  #define FAST_ABS(x) ((((int)(x)) >> 31) ^ ((int)(x))) - (((int)(x)) >> 31)  #define FAST_ABS(x) ((((int)(x)) >> 31) ^ ((int)(x))) - (((int)(x)) >> 31)
48  #define ABS(X)    (((X)>0)?(X):-(X))  #define ABS(X)    (((X)>0)?(X):-(X))
49    
 static int8_t xvid_thresh_tbl[510];  
 static int8_t xvid_abs_tbl[510];  
   
50  void init_postproc(void)  void init_postproc(void)
51  {  {
52          int i;          init_deblock();
53            init_noise();
         for(i = -255; i < 256; i++) {  
                 xvid_thresh_tbl[i + 255] = 0;  
                 if(ABS(i) < THR1)  
                         xvid_thresh_tbl[i + 255] = 1;  
                 xvid_abs_tbl[i + 255] = ABS(i);  
         }  
54  }  }
55    
56  void  void
57  image_deblock(IMAGE * img, int edged_width,  image_postproc(IMAGE * img, int edged_width,
58                                  const MACROBLOCK * mbs, int mb_width, int mb_height, int mb_stride,                                  const MACROBLOCK * mbs, int mb_width, int mb_height, int mb_stride,
59                                  int flags)                                  int flags, int frame_num)
60  {  {
61          const int edged_width2 = edged_width /2;          const int edged_width2 = edged_width /2;
62          int i,j;          int i,j;
# Line 108  Line 100 
100                          deblock8x8_v(img->v + j*8*edged_width2 + i*8, edged_width2, quant);                          deblock8x8_v(img->v + j*8*edged_width2 + i*8, edged_width2, quant);
101                  }                  }
102          }          }
103    
104            if ((flags & XVID_FILMEFFECT))
105            {
106                    add_noise(img->y, img->y, edged_width, mb_width*16, mb_height*16, frame_num % 3);
107            }
108    }
109    
110    /******************************************************************************/
111    
112    static int8_t xvid_thresh_tbl[510];
113    static int8_t xvid_abs_tbl[510];
114    
115    void init_deblock(void)
116    {
117            int i;
118    
119            for(i = -255; i < 256; i++) {
120                    xvid_thresh_tbl[i + 255] = 0;
121                    if(ABS(i) < THR1)
122                            xvid_thresh_tbl[i + 255] = 1;
123                    xvid_abs_tbl[i + 255] = ABS(i);
124            }
125  }  }
126    
127  #define LOAD_DATA_HOR(x) \  #define LOAD_DATA_HOR(x) \
# Line 154  Line 168 
168                          int a30, a31, a32;                                      \                          int a30, a31, a32;                                      \
169                          int diff, limit;                                        \                          int diff, limit;                                        \
170                                                                                                  \                                                                                                  \
171                            if(xvid_abs_tbl[(s[4] - s[5]) + 255] < quant) {                 \
172                          a30 = ((s[3]<<1) - s[4] * 5 + s[5] * 5 - (s[6]<<1));    \                          a30 = ((s[3]<<1) - s[4] * 5 + s[5] * 5 - (s[6]<<1));    \
                                                                                                                                         \  
                         if(xvid_abs_tbl[a30 + 255] < 8*quant) {                                                         \  
173                                  a31 = ((s[1]<<1) - s[2] * 5 + s[3] * 5 - (s[4]<<1));    \                                  a31 = ((s[1]<<1) - s[2] * 5 + s[3] * 5 - (s[4]<<1));    \
174                                  a32 = ((s[5]<<1) - s[6] * 5 + s[7] * 5 - (s[8]<<1));    \                                  a32 = ((s[5]<<1) - s[6] * 5 + s[7] * 5 - (s[8]<<1));    \
175                                                                                                                                                  \                                                                                                                                                  \
# Line 259  Line 272 
272          LOAD_DATA_VER(7)          LOAD_DATA_VER(7)
273          APPLY_FILTER_CORE          APPLY_FILTER_CORE
274  }  }
275    
276    /******************************************************************************
277     *                                                                            *
278     *  Noise code below taken from MPlayer: http://www.mplayerhq.hu/             *
279     *  Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>                 *
280     *                                                                                                                                                        *
281     ******************************************************************************/
282    
283    #define MAX_NOISE 4096
284    #define MAX_SHIFT 1024
285    #define MAX_RES (MAX_NOISE - MAX_SHIFT)
286    
287    #define RAND_N(range) ((int) ((double)range * rand() / (RAND_MAX + 1.0)))
288    
289    #define STRENGTH 13
290    
291    static int8_t xvid_noise[MAX_NOISE * sizeof(int8_t)];
292    static int8_t *xvid_prev_shift[MAX_RES][3];
293    
294    void init_noise(void)
295    {
296            int i, j;
297            int patt[4] = { -1,0,1,0 };
298    
299            emms();
300    
301            srand(123457);
302    
303            for(i = 0, j = 0; i < MAX_NOISE; i++, j++)
304            {
305                    double x1, x2, w, y1;
306    
307                    do {
308                            x1 = 2.0 * rand() / (float) RAND_MAX - 1.0;
309                            x2 = 2.0 * rand() / (float) RAND_MAX - 1.0;
310                            w = x1 * x1 + x2 * x2;
311                    } while (w >= 1.0);
312    
313                    w = sqrt((-2.0 * log(w)) / w);
314                    y1 = x1 * w;
315                    y1 *= STRENGTH / sqrt(3.0);
316    
317                y1 /= 2;
318                y1 += patt[j%4] * STRENGTH * 0.35;
319    
320                    if (y1 < -128) {
321                            y1=-128;
322                    }
323                    else if (y1 > 127) {
324                            y1= 127;
325                    }
326    
327                    y1 /= 3.0;
328                    xvid_noise[i] = (int) y1;
329    
330                    if (RAND_N(6) == 0) {
331                            j--;
332                    }
333            }
334    
335            for (i = 0; i < MAX_RES; i++)
336                    for (j = 0; j < 3; j++) {
337                            xvid_prev_shift[i][j] = xvid_noise + (rand() & (MAX_SHIFT - 1));
338                    }
339    }
340    
341    void add_noise(uint8_t *dst, uint8_t *src, int stride, int width, int height, int shiftptr)
342    {
343            int x, y;
344            int shift = 0;
345    
346            for(y = 0; y < height; y++)
347            {
348            int8_t *src2 = (int8_t *) src;
349    
350                    shift = rand() & (MAX_SHIFT - 1);
351    
352                    shift &= ~7;
353                    for(x = 0; x < width; x++)
354                    {
355                            const int n = xvid_prev_shift[y][0][x] + xvid_prev_shift[y][1][x] +
356                                              xvid_prev_shift[y][2][x];
357    
358                            dst[x] = src2[x] + ((n * src2[x]) >> 7);
359                    }
360    
361                    xvid_prev_shift[y][shiftptr] = xvid_noise + shift;
362    
363                    dst += stride;
364                    src += stride;
365            }
366    }

Legend:
Removed from v.1253  
changed lines
  Added in v.1270

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