[cvs] / xvidcore / src / image / postprocessing.c Repository:
ViewVC logotype

Diff of /xvidcore/src/image/postprocessing.c

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

revision 1.1.2.1, Sat May 3 23:26:55 2003 UTC revision 1.2, Mon Mar 22 22:36:23 2004 UTC
# Line 1  Line 1 
1    /*****************************************************************************
2     *
3     *  XVID MPEG-4 VIDEO CODEC
4     *  - Postprocessing  functions -
5     *
6     *  Copyright(C) 2003 Michael Militzer <isibaar@xvid.org>
7     *
8     *  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
10     *  the Free Software Foundation ; either version 2 of the License, or
11     *  (at your option) any later version.
12     *
13     *  This program is distributed in the hope that it will be useful,
14     *  but WITHOUT ANY WARRANTY ; without even the implied warranty of
15     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     *  GNU General Public License for more details.
17     *
18     *  You should have received a copy of the GNU General Public License
19     *  along with this program ; if not, write to the Free Software
20     *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21     *
22     * $Id$
23     *
24     ****************************************************************************/
25    
26  #include <stdlib.h>  #include <stdlib.h>
27  #include <string.h>  #include <string.h>
28  #include <math.h>  #include <math.h>
# Line 5  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    /* Some useful (and fast) macros
37       Note that the MIN/MAX macros assume signed shift - if your compiler
38       doesn't do signed shifts, use the default MIN/MAX macros from global.h */
39    
40    #define FAST_MAX(x,y) ((x) - ((((x) - (y))>>(32 - 1)) & ((x) - (y))))
41    #define FAST_MIN(x,y) ((x) + ((((y) - (x))>>(32 - 1)) & ((y) - (x))))
42    #define FAST_ABS(x) ((((int)(x)) >> 31) ^ ((int)(x))) - (((int)(x)) >> 31)
43    #define ABS(X)    (((X)>0)?(X):-(X))
44    
45    void init_postproc(XVID_POSTPROC *tbls)
46    {
47            init_deblock(tbls);
48            init_noise(tbls);
49    }
50    
51  void  void
52  image_deblock(IMAGE * img, int edged_width,  image_postproc(XVID_POSTPROC *tbls, IMAGE * img, int edged_width,
53                                  const MACROBLOCK * mbs, int mb_width, int mb_height, int mb_stride,                                  const MACROBLOCK * mbs, int mb_width, int mb_height, int mb_stride,
54                                  int flags)                                  int flags, int frame_num, int bvop)
55  {  {
56          const int edged_width2 = edged_width /2;          const int edged_width2 = edged_width /2;
57          int i,j;          int i,j;
58          int quant;          int quant;
59    
60          /* luma: j,i in block units */          /* luma: j,i in block units */
61          if ((flags & XVID_DEC_DEBLOCKY))          if ((flags & XVID_DEBLOCKY))
62          {          {
63                  for (j = 1; j < mb_height*2; j++)               /* horizontal deblocking */                  for (j = 1; j < mb_height*2; j++)               /* horizontal deblocking */
64                  for (i = 0; i < mb_width*2; i++)                  for (i = 0; i < mb_width*2; i++)
65                  {                  {
66                          quant = mbs[(j+0)/2*mb_stride + (i/2)].quant;                          quant = mbs[(j+0)/2*mb_stride + (i/2)].quant;
67                          deblock8x8_h(img->y + j*8*edged_width + i*8, edged_width, quant);                          deblock8x8_h(tbls, img->y + j*8*edged_width + i*8, edged_width, quant);
68                  }                  }
69    
70                  for (j = 0; j < mb_height*2; j++)               /* vertical deblocking */                  for (j = 0; j < mb_height*2; j++)               /* vertical deblocking */
71                  for (i = 1; i < mb_width*2; i++)                  for (i = 1; i < mb_width*2; i++)
72                  {                  {
73                          quant = mbs[(j+0)/2*mb_stride + (i/2)].quant;                          quant = mbs[(j+0)/2*mb_stride + (i/2)].quant;
74                          deblock8x8_v(img->y + j*8*edged_width + i*8, edged_width, quant);                          deblock8x8_v(tbls, img->y + j*8*edged_width + i*8, edged_width, quant);
75                  }                  }
76          }          }
77    
78    
79          /* chroma */          /* chroma */
80          if ((flags & XVID_DEC_DEBLOCKUV))          if ((flags & XVID_DEBLOCKUV))
81          {          {
82                  for (j = 1; j < mb_height; j++)         /* horizontal deblocking */                  for (j = 1; j < mb_height; j++)         /* horizontal deblocking */
83                  for (i = 0; i < mb_width; i++)                  for (i = 0; i < mb_width; i++)
84                  {                  {
85                          quant = mbs[(j+0)*mb_stride + i].quant;                          quant = mbs[(j+0)*mb_stride + i].quant;
86                          deblock8x8_h(img->u + j*8*edged_width2 + i*8, edged_width2, quant);                          deblock8x8_h(tbls, img->u + j*8*edged_width2 + i*8, edged_width2, quant);
87                          deblock8x8_h(img->v + j*8*edged_width2 + i*8, edged_width2, quant);                          deblock8x8_h(tbls, img->v + j*8*edged_width2 + i*8, edged_width2, quant);
88                  }                  }
89    
90                  for (j = 0; j < mb_height; j++)         /* vertical deblocking */                  for (j = 0; j < mb_height; j++)         /* vertical deblocking */
91                  for (i = 1; i < mb_width; i++)                  for (i = 1; i < mb_width; i++)
92                  {                  {
93                          quant = mbs[(j+0)*mb_stride + i].quant;                          quant = mbs[(j+0)*mb_stride + i].quant;
94                          deblock8x8_v(img->u + j*8*edged_width2 + i*8, edged_width2, quant);                          deblock8x8_v(tbls, img->u + j*8*edged_width2 + i*8, edged_width2, quant);
95                          deblock8x8_v(img->v + j*8*edged_width2 + i*8, edged_width2, quant);                          deblock8x8_v(tbls, img->v + j*8*edged_width2 + i*8, edged_width2, quant);
                 }  
96          }          }
97  }  }
98    
99  #define THR1 2          if (!bvop)
100  #define THR2 6                  tbls->prev_quant = mbs->quant;
101    
102            if ((flags & XVID_FILMEFFECT))
103            {
104                    add_noise(tbls, img->y, img->y, edged_width, mb_width*16,
105                                      mb_height*16, frame_num % 3, tbls->prev_quant);
106            }
107    }
108    
109    /******************************************************************************/
110    
111    void init_deblock(XVID_POSTPROC *tbls)
112    {
113            int i;
114    
115            for(i = -255; i < 256; i++) {
116                    tbls->xvid_thresh_tbl[i + 255] = 0;
117                    if(ABS(i) < THR1)
118                            tbls->xvid_thresh_tbl[i + 255] = 1;
119                    tbls->xvid_abs_tbl[i + 255] = ABS(i);
120            }
121    }
122    
123    #define LOAD_DATA_HOR(x) \
124                    /* Load pixel addresses and data for filtering */ \
125                s[0] = *(v[0] = img - 5*stride + x); \
126                    s[1] = *(v[1] = img - 4*stride + x); \
127                    s[2] = *(v[2] = img - 3*stride + x); \
128                    s[3] = *(v[3] = img - 2*stride + x); \
129                    s[4] = *(v[4] = img - 1*stride + x); \
130                    s[5] = *(v[5] = img + 0*stride + x); \
131                    s[6] = *(v[6] = img + 1*stride + x); \
132                    s[7] = *(v[7] = img + 2*stride + x); \
133                    s[8] = *(v[8] = img + 3*stride + x); \
134                    s[9] = *(v[9] = img + 4*stride + x);
135    
136    #define LOAD_DATA_VER(x) \
137                    /* Load pixel addresses and data for filtering */ \
138                    s[0] = *(v[0] = img + x*stride - 5); \
139                    s[1] = *(v[1] = img + x*stride - 4); \
140                    s[2] = *(v[2] = img + x*stride - 3); \
141                    s[3] = *(v[3] = img + x*stride - 2); \
142                    s[4] = *(v[4] = img + x*stride - 1); \
143                    s[5] = *(v[5] = img + x*stride + 0); \
144                    s[6] = *(v[6] = img + x*stride + 1); \
145                    s[7] = *(v[7] = img + x*stride + 2); \
146                    s[8] = *(v[8] = img + x*stride + 3); \
147                    s[9] = *(v[9] = img + x*stride + 4);
148    
149    #define APPLY_FILTER_CORE \
150                    /* First, decide whether to use default or DC-offset mode */ \
151                    \
152                    eq_cnt = 0; \
153                    \
154                    eq_cnt += tbls->xvid_thresh_tbl[s[0] - s[1] + 255]; \
155                    eq_cnt += tbls->xvid_thresh_tbl[s[1] - s[2] + 255]; \
156                    eq_cnt += tbls->xvid_thresh_tbl[s[2] - s[3] + 255]; \
157                    eq_cnt += tbls->xvid_thresh_tbl[s[3] - s[4] + 255]; \
158                    eq_cnt += tbls->xvid_thresh_tbl[s[4] - s[5] + 255]; \
159                    eq_cnt += tbls->xvid_thresh_tbl[s[5] - s[6] + 255]; \
160                    eq_cnt += tbls->xvid_thresh_tbl[s[6] - s[7] + 255]; \
161                    eq_cnt += tbls->xvid_thresh_tbl[s[7] - s[8] + 255]; \
162                    \
163                    if(eq_cnt < THR2) { /* Default mode */  \
164                            int a30, a31, a32;                                      \
165                            int diff, limit;                                        \
166                                                                                                    \
167                            if(tbls->xvid_abs_tbl[(s[4] - s[5]) + 255] < quant) {                   \
168                                    a30 = ((s[3]<<1) - s[4] * 5 + s[5] * 5 - (s[6]<<1));    \
169                                    a31 = ((s[1]<<1) - s[2] * 5 + s[3] * 5 - (s[4]<<1));    \
170                                    a32 = ((s[5]<<1) - s[6] * 5 + s[7] * 5 - (s[8]<<1));    \
171                                                                                                                                                    \
172                                    diff = (5 * ((SIGN(a30) * MIN(FAST_ABS(a30), MIN(FAST_ABS(a31), FAST_ABS(a32)))) - a30) + 32) >> 6;     \
173                                    limit = (s[4] - s[5]) / 2;      \
174                                    \
175                                    if (limit > 0)                          \
176                                            diff = (diff < 0) ? 0 : ((diff > limit) ? limit : diff);        \
177                                    else    \
178                                            diff = (diff > 0) ? 0 : ((diff < limit) ? limit : diff);        \
179                                                                                                                                                                    \
180                                    *v[4] -= diff;  \
181                                    *v[5] += diff;  \
182                            }       \
183                    }       \
184                    else {  /* DC-offset mode */    \
185                            uint8_t p0, p9; \
186                            int min, max;   \
187                                                            \
188                            /* Now decide whether to apply smoothing filter or not */       \
189                            max = FAST_MAX(s[1], FAST_MAX(s[2], FAST_MAX(s[3], FAST_MAX(s[4], FAST_MAX(s[5], FAST_MAX(s[6], FAST_MAX(s[7], s[8])))))));     \
190                            min = FAST_MIN(s[1], FAST_MIN(s[2], FAST_MIN(s[3], FAST_MIN(s[4], FAST_MIN(s[5], FAST_MIN(s[6], FAST_MIN(s[7], s[8])))))));     \
191                            \
192                            if(((max-min)) < 2*quant) {     \
193                                                                                    \
194                                    /* Choose edge pixels */        \
195                                    p0 = (tbls->xvid_abs_tbl[(s[1] - s[0]) + 255] < quant) ? s[0] : s[1];   \
196                                    p9 = (tbls->xvid_abs_tbl[(s[8] - s[9]) + 255] < quant) ? s[9] : s[8];   \
197                                                                                                                                    \
198                                    *v[1] = (uint8_t) ((6*p0 + (s[1]<<2) + (s[2]<<1) + (s[3]<<1) + s[4] + s[5] + 8) >> 4);  \
199                                    *v[2] = (uint8_t) (((p0<<2) + (s[1]<<1) + (s[2]<<2) + (s[3]<<1) + (s[4]<<1) + s[5] + s[6] + 8) >> 4);   \
200                                    *v[3] = (uint8_t) (((p0<<1) + (s[1]<<1) + (s[2]<<1) + (s[3]<<2) + (s[4]<<1) + (s[5]<<1) + s[6] + s[7] + 8) >> 4);       \
201                                    *v[4] = (uint8_t) ((p0 + s[1] + (s[2]<<1) + (s[3]<<1) + (s[4]<<2) + (s[5]<<1) + (s[6]<<1) + s[7] + s[8] + 8) >> 4);     \
202                                    *v[5] = (uint8_t) ((s[1] + s[2] + (s[3]<<1) + (s[4]<<1) + (s[5]<<2) + (s[6]<<1) + (s[7]<<1) + s[8] + p9 + 8) >> 4);     \
203                                    *v[6] = (uint8_t) ((s[2] + s[3] + (s[4]<<1) + (s[5]<<1) + (s[6]<<2) + (s[7]<<1) + (s[8]<<1) + (p9<<1) + 8) >> 4);       \
204                                    *v[7] = (uint8_t) ((s[3] + s[4] + (s[5]<<1) + (s[6]<<1) + (s[7]<<2) + (s[8]<<1) + (p9<<2) + 8) >> 4);   \
205                                    *v[8] = (uint8_t) ((s[4] + s[5] + (s[6]<<1) + (s[7]<<1) + (s[8]<<2) + 6*p9 + 8) >> 4);  \
206                            }       \
207                    }
208    
209  void deblock8x8_h(uint8_t *img, int stride, int quant)  void deblock8x8_h(XVID_POSTPROC *tbls, uint8_t *img, int stride, int quant)
210  {  {
         int i, j;  
211          int eq_cnt;          int eq_cnt;
212          uint8_t *v[10], p0, p9;          uint8_t *v[10];
213          int min, max;          int32_t s[10];
         int a30, a31, a32;  
         int diff, limit;  
214    
215          for(j = 0; j < 8; j++) {          LOAD_DATA_HOR(0)
216                  eq_cnt = 0;          APPLY_FILTER_CORE
217    
218                  /* Load pixel addresses for filtering */          LOAD_DATA_HOR(1)
219            APPLY_FILTER_CORE
220    
221                  for(i = 0; i < 10; i++)          LOAD_DATA_HOR(2)
222                          v[i] = img + (i-5)*stride + j;          APPLY_FILTER_CORE
223    
224                  /* First, decide whether to use default or DC-offset mode */          LOAD_DATA_HOR(3)
225            APPLY_FILTER_CORE
226    
227                  for(i = 0; i < 9; i++)          LOAD_DATA_HOR(4)
228                  {          APPLY_FILTER_CORE
229                          if(ABS(*v[i] - *v[(i+1)]) < THR1)  
230                                  eq_cnt++;          LOAD_DATA_HOR(5)
231            APPLY_FILTER_CORE
232    
233            LOAD_DATA_HOR(6)
234            APPLY_FILTER_CORE
235    
236            LOAD_DATA_HOR(7)
237            APPLY_FILTER_CORE
238                  }                  }
239    
                 if(eq_cnt < THR2) { /* Default mode */  
240    
241                          a30 = (*v[3] * 2 - *v[4] * 5 + *v[5] * 5 - *v[6] * 2);  void deblock8x8_v(XVID_POSTPROC *tbls, uint8_t *img, int stride, int quant)
242    {
243            int eq_cnt;
244            uint8_t *v[10];
245            int s[10];
246    
247                          if(ABS(a30) < 8*quant) {          LOAD_DATA_VER(0)
248                                  a31 = (*v[1] * 2 - *v[2] * 5 + *v[3] * 5 - *v[4] * 2);          APPLY_FILTER_CORE
                                 a32 = (*v[5] * 2 - *v[6] * 5 + *v[7] * 5 - *v[8] * 2);  
249    
250                                  diff = (5 * ((SIGN(a30) * MIN(ABS(a30), MIN(ABS(a31), ABS(a32)))) - a30) + 32) >> 6;          LOAD_DATA_VER(1)
251                                  limit = (*v[4] - *v[5]) / 2;          APPLY_FILTER_CORE
252    
253                                  if (limit > 0)          LOAD_DATA_VER(2)
254                                          diff = (diff < 0) ? 0 : ((diff > limit) ? limit : diff);          APPLY_FILTER_CORE
                                 else  
                                         diff = (diff > 0) ? 0 : ((diff < limit) ? limit : diff);  
255    
256                                  *v[4] -= diff;          LOAD_DATA_VER(3)
257                                  *v[5] += diff;          APPLY_FILTER_CORE
                         }  
                 }  
                 else {  /* DC-offset mode */  
258    
259                          /* Now decide whether to apply smoothing filter or not */          LOAD_DATA_VER(4)
260                          max = MAX(*v[1], MAX(*v[2], MAX(*v[3], MAX(*v[4], MAX(*v[5], MAX(*v[6], MAX(*v[7], *v[8])))))));          APPLY_FILTER_CORE
                         min = MIN(*v[1], MIN(*v[2], MIN(*v[3], MIN(*v[4], MIN(*v[5], MIN(*v[6], MIN(*v[7], *v[8])))))));  
261    
262                          if((max-min) < 2*quant) {          LOAD_DATA_VER(5)
263            APPLY_FILTER_CORE
264    
265                                  /* Choose edge pixels */          LOAD_DATA_VER(6)
266                                  p0 = (ABS(*v[1]-*v[0]) < quant) ? *v[0] : *v[1];          APPLY_FILTER_CORE
                                 p9 = (ABS(*v[8]-*v[9]) < quant) ? *v[9] : *v[8];  
267    
268                                  *v[1] = (6*p0 + (*v[1]<<2) + (*v[2]<<1) + (*v[3]<<1) + *v[4] + *v[5] + 8) >> 4;          LOAD_DATA_VER(7)
269                                  *v[2] = ((p0<<2) + (*v[1]<<1) + (*v[2]<<2) + (*v[3]<<1) + (*v[4]<<1) + *v[5] + *v[6] + 8) >> 4;          APPLY_FILTER_CORE
                                 *v[3] = ((p0<<1) + (*v[1]<<1) + (*v[2]<<1) + (*v[3]<<2) + (*v[4]<<1) + (*v[5]<<1) + *v[6] + *v[7] + 8) >> 4;  
                                 *v[4] = (p0 + *v[1] + (*v[2]<<1) + (*v[3]<<1) + (*v[4]<<2) + (*v[5]<<1) + (*v[6]<<1) + *v[7] + *v[8] + 8) >> 4;  
                                 *v[5] = (*v[1] + *v[2] + (*v[3]<<1) + (*v[4]<<1) + (*v[5]<<2) + (*v[6]<<1) + (*v[7]<<1) + *v[8] + p9 + 8) >> 4;  
                                 *v[6] = (*v[2] + *v[3] + (*v[4]<<1) + (*v[5]<<1) + (*v[6]<<2) + (*v[7]<<1) + (*v[8]<<1) + (p9<<1) + 8) >> 4;  
                                 *v[7] = (*v[3] + *v[4] + (*v[5]<<1) + (*v[6]<<1) + (*v[7]<<2) + (*v[8]<<1) + (p9<<2) + 8) >> 4;  
                                 *v[8] = (*v[4] + *v[5] + (*v[6]<<1) + (*v[7]<<1) + (*v[8]<<2) + 6*p9 + 8) >> 4;  
                         }  
                 }  
         }  
270  }  }
271    
272    /******************************************************************************
273     *                                                                            *
274     *  Noise code below taken from MPlayer: http://www.mplayerhq.hu/             *
275     *  Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at>                 *
276     *                                                                                                                                                        *
277     ******************************************************************************/
278    
279    #define RAND_N(range) ((int) ((double)range * rand() / (RAND_MAX + 1.0)))
280    #define STRENGTH1 12
281    #define STRENGTH2 8
282    
283  void deblock8x8_v(uint8_t *img, int stride, int quant)  void init_noise(XVID_POSTPROC *tbls)
284  {  {
285          int i, j;          int i, j;
286          int eq_cnt;          int patt[4] = { -1,0,1,0 };
         uint8_t *v[10], p0, p9;  
         int min, max;  
         int a30, a31, a32;  
         int diff, limit;  
287    
288          for(j = 0; j < 8; j++) {          emms();
                 eq_cnt = 0;  
289    
290                  /* Load pixel addresses for filtering */          srand(123457);
291    
292                  for(i = 0; i < 10; i++)          for(i = 0, j = 0; i < MAX_NOISE; i++, j++)
293                          v[i] = img + j*stride + (i-5);          {
294                    double x1, x2, w, y1, y2;
295    
296                  /* First, decide whether to use default or DC-offset mode */                  do {
297                            x1 = 2.0 * rand() / (float) RAND_MAX - 1.0;
298                            x2 = 2.0 * rand() / (float) RAND_MAX - 1.0;
299                            w = x1 * x1 + x2 * x2;
300                    } while (w >= 1.0);
301    
302                  for(i = 0; i < 9; i++)                  w = sqrt((-2.0 * log(w)) / w);
303                  {                  y1 = x1 * w;
304                          if(ABS(*v[i] - *v[i+1]) < THR1)                  y2 = x1 * w;
                                 eq_cnt++;  
                 }  
305    
306                  if(eq_cnt < THR2) { /* Default mode */                  y1 *= STRENGTH1 / sqrt(3.0);
307                    y2 *= STRENGTH2 / sqrt(3.0);
308    
309                          a30 = (*v[3] * 2 - *v[4] * 5 + *v[5] * 5 - *v[6] * 2);              y1 /= 2;
310                    y2 /= 2;
311                y1 += patt[j%4] * STRENGTH1 * 0.35;
312                    y2 += patt[j%4] * STRENGTH2 * 0.35;
313    
314                          if(ABS(a30) < 8*quant) {                  if (y1 < -128) {
315                                  a31 = (*v[1] * 2 - *v[2] * 5 + *v[3] * 5 - *v[4] * 2);                          y1=-128;
316                                  a32 = (*v[5] * 2 - *v[6] * 5 + *v[7] * 5 - *v[8] * 2);                  }
317                    else if (y1 > 127) {
318                            y1= 127;
319                    }
320    
321                                  diff = (5 * ((SIGN(a30) * MIN(ABS(a30), MIN(ABS(a31), ABS(a32)))) - a30) + 32) >> 6;                  if (y2 < -128) {
322                                  limit = (*v[4] - *v[5]) / 2;                          y2=-128;
323                    }
324                    else if (y2 > 127) {
325                            y2= 127;
326                    }
327    
328                                  if (limit > 0)                  y1 /= 3.0;
329                                          diff = (diff < 0) ? 0 : ((diff > limit) ? limit : diff);                  y2 /= 3.0;
330                                  else                  tbls->xvid_noise1[i] = (int) y1;
331                                          diff = (diff > 0) ? 0 : ((diff < limit) ? limit : diff);                  tbls->xvid_noise2[i] = (int) y2;
332    
333                                  *v[4] -= diff;                  if (RAND_N(6) == 0) {
334                                  *v[5] += diff;                          j--;
335                          }                          }
336                  }                  }
                 else {  /* DC-offset mode */  
337    
338                          /* Now decide whether to apply smoothing filter or not */          for (i = 0; i < MAX_RES; i++)
339                          max = MAX(*v[1], MAX(*v[2], MAX(*v[3], MAX(*v[4], MAX(*v[5], MAX(*v[6], MAX(*v[7], *v[8])))))));                  for (j = 0; j < 3; j++) {
340                          min = MIN(*v[1], MIN(*v[2], MIN(*v[3], MIN(*v[4], MIN(*v[5], MIN(*v[6], MIN(*v[7], *v[8])))))));                          tbls->xvid_prev_shift[i][j] = tbls->xvid_noise1 + (rand() & (MAX_SHIFT - 1));
341                            tbls->xvid_prev_shift[i][3 + j] = tbls->xvid_noise2 + (rand() & (MAX_SHIFT - 1));
342                    }
343    }
344    
345                          if((max-min) < 2*quant) {  void add_noise(XVID_POSTPROC *tbls, uint8_t *dst, uint8_t *src, int stride, int width, int height, int shiftptr, int quant)
346    {
347            int x, y;
348            int shift = 0;
349            int add = (quant < 5) ? 3 : 0;
350            int8_t *noise = (quant < 5) ? tbls->xvid_noise2 : tbls->xvid_noise1;
351    
352                                  /* Choose edge pixels */          for(y = 0; y < height; y++)
353                                  p0 = (ABS(*v[1]-*v[0]) < quant) ? *v[0] : *v[1];          {
354                                  p9 = (ABS(*v[8]-*v[9]) < quant) ? *v[9] : *v[8];          int8_t *src2 = (int8_t *) src;
355    
356                                  *v[1] = (6*p0 + (*v[1]<<2) + (*v[2]<<1) + (*v[3]<<1) + *v[4] + *v[5] + 8) >> 4;                  shift = rand() & (MAX_SHIFT - 1);
357                                  *v[2] = ((p0<<2) + (*v[1]<<1) + (*v[2]<<2) + (*v[3]<<1) + (*v[4]<<1) + *v[5] + *v[6] + 8) >> 4;  
358                                  *v[3] = ((p0<<1) + (*v[1]<<1) + (*v[2]<<1) + (*v[3]<<2) + (*v[4]<<1) + (*v[5]<<1) + *v[6] + *v[7] + 8) >> 4;                  shift &= ~7;
359                                  *v[4] = (p0 + *v[1] + (*v[2]<<1) + (*v[3]<<1) + (*v[4]<<2) + (*v[5]<<1) + (*v[6]<<1) + *v[7] + *v[8] + 8) >> 4;                  for(x = 0; x < width; x++)
360                                  *v[5] = (*v[1] + *v[2] + (*v[3]<<1) + (*v[4]<<1) + (*v[5]<<2) + (*v[6]<<1) + (*v[7]<<1) + *v[8] + p9 + 8) >> 4;                  {
361                                  *v[6] = (*v[2] + *v[3] + (*v[4]<<1) + (*v[5]<<1) + (*v[6]<<2) + (*v[7]<<1) + (*v[8]<<1) + (p9<<1) + 8) >> 4;                          const int n = tbls->xvid_prev_shift[y][0 + add][x] + tbls->xvid_prev_shift[y][1 + add][x] +
362                                  *v[7] = (*v[3] + *v[4] + (*v[5]<<1) + (*v[6]<<1) + (*v[7]<<2) + (*v[8]<<1) + (p9<<2) + 8) >> 4;                                            tbls->xvid_prev_shift[y][2 + add][x];
363                                  *v[8] = (*v[4] + *v[5] + (*v[6]<<1) + (*v[7]<<1) + (*v[8]<<2) + 6*p9 + 8) >> 4;  
364                          }                          dst[x] = src2[x] + ((n * src2[x]) >> 7);
365                  }                  }
366    
367                    tbls->xvid_prev_shift[y][shiftptr + add] = noise + shift;
368    
369                    dst += stride;
370                    src += stride;
371          }          }
372  }  }

Legend:
Removed from v.1.1.2.1  
changed lines
  Added in v.1.2

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