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

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

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