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

Annotation of /trunk/xvidcore/src/image/postprocessing.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1911 - (view) (download)

1 : edgomez 1382 /*****************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * - Postprocessing functions -
5 :     *
6 : Isibaar 1911 * Copyright(C) 2003-2010 Michael Militzer <isibaar@xvid.org>
7 : syskin 1437 * 2004 Marc Fauconneau
8 : edgomez 1382 *
9 :     * This program is free software ; you can redistribute it and/or modify
10 :     * it under the terms of the GNU General Public License as published by
11 :     * the Free Software Foundation ; either version 2 of the License, or
12 :     * (at your option) any later version.
13 :     *
14 :     * This program is distributed in the hope that it will be useful,
15 :     * but WITHOUT ANY WARRANTY ; without even the implied warranty of
16 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 :     * GNU General Public License for more details.
18 :     *
19 :     * You should have received a copy of the GNU General Public License
20 :     * along with this program ; if not, write to the Free Software
21 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 :     *
23 : Isibaar 1911 * $Id: postprocessing.c,v 1.6 2010-12-18 10:13:38 Isibaar Exp $
24 : edgomez 1382 *
25 :     ****************************************************************************/
26 :    
27 :     #include <stdlib.h>
28 :     #include <string.h>
29 :     #include <math.h>
30 :    
31 :     #include "../portab.h"
32 :     #include "../global.h"
33 :     #include "image.h"
34 :     #include "../utils/emms.h"
35 :     #include "postprocessing.h"
36 :    
37 : suxen_drol 1397 /* function pointers */
38 :     IMAGEBRIGHTNESS_PTR image_brightness;
39 :    
40 :    
41 : edgomez 1382 /* Some useful (and fast) macros
42 :     Note that the MIN/MAX macros assume signed shift - if your compiler
43 :     doesn't do signed shifts, use the default MIN/MAX macros from global.h */
44 :    
45 :     #define FAST_MAX(x,y) ((x) - ((((x) - (y))>>(32 - 1)) & ((x) - (y))))
46 :     #define FAST_MIN(x,y) ((x) + ((((y) - (x))>>(32 - 1)) & ((y) - (x))))
47 :     #define FAST_ABS(x) ((((int)(x)) >> 31) ^ ((int)(x))) - (((int)(x)) >> 31)
48 :     #define ABS(X) (((X)>0)?(X):-(X))
49 :    
50 :     void init_postproc(XVID_POSTPROC *tbls)
51 :     {
52 :     init_deblock(tbls);
53 :     init_noise(tbls);
54 :     }
55 :    
56 : Isibaar 1911 void
57 :     stripe_deblock_h(SMPDeblock *h)
58 : edgomez 1382 {
59 : Isibaar 1911 const int stride = h->stride;
60 :     const int stride2 = stride /2;
61 :    
62 : edgomez 1382 int i,j;
63 :     int quant;
64 :    
65 :     /* luma: j,i in block units */
66 : Isibaar 1911 if ((h->flags & XVID_DEBLOCKY))
67 : edgomez 1382 {
68 : Isibaar 1911 int dering = h->flags & XVID_DERINGY;
69 :    
70 :     for (j = 1; j < h->stop_y; j++) /* horizontal luma deblocking */
71 :     for (i = h->start_x; i < h->stop_x; i++)
72 : edgomez 1382 {
73 : Isibaar 1911 quant = h->mbs[(j+0)/2*h->mb_stride + (i/2)].quant;
74 :     deblock8x8_h(h->tbls, h->img->y + j*8*stride + i*8, stride, quant, dering);
75 : edgomez 1382 }
76 : Isibaar 1911 }
77 : edgomez 1382
78 : Isibaar 1911 /* chroma */
79 :     if ((h->flags & XVID_DEBLOCKUV))
80 :     {
81 :     int dering = h->flags & XVID_DERINGUV;
82 :    
83 :     for (j = 1; j < h->stop_y/2; j++) /* horizontal deblocking */
84 :     for (i = h->start_x/2; i < h->stop_x/2; i++)
85 : edgomez 1382 {
86 : Isibaar 1911 quant = h->mbs[(j+0)*h->mb_stride + i].quant;
87 :     deblock8x8_h(h->tbls, h->img->u + j*8*stride2 + i*8, stride2, quant, dering);
88 :     deblock8x8_h(h->tbls, h->img->v + j*8*stride2 + i*8, stride2, quant, dering);
89 : edgomez 1382 }
90 :     }
91 : Isibaar 1911 }
92 : edgomez 1382
93 : Isibaar 1911 void
94 :     stripe_deblock_v(SMPDeblock *h)
95 :     {
96 :     const int stride = h->stride;
97 :     const int stride2 = stride /2;
98 : edgomez 1382
99 : Isibaar 1911 int i,j;
100 :     int quant;
101 :    
102 :     /* luma: j,i in block units */
103 :     if ((h->flags & XVID_DEBLOCKY))
104 : edgomez 1382 {
105 : Isibaar 1911 int dering = h->flags & XVID_DERINGY;
106 : syskin 1437
107 : Isibaar 1911 for (j = h->start_y; j < h->stop_y; j++) /* vertical deblocking */
108 :     for (i = 1; i < h->stop_x; i++)
109 : edgomez 1382 {
110 : Isibaar 1911 quant = h->mbs[(j+0)/2*h->mb_stride + (i/2)].quant;
111 :     deblock8x8_v(h->tbls, h->img->y + j*8*stride + i*8, stride, quant, dering);
112 : edgomez 1382 }
113 : Isibaar 1911 }
114 : edgomez 1382
115 : Isibaar 1911 /* chroma */
116 :     if ((h->flags & XVID_DEBLOCKUV))
117 :     {
118 :     int dering = h->flags & XVID_DERINGUV;
119 :    
120 :     for (j = h->start_y/2; j < h->stop_y/2; j++) /* vertical deblocking */
121 :     for (i = 1; i < h->stop_x/2; i++)
122 : edgomez 1382 {
123 : Isibaar 1911 quant = h->mbs[(j+0)*h->mb_stride + i].quant;
124 :     deblock8x8_v(h->tbls, h->img->u + j*8*stride2 + i*8, stride2, quant, dering);
125 :     deblock8x8_v(h->tbls, h->img->v + j*8*stride2 + i*8, stride2, quant, dering);
126 : edgomez 1382 }
127 :     }
128 : Isibaar 1911 }
129 : edgomez 1382
130 : Isibaar 1911 void
131 :     image_postproc(XVID_POSTPROC *tbls, IMAGE * img, int edged_width,
132 :     const MACROBLOCK * mbs, int mb_width, int mb_height, int mb_stride,
133 :     int flags, int brightness, int frame_num, int bvop, int threads)
134 :     {
135 :     int k, num_threads = MAX(1, MIN(threads, 4));
136 :     SMPDeblock data[4];
137 :     void *status = NULL;
138 :    
139 :     /* horizontal deblocking, dispatch threads */
140 :     for (k = 0; k < num_threads; k++) {
141 :     data[k].flags = flags;
142 :     data[k].img = img;
143 :     data[k].mb_stride = mb_stride;
144 :     data[k].mbs = mbs;
145 :     data[k].stride = edged_width;
146 :     data[k].tbls = tbls;
147 :    
148 :     data[k].start_x = (k*mb_width / num_threads)*2;
149 :     data[k].stop_x = ((k+1)*mb_width / num_threads)*2;
150 :    
151 :     data[k].stop_y = mb_height*2;
152 :     }
153 :    
154 :     /* create threads */
155 :     for (k = 1; k < num_threads; k++) {
156 :     pthread_create(&data[k].handle, NULL,
157 :     (void*)stripe_deblock_h, (void*)&data[k]);
158 :     }
159 :    
160 :     stripe_deblock_h(&data[0]);
161 :    
162 :     /* wait until all threads are finished */
163 :     for (k = 1; k < num_threads; k++) {
164 :     pthread_join(data[k].handle, &status);
165 :     }
166 :    
167 :    
168 :     /* vertical deblocking, dispatch threads */
169 :     for (k = 0; k < num_threads; k++) {
170 :     data[k].start_y = (k*mb_height / num_threads)*2;
171 :     data[k].stop_y = ((k+1)*mb_height / num_threads)*2;
172 :     data[k].stop_x = mb_width*2;
173 :     }
174 :    
175 :     /* create threads */
176 :     for (k = 1; k < num_threads; k++) {
177 :     pthread_create(&data[k].handle, NULL,
178 :     (void*)stripe_deblock_v, (void*)&data[k]);
179 :     }
180 :    
181 :     stripe_deblock_v(&data[0]);
182 :    
183 :     /* wait until all threads are finished */
184 :     for (k = 1; k < num_threads; k++) {
185 :     pthread_join(data[k].handle, &status);
186 :     }
187 :    
188 :    
189 : edgomez 1382 if (!bvop)
190 :     tbls->prev_quant = mbs->quant;
191 :    
192 :     if ((flags & XVID_FILMEFFECT))
193 :     {
194 :     add_noise(tbls, img->y, img->y, edged_width, mb_width*16,
195 :     mb_height*16, frame_num % 3, tbls->prev_quant);
196 :     }
197 : suxen_drol 1397
198 :     if (brightness != 0) {
199 :     image_brightness(img->y, edged_width, mb_width*16, mb_height*16, brightness);
200 :     }
201 : edgomez 1382 }
202 :    
203 :     /******************************************************************************/
204 :    
205 :     void init_deblock(XVID_POSTPROC *tbls)
206 :     {
207 :     int i;
208 :    
209 :     for(i = -255; i < 256; i++) {
210 :     tbls->xvid_thresh_tbl[i + 255] = 0;
211 :     if(ABS(i) < THR1)
212 :     tbls->xvid_thresh_tbl[i + 255] = 1;
213 :     tbls->xvid_abs_tbl[i + 255] = ABS(i);
214 :     }
215 :     }
216 :    
217 :     #define LOAD_DATA_HOR(x) \
218 :     /* Load pixel addresses and data for filtering */ \
219 :     s[0] = *(v[0] = img - 5*stride + x); \
220 :     s[1] = *(v[1] = img - 4*stride + x); \
221 :     s[2] = *(v[2] = img - 3*stride + x); \
222 :     s[3] = *(v[3] = img - 2*stride + x); \
223 :     s[4] = *(v[4] = img - 1*stride + x); \
224 :     s[5] = *(v[5] = img + 0*stride + x); \
225 :     s[6] = *(v[6] = img + 1*stride + x); \
226 :     s[7] = *(v[7] = img + 2*stride + x); \
227 :     s[8] = *(v[8] = img + 3*stride + x); \
228 :     s[9] = *(v[9] = img + 4*stride + x);
229 :    
230 :     #define LOAD_DATA_VER(x) \
231 :     /* Load pixel addresses and data for filtering */ \
232 :     s[0] = *(v[0] = img + x*stride - 5); \
233 :     s[1] = *(v[1] = img + x*stride - 4); \
234 :     s[2] = *(v[2] = img + x*stride - 3); \
235 :     s[3] = *(v[3] = img + x*stride - 2); \
236 :     s[4] = *(v[4] = img + x*stride - 1); \
237 :     s[5] = *(v[5] = img + x*stride + 0); \
238 :     s[6] = *(v[6] = img + x*stride + 1); \
239 :     s[7] = *(v[7] = img + x*stride + 2); \
240 :     s[8] = *(v[8] = img + x*stride + 3); \
241 :     s[9] = *(v[9] = img + x*stride + 4);
242 :    
243 : syskin 1437 #define APPLY_DERING(x) \
244 :     *v[x] = (e[x] == 0) ? ( \
245 :     (e[x-1] == 0) ? ( \
246 :     (e[x+1] == 0) ? \
247 :     ((s[x-1]+s[x]*2+s[x+1])>>2) \
248 :     : ((s[x-1]+s[x])>>1) ) \
249 :     : ((s[x]+s[x+1])>>1) ) \
250 :     : s[x];
251 :    
252 : edgomez 1382 #define APPLY_FILTER_CORE \
253 :     /* First, decide whether to use default or DC-offset mode */ \
254 :     \
255 :     eq_cnt = 0; \
256 :     \
257 :     eq_cnt += tbls->xvid_thresh_tbl[s[0] - s[1] + 255]; \
258 :     eq_cnt += tbls->xvid_thresh_tbl[s[1] - s[2] + 255]; \
259 :     eq_cnt += tbls->xvid_thresh_tbl[s[2] - s[3] + 255]; \
260 :     eq_cnt += tbls->xvid_thresh_tbl[s[3] - s[4] + 255]; \
261 :     eq_cnt += tbls->xvid_thresh_tbl[s[4] - s[5] + 255]; \
262 :     eq_cnt += tbls->xvid_thresh_tbl[s[5] - s[6] + 255]; \
263 :     eq_cnt += tbls->xvid_thresh_tbl[s[6] - s[7] + 255]; \
264 :     eq_cnt += tbls->xvid_thresh_tbl[s[7] - s[8] + 255]; \
265 :     \
266 :     if(eq_cnt < THR2) { /* Default mode */ \
267 :     int a30, a31, a32; \
268 :     int diff, limit; \
269 :     \
270 :     if(tbls->xvid_abs_tbl[(s[4] - s[5]) + 255] < quant) { \
271 :     a30 = ((s[3]<<1) - s[4] * 5 + s[5] * 5 - (s[6]<<1)); \
272 :     a31 = ((s[1]<<1) - s[2] * 5 + s[3] * 5 - (s[4]<<1)); \
273 :     a32 = ((s[5]<<1) - s[6] * 5 + s[7] * 5 - (s[8]<<1)); \
274 :     \
275 :     diff = (5 * ((SIGN(a30) * MIN(FAST_ABS(a30), MIN(FAST_ABS(a31), FAST_ABS(a32)))) - a30) + 32) >> 6; \
276 :     limit = (s[4] - s[5]) / 2; \
277 :     \
278 :     if (limit > 0) \
279 :     diff = (diff < 0) ? 0 : ((diff > limit) ? limit : diff); \
280 :     else \
281 :     diff = (diff > 0) ? 0 : ((diff < limit) ? limit : diff); \
282 :     \
283 :     *v[4] -= diff; \
284 :     *v[5] += diff; \
285 :     } \
286 : syskin 1437 if (dering) { \
287 :     e[0] = (tbls->xvid_abs_tbl[(s[0] - s[1]) + 255] > quant + DERING_STRENGTH) ? 1 : 0; \
288 :     e[1] = (tbls->xvid_abs_tbl[(s[1] - s[2]) + 255] > quant + DERING_STRENGTH) ? 1 : 0; \
289 :     e[2] = (tbls->xvid_abs_tbl[(s[2] - s[3]) + 255] > quant + DERING_STRENGTH) ? 1 : 0; \
290 :     e[3] = (tbls->xvid_abs_tbl[(s[3] - s[4]) + 255] > quant + DERING_STRENGTH) ? 1 : 0; \
291 :     e[4] = (tbls->xvid_abs_tbl[(s[4] - s[5]) + 255] > quant + DERING_STRENGTH) ? 1 : 0; \
292 :     e[5] = (tbls->xvid_abs_tbl[(s[5] - s[6]) + 255] > quant + DERING_STRENGTH) ? 1 : 0; \
293 :     e[6] = (tbls->xvid_abs_tbl[(s[6] - s[7]) + 255] > quant + DERING_STRENGTH) ? 1 : 0; \
294 :     e[7] = (tbls->xvid_abs_tbl[(s[7] - s[8]) + 255] > quant + DERING_STRENGTH) ? 1 : 0; \
295 :     e[8] = (tbls->xvid_abs_tbl[(s[8] - s[9]) + 255] > quant + DERING_STRENGTH) ? 1 : 0; \
296 :     \
297 :     e[1] |= e[0]; \
298 :     e[2] |= e[1]; \
299 :     e[3] |= e[2]; \
300 :     e[4] |= e[3]; \
301 :     e[5] |= e[4]; \
302 :     e[6] |= e[5]; \
303 :     e[7] |= e[6]; \
304 :     e[8] |= e[7]; \
305 :     e[9] = e[8]; \
306 :     \
307 :     APPLY_DERING(1) \
308 :     APPLY_DERING(2) \
309 :     APPLY_DERING(3) \
310 :     APPLY_DERING(4) \
311 :     APPLY_DERING(5) \
312 :     APPLY_DERING(6) \
313 :     APPLY_DERING(7) \
314 :     APPLY_DERING(8) \
315 :     } \
316 : edgomez 1382 } \
317 :     else { /* DC-offset mode */ \
318 :     uint8_t p0, p9; \
319 :     int min, max; \
320 :     \
321 :     /* Now decide whether to apply smoothing filter or not */ \
322 :     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]))))))); \
323 :     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]))))))); \
324 :     \
325 :     if(((max-min)) < 2*quant) { \
326 :     \
327 :     /* Choose edge pixels */ \
328 :     p0 = (tbls->xvid_abs_tbl[(s[1] - s[0]) + 255] < quant) ? s[0] : s[1]; \
329 :     p9 = (tbls->xvid_abs_tbl[(s[8] - s[9]) + 255] < quant) ? s[9] : s[8]; \
330 :     \
331 :     *v[1] = (uint8_t) ((6*p0 + (s[1]<<2) + (s[2]<<1) + (s[3]<<1) + s[4] + s[5] + 8) >> 4); \
332 :     *v[2] = (uint8_t) (((p0<<2) + (s[1]<<1) + (s[2]<<2) + (s[3]<<1) + (s[4]<<1) + s[5] + s[6] + 8) >> 4); \
333 :     *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); \
334 :     *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); \
335 :     *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); \
336 :     *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); \
337 :     *v[7] = (uint8_t) ((s[3] + s[4] + (s[5]<<1) + (s[6]<<1) + (s[7]<<2) + (s[8]<<1) + (p9<<2) + 8) >> 4); \
338 :     *v[8] = (uint8_t) ((s[4] + s[5] + (s[6]<<1) + (s[7]<<1) + (s[8]<<2) + 6*p9 + 8) >> 4); \
339 :     } \
340 :     }
341 :    
342 : syskin 1437 void deblock8x8_h(XVID_POSTPROC *tbls, uint8_t *img, int stride, int quant, int dering)
343 : edgomez 1382 {
344 :     int eq_cnt;
345 :     uint8_t *v[10];
346 : syskin 1437 int s[10];
347 :     int e[10];
348 : edgomez 1382
349 :     LOAD_DATA_HOR(0)
350 :     APPLY_FILTER_CORE
351 :    
352 :     LOAD_DATA_HOR(1)
353 :     APPLY_FILTER_CORE
354 :    
355 :     LOAD_DATA_HOR(2)
356 :     APPLY_FILTER_CORE
357 :    
358 :     LOAD_DATA_HOR(3)
359 :     APPLY_FILTER_CORE
360 :    
361 :     LOAD_DATA_HOR(4)
362 :     APPLY_FILTER_CORE
363 :    
364 :     LOAD_DATA_HOR(5)
365 :     APPLY_FILTER_CORE
366 :    
367 :     LOAD_DATA_HOR(6)
368 :     APPLY_FILTER_CORE
369 :    
370 :     LOAD_DATA_HOR(7)
371 :     APPLY_FILTER_CORE
372 :     }
373 :    
374 :    
375 : syskin 1437 void deblock8x8_v(XVID_POSTPROC *tbls, uint8_t *img, int stride, int quant, int dering)
376 : edgomez 1382 {
377 :     int eq_cnt;
378 :     uint8_t *v[10];
379 :     int s[10];
380 : syskin 1437 int e[10];
381 : edgomez 1382
382 :     LOAD_DATA_VER(0)
383 :     APPLY_FILTER_CORE
384 :    
385 :     LOAD_DATA_VER(1)
386 :     APPLY_FILTER_CORE
387 :    
388 :     LOAD_DATA_VER(2)
389 :     APPLY_FILTER_CORE
390 :    
391 :     LOAD_DATA_VER(3)
392 :     APPLY_FILTER_CORE
393 :    
394 :     LOAD_DATA_VER(4)
395 :     APPLY_FILTER_CORE
396 :    
397 :     LOAD_DATA_VER(5)
398 :     APPLY_FILTER_CORE
399 :    
400 :     LOAD_DATA_VER(6)
401 :     APPLY_FILTER_CORE
402 :    
403 :     LOAD_DATA_VER(7)
404 :     APPLY_FILTER_CORE
405 :     }
406 :    
407 :     /******************************************************************************
408 :     * *
409 :     * Noise code below taken from MPlayer: http://www.mplayerhq.hu/ *
410 :     * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at> *
411 :     * *
412 :     ******************************************************************************/
413 :    
414 :     #define RAND_N(range) ((int) ((double)range * rand() / (RAND_MAX + 1.0)))
415 :     #define STRENGTH1 12
416 :     #define STRENGTH2 8
417 :    
418 :     void init_noise(XVID_POSTPROC *tbls)
419 :     {
420 :     int i, j;
421 :     int patt[4] = { -1,0,1,0 };
422 :    
423 :     emms();
424 :    
425 :     srand(123457);
426 :    
427 :     for(i = 0, j = 0; i < MAX_NOISE; i++, j++)
428 :     {
429 :     double x1, x2, w, y1, y2;
430 :    
431 :     do {
432 :     x1 = 2.0 * rand() / (float) RAND_MAX - 1.0;
433 :     x2 = 2.0 * rand() / (float) RAND_MAX - 1.0;
434 :     w = x1 * x1 + x2 * x2;
435 :     } while (w >= 1.0);
436 :    
437 :     w = sqrt((-2.0 * log(w)) / w);
438 :     y1 = x1 * w;
439 :     y2 = x1 * w;
440 :    
441 :     y1 *= STRENGTH1 / sqrt(3.0);
442 :     y2 *= STRENGTH2 / sqrt(3.0);
443 :    
444 :     y1 /= 2;
445 :     y2 /= 2;
446 :     y1 += patt[j%4] * STRENGTH1 * 0.35;
447 :     y2 += patt[j%4] * STRENGTH2 * 0.35;
448 :    
449 :     if (y1 < -128) {
450 :     y1=-128;
451 :     }
452 :     else if (y1 > 127) {
453 :     y1= 127;
454 :     }
455 :    
456 :     if (y2 < -128) {
457 :     y2=-128;
458 :     }
459 :     else if (y2 > 127) {
460 :     y2= 127;
461 :     }
462 :    
463 :     y1 /= 3.0;
464 :     y2 /= 3.0;
465 :     tbls->xvid_noise1[i] = (int) y1;
466 :     tbls->xvid_noise2[i] = (int) y2;
467 :    
468 :     if (RAND_N(6) == 0) {
469 :     j--;
470 :     }
471 :     }
472 :    
473 :     for (i = 0; i < MAX_RES; i++)
474 :     for (j = 0; j < 3; j++) {
475 :     tbls->xvid_prev_shift[i][j] = tbls->xvid_noise1 + (rand() & (MAX_SHIFT - 1));
476 :     tbls->xvid_prev_shift[i][3 + j] = tbls->xvid_noise2 + (rand() & (MAX_SHIFT - 1));
477 :     }
478 :     }
479 :    
480 :     void add_noise(XVID_POSTPROC *tbls, uint8_t *dst, uint8_t *src, int stride, int width, int height, int shiftptr, int quant)
481 :     {
482 :     int x, y;
483 :     int shift = 0;
484 :     int add = (quant < 5) ? 3 : 0;
485 :     int8_t *noise = (quant < 5) ? tbls->xvid_noise2 : tbls->xvid_noise1;
486 :    
487 :     for(y = 0; y < height; y++)
488 :     {
489 :     int8_t *src2 = (int8_t *) src;
490 :    
491 :     shift = rand() & (MAX_SHIFT - 1);
492 :    
493 :     shift &= ~7;
494 :     for(x = 0; x < width; x++)
495 :     {
496 :     const int n = tbls->xvid_prev_shift[y][0 + add][x] + tbls->xvid_prev_shift[y][1 + add][x] +
497 :     tbls->xvid_prev_shift[y][2 + add][x];
498 :    
499 :     dst[x] = src2[x] + ((n * src2[x]) >> 7);
500 :     }
501 :    
502 :     tbls->xvid_prev_shift[y][shiftptr + add] = noise + shift;
503 :    
504 :     dst += stride;
505 :     src += stride;
506 :     }
507 :     }
508 : suxen_drol 1397
509 :    
510 :     void image_brightness_c(uint8_t *dst, int stride, int width, int height, int offset)
511 :     {
512 :     int x,y;
513 :    
514 :     for(y = 0; y < height; y++)
515 :     {
516 :     for(x = 0; x < width; x++)
517 :     {
518 : Isibaar 1805 int p = dst[y*stride + x];
519 :     dst[y*stride + x] = CLIP( p + offset, 0, 255);
520 : suxen_drol 1397 }
521 :     }
522 :     }

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