]> git.sesse.net Git - vlc/blob - modules/video_filter/adjust.c
Used filter_New/DeletePicture when applicable.
[vlc] / modules / video_filter / adjust.c
1 /*****************************************************************************
2  * adjust.c : Contrast/Hue/Saturation/Brightness video plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Simon Latapie <garf@via.ecp.fr>
8  *          Antoine Cellerier <dionoea -at- videolan d0t org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <errno.h>
34 #include <math.h>
35
36 #include <vlc_common.h>
37 #include <vlc_plugin.h>
38 #include <vlc_sout.h>
39
40 #include "vlc_filter.h"
41 #include "filter_picture.h"
42
43 #ifndef M_PI
44 #   define M_PI 3.14159265358979323846
45 #endif
46
47 #define eight_times( x )    x x x x x x x x
48
49 /*****************************************************************************
50  * Local prototypes
51  *****************************************************************************/
52 static int  Create    ( vlc_object_t * );
53 static void Destroy   ( vlc_object_t * );
54
55 static picture_t *FilterPlanar( filter_t *, picture_t * );
56 static picture_t *FilterPacked( filter_t *, picture_t * );
57 static int AdjustCallback( vlc_object_t *p_this, char const *psz_var,
58                            vlc_value_t oldval, vlc_value_t newval,
59                            void *p_data );
60
61 /*****************************************************************************
62  * Module descriptor
63  *****************************************************************************/
64
65 #define THRES_TEXT N_("Brightness threshold")
66 #define THRES_LONGTEXT N_("When this mode is enabled, pixels will be " \
67         "shown as black or white. The threshold value will be the brighness " \
68         "defined below." )
69 #define CONT_TEXT N_("Image contrast (0-2)")
70 #define CONT_LONGTEXT N_("Set the image contrast, between 0 and 2. Defaults to 1.")
71 #define HUE_TEXT N_("Image hue (0-360)")
72 #define HUE_LONGTEXT N_("Set the image hue, between 0 and 360. Defaults to 0.")
73 #define SAT_TEXT N_("Image saturation (0-3)")
74 #define SAT_LONGTEXT N_("Set the image saturation, between 0 and 3. Defaults to 1.")
75 #define LUM_TEXT N_("Image brightness (0-2)")
76 #define LUM_LONGTEXT N_("Set the image brightness, between 0 and 2. Defaults to 1.")
77 #define GAMMA_TEXT N_("Image gamma (0-10)")
78 #define GAMMA_LONGTEXT N_("Set the image gamma, between 0.01 and 10. Defaults to 1.")
79
80 vlc_module_begin ()
81     set_description( N_("Image properties filter") )
82     set_shortname( N_("Image adjust" ))
83     set_category( CAT_VIDEO )
84     set_subcategory( SUBCAT_VIDEO_VFILTER )
85     set_capability( "video filter2", 0 )
86
87     add_float_with_range( "contrast", 1.0, 0.0, 2.0, NULL,
88                           CONT_TEXT, CONT_LONGTEXT, false )
89     add_float_with_range( "brightness", 1.0, 0.0, 2.0, NULL,
90                            LUM_TEXT, LUM_LONGTEXT, false )
91     add_integer_with_range( "hue", 0, 0, 360, NULL,
92                             HUE_TEXT, HUE_LONGTEXT, false )
93     add_float_with_range( "saturation", 1.0, 0.0, 3.0, NULL,
94                           SAT_TEXT, SAT_LONGTEXT, false )
95     add_float_with_range( "gamma", 1.0, 0.01, 10.0, NULL,
96                           GAMMA_TEXT, GAMMA_LONGTEXT, false )
97
98     add_bool( "brightness-threshold", 0, NULL,
99               THRES_TEXT, THRES_LONGTEXT, false )
100
101     add_shortcut( "adjust" )
102     set_callbacks( Create, Destroy )
103 vlc_module_end ()
104
105 static const char *const ppsz_filter_options[] = {
106     "contrast", "brightness", "hue", "saturation", "gamma",
107     "brightness-threshold", NULL
108 };
109
110 /*****************************************************************************
111  * filter_sys_t: adjust filter method descriptor
112  *****************************************************************************/
113 struct filter_sys_t
114 {
115     double     f_contrast;
116     double     f_brightness;
117     int        i_hue;
118     double     f_saturation;
119     double     f_gamma;
120     bool b_brightness_threshold;
121 };
122
123 /*****************************************************************************
124  * Create: allocates adjust video filter
125  *****************************************************************************/
126 static int Create( vlc_object_t *p_this )
127 {
128     filter_t *p_filter = (filter_t *)p_this;
129     filter_sys_t *p_sys;
130
131     switch( p_filter->fmt_in.video.i_chroma )
132     {
133         CASE_PLANAR_YUV
134             /* Planar YUV */
135             p_filter->pf_video_filter = FilterPlanar;
136             break;
137
138         CASE_PACKED_YUV_422
139             /* Packed YUV 4:2:2 */
140             p_filter->pf_video_filter = FilterPacked;
141             break;
142
143         default:
144             msg_Err( p_filter, "Unsupported input chroma (%4s)",
145                      (char*)&(p_filter->fmt_in.video.i_chroma) );
146             return VLC_EGENERIC;
147     }
148
149     if( p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma )
150     {
151         msg_Err( p_filter, "Input and output chromas don't match" );
152         return VLC_EGENERIC;
153     }
154
155     /* Allocate structure */
156     p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
157     if( p_filter->p_sys == NULL )
158         return VLC_ENOMEM;
159     p_sys = p_filter->p_sys;
160
161     /* needed to get options passed in transcode using the
162      * adjust{name=value} syntax */
163     config_ChainParse( p_filter, "", ppsz_filter_options,
164                    p_filter->p_cfg );
165
166     p_sys->f_contrast = var_CreateGetFloatCommand( p_filter, "contrast" );
167     p_sys->f_brightness = var_CreateGetFloatCommand( p_filter, "brightness" );
168     p_sys->i_hue = var_CreateGetIntegerCommand( p_filter, "hue" );
169     p_sys->f_saturation = var_CreateGetFloatCommand( p_filter, "saturation" );
170     p_sys->f_gamma = var_CreateGetFloatCommand( p_filter, "gamma" );
171     p_sys->b_brightness_threshold =
172         var_CreateGetBoolCommand( p_filter, "brightness-threshold" );
173
174     var_AddCallback( p_filter, "contrast",   AdjustCallback, p_sys );
175     var_AddCallback( p_filter, "brightness", AdjustCallback, p_sys );
176     var_AddCallback( p_filter, "hue",        AdjustCallback, p_sys );
177     var_AddCallback( p_filter, "saturation", AdjustCallback, p_sys );
178     var_AddCallback( p_filter, "gamma",      AdjustCallback, p_sys );
179     var_AddCallback( p_filter, "brightness-threshold",
180                                              AdjustCallback, p_sys );
181
182     return VLC_SUCCESS;
183 }
184
185 /*****************************************************************************
186  * Destroy: destroy adjust video filter
187  *****************************************************************************/
188 static void Destroy( vlc_object_t *p_this )
189 {
190     filter_t *p_filter = (filter_t *)p_this;
191     filter_sys_t *p_sys = p_filter->p_sys;
192
193     var_DelCallback( p_filter, "contrast",   AdjustCallback, p_sys );
194     var_DelCallback( p_filter, "brightness", AdjustCallback, p_sys );
195     var_DelCallback( p_filter, "hue",        AdjustCallback, p_sys );
196     var_DelCallback( p_filter, "saturation", AdjustCallback, p_sys );
197     var_DelCallback( p_filter, "gamma",      AdjustCallback, p_sys );
198     var_DelCallback( p_filter, "brightness-threshold",
199                                              AdjustCallback, p_sys );
200
201     free( p_sys );
202 }
203
204 /*****************************************************************************
205  * Run the filter on a Planar YUV picture
206  *****************************************************************************/
207 static picture_t *FilterPlanar( filter_t *p_filter, picture_t *p_pic )
208 {
209     int pi_luma[256];
210     int pi_gamma[256];
211
212     picture_t *p_outpic;
213     uint8_t *p_in, *p_in_v, *p_in_end, *p_line_end;
214     uint8_t *p_out, *p_out_v;
215
216     bool b_thres;
217     double  f_hue;
218     double  f_gamma;
219     int32_t i_cont, i_lum;
220     int i_sat, i_sin, i_cos, i_x, i_y;
221     int i;
222
223     filter_sys_t *p_sys = p_filter->p_sys;
224
225     if( !p_pic ) return NULL;
226
227     p_outpic = filter_NewPicture( p_filter );
228     if( !p_outpic )
229     {
230         picture_Release( p_pic );
231         return NULL;
232     }
233
234     /* Getvariables */
235     i_cont = (int)( p_sys->f_contrast * 255 );
236     i_lum = (int)( (p_sys->f_brightness - 1.0)*255 );
237     f_hue = (float)( p_sys->i_hue * M_PI / 180 );
238     i_sat = (int)( p_sys->f_saturation * 256 );
239     f_gamma = 1.0 / p_sys->f_gamma;
240     b_thres = p_sys->b_brightness_threshold;
241
242     /*
243      * Threshold mode drops out everything about luma, contrast and gamma.
244      */
245     if( b_thres != true )
246     {
247
248         /* Contrast is a fast but kludged function, so I put this gap to be
249          * cleaner :) */
250         i_lum += 128 - i_cont / 2;
251
252         /* Fill the gamma lookup table */
253         for( i = 0 ; i < 256 ; i++ )
254         {
255           pi_gamma[ i ] = clip_uint8_vlc( pow(i / 255.0, f_gamma) * 255.0);
256         }
257
258         /* Fill the luma lookup table */
259         for( i = 0 ; i < 256 ; i++ )
260         {
261             pi_luma[ i ] = pi_gamma[clip_uint8_vlc( i_lum + i_cont * i / 256)];
262         }
263     }
264     else
265     {
266         /*
267          * We get luma as threshold value: the higher it is, the darker is
268          * the image. Should I reverse this?
269          */
270         for( i = 0 ; i < 256 ; i++ )
271         {
272             pi_luma[ i ] = (i < i_lum) ? 0 : 255;
273         }
274
275         /*
276          * Desaturates image to avoid that strange yellow halo...
277          */
278         i_sat = 0;
279     }
280
281     /*
282      * Do the Y plane
283      */
284
285     p_in = p_pic->p[Y_PLANE].p_pixels;
286     p_in_end = p_in + p_pic->p[Y_PLANE].i_visible_lines
287                       * p_pic->p[Y_PLANE].i_pitch - 8;
288
289     p_out = p_outpic->p[Y_PLANE].p_pixels;
290
291     for( ; p_in < p_in_end ; )
292     {
293         p_line_end = p_in + p_pic->p[Y_PLANE].i_visible_pitch - 8;
294
295         for( ; p_in < p_line_end ; )
296         {
297             /* Do 8 pixels at a time */
298             *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
299             *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
300             *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
301             *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
302         }
303
304         p_line_end += 8;
305
306         for( ; p_in < p_line_end ; )
307         {
308             *p_out++ = pi_luma[ *p_in++ ];
309         }
310
311         p_in += p_pic->p[Y_PLANE].i_pitch
312               - p_pic->p[Y_PLANE].i_visible_pitch;
313         p_out += p_outpic->p[Y_PLANE].i_pitch
314                - p_outpic->p[Y_PLANE].i_visible_pitch;
315     }
316
317     /*
318      * Do the U and V planes
319      */
320
321     p_in = p_pic->p[U_PLANE].p_pixels;
322     p_in_v = p_pic->p[V_PLANE].p_pixels;
323     p_in_end = p_in + p_pic->p[U_PLANE].i_visible_lines
324                       * p_pic->p[U_PLANE].i_pitch - 8;
325
326     p_out = p_outpic->p[U_PLANE].p_pixels;
327     p_out_v = p_outpic->p[V_PLANE].p_pixels;
328
329     i_sin = sin(f_hue) * 256;
330     i_cos = cos(f_hue) * 256;
331
332     i_x = ( cos(f_hue) + sin(f_hue) ) * 32768;
333     i_y = ( cos(f_hue) - sin(f_hue) ) * 32768;
334
335     if ( i_sat > 256 )
336     {
337 #define WRITE_UV_CLIP() \
338     i_u = *p_in++ ; i_v = *p_in_v++ ; \
339     *p_out++ = clip_uint8_vlc( (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \
340                            * i_sat) >> 8) + 128); \
341     *p_out_v++ = clip_uint8_vlc( (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \
342                            * i_sat) >> 8) + 128)
343
344         uint8_t i_u, i_v;
345
346         for( ; p_in < p_in_end ; )
347         {
348             p_line_end = p_in + p_pic->p[U_PLANE].i_visible_pitch - 8;
349
350             for( ; p_in < p_line_end ; )
351             {
352                 /* Do 8 pixels at a time */
353                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
354                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
355                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
356                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
357             }
358
359             p_line_end += 8;
360
361             for( ; p_in < p_line_end ; )
362             {
363                 WRITE_UV_CLIP();
364             }
365
366             p_in += p_pic->p[U_PLANE].i_pitch
367                   - p_pic->p[U_PLANE].i_visible_pitch;
368             p_in_v += p_pic->p[V_PLANE].i_pitch
369                     - p_pic->p[V_PLANE].i_visible_pitch;
370             p_out += p_outpic->p[U_PLANE].i_pitch
371                    - p_outpic->p[U_PLANE].i_visible_pitch;
372             p_out_v += p_outpic->p[V_PLANE].i_pitch
373                      - p_outpic->p[V_PLANE].i_visible_pitch;
374         }
375 #undef WRITE_UV_CLIP
376     }
377     else
378     {
379 #define WRITE_UV() \
380     i_u = *p_in++ ; i_v = *p_in_v++ ; \
381     *p_out++ = (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \
382                        * i_sat) >> 8) + 128; \
383     *p_out_v++ = (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \
384                        * i_sat) >> 8) + 128
385
386         uint8_t i_u, i_v;
387
388         for( ; p_in < p_in_end ; )
389         {
390             p_line_end = p_in + p_pic->p[U_PLANE].i_visible_pitch - 8;
391
392             for( ; p_in < p_line_end ; )
393             {
394                 /* Do 8 pixels at a time */
395                 WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV();
396                 WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV();
397             }
398
399             p_line_end += 8;
400
401             for( ; p_in < p_line_end ; )
402             {
403                 WRITE_UV();
404             }
405
406             p_in += p_pic->p[U_PLANE].i_pitch
407                   - p_pic->p[U_PLANE].i_visible_pitch;
408             p_in_v += p_pic->p[V_PLANE].i_pitch
409                     - p_pic->p[V_PLANE].i_visible_pitch;
410             p_out += p_outpic->p[U_PLANE].i_pitch
411                    - p_outpic->p[U_PLANE].i_visible_pitch;
412             p_out_v += p_outpic->p[V_PLANE].i_pitch
413                      - p_outpic->p[V_PLANE].i_visible_pitch;
414         }
415 #undef WRITE_UV
416     }
417
418     return CopyInfoAndRelease( p_outpic, p_pic );
419 }
420
421 /*****************************************************************************
422  * Run the filter on a Packed YUV picture
423  *****************************************************************************/
424 static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic )
425 {
426     int pi_luma[256];
427     int pi_gamma[256];
428
429     picture_t *p_outpic;
430     uint8_t *p_in, *p_in_v, *p_in_end, *p_line_end;
431     uint8_t *p_out, *p_out_v;
432     int i_y_offset, i_u_offset, i_v_offset;
433
434     int i_lines, i_visible_lines, i_pitch, i_visible_pitch;
435
436     bool b_thres;
437     double  f_hue;
438     double  f_gamma;
439     int32_t i_cont, i_lum;
440     int i_sat, i_sin, i_cos, i_x, i_y;
441     int i;
442
443     filter_sys_t *p_sys = p_filter->p_sys;
444
445     if( !p_pic ) return NULL;
446
447     i_lines = p_pic->p->i_lines;
448     i_visible_lines = p_pic->p->i_visible_lines;
449     i_pitch = p_pic->p->i_pitch;
450     i_visible_pitch = p_pic->p->i_visible_pitch;
451
452     if( GetPackedYuvOffsets( p_pic->format.i_chroma, &i_y_offset,
453                              &i_u_offset, &i_v_offset ) != VLC_SUCCESS )
454     {
455         msg_Warn( p_filter, "Unsupported input chroma (%4s)",
456                   (char*)&(p_pic->format.i_chroma) );
457
458         picture_Release( p_pic );
459         return NULL;
460     }
461
462     p_outpic = filter_NewPicture( p_filter );
463     if( !p_outpic )
464     {
465         msg_Warn( p_filter, "can't get output picture" );
466
467         picture_Release( p_pic );
468         return NULL;
469     }
470
471     /* Getvariables */
472     i_cont = (int)( p_sys->f_contrast * 255 );
473     i_lum = (int)( (p_sys->f_brightness - 1.0)*255 );
474     f_hue = (float)( p_sys->i_hue * M_PI / 180 );
475     i_sat = (int)( p_sys->f_saturation * 256 );
476     f_gamma = 1.0 / p_sys->f_gamma;
477     b_thres = p_sys->b_brightness_threshold;
478
479     /*
480      * Threshold mode drops out everything about luma, contrast and gamma.
481      */
482     if( b_thres != true )
483     {
484
485         /* Contrast is a fast but kludged function, so I put this gap to be
486          * cleaner :) */
487         i_lum += 128 - i_cont / 2;
488
489         /* Fill the gamma lookup table */
490         for( i = 0 ; i < 256 ; i++ )
491         {
492           pi_gamma[ i ] = clip_uint8_vlc( pow(i / 255.0, f_gamma) * 255.0);
493         }
494
495         /* Fill the luma lookup table */
496         for( i = 0 ; i < 256 ; i++ )
497         {
498             pi_luma[ i ] = pi_gamma[clip_uint8_vlc( i_lum + i_cont * i / 256)];
499         }
500     }
501     else
502     {
503         /*
504          * We get luma as threshold value: the higher it is, the darker is
505          * the image. Should I reverse this?
506          */
507         for( i = 0 ; i < 256 ; i++ )
508         {
509             pi_luma[ i ] = (i < i_lum) ? 0 : 255;
510         }
511
512         /*
513          * Desaturates image to avoid that strange yellow halo...
514          */
515         i_sat = 0;
516     }
517
518     /*
519      * Do the Y plane
520      */
521
522     p_in = p_pic->p->p_pixels + i_y_offset;
523     p_in_end = p_in + p_pic->p->i_visible_lines * p_pic->p->i_pitch - 8 * 4;
524
525     p_out = p_outpic->p->p_pixels + i_y_offset;
526
527     for( ; p_in < p_in_end ; )
528     {
529         p_line_end = p_in + i_visible_pitch - 8 * 4;
530
531         for( ; p_in < p_line_end ; )
532         {
533             /* Do 8 pixels at a time */
534             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
535             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
536             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
537             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
538             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
539             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
540             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
541             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
542         }
543
544         p_line_end += 8 * 4;
545
546         for( ; p_in < p_line_end ; )
547         {
548             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
549         }
550
551         p_in += i_pitch - p_pic->p->i_visible_pitch;
552         p_out += i_pitch - p_outpic->p->i_visible_pitch;
553     }
554
555     /*
556      * Do the U and V planes
557      */
558
559     p_in = p_pic->p->p_pixels + i_u_offset;
560     p_in_v = p_pic->p->p_pixels + i_v_offset;
561     p_in_end = p_in + i_visible_lines * i_pitch - 8 * 4;
562
563     p_out = p_outpic->p->p_pixels + i_u_offset;
564     p_out_v = p_outpic->p->p_pixels + i_v_offset;
565
566     i_sin = sin(f_hue) * 256;
567     i_cos = cos(f_hue) * 256;
568
569     i_x = ( cos(f_hue) + sin(f_hue) ) * 32768;
570     i_y = ( cos(f_hue) - sin(f_hue) ) * 32768;
571
572     if ( i_sat > 256 )
573     {
574 #define WRITE_UV_CLIP() \
575     i_u = *p_in; p_in += 4; i_v = *p_in_v; p_in_v += 4; \
576     *p_out = clip_uint8_vlc( (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \
577                            * i_sat) >> 8) + 128); \
578     p_out += 4; \
579     *p_out_v = clip_uint8_vlc( (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \
580                            * i_sat) >> 8) + 128); \
581     p_out_v += 4
582
583         uint8_t i_u, i_v;
584
585         for( ; p_in < p_in_end ; )
586         {
587             p_line_end = p_in + i_visible_pitch - 8 * 4;
588
589             for( ; p_in < p_line_end ; )
590             {
591                 /* Do 8 pixels at a time */
592                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
593                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
594                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
595                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
596             }
597
598             p_line_end += 8 * 4;
599
600             for( ; p_in < p_line_end ; )
601             {
602                 WRITE_UV_CLIP();
603             }
604
605             p_in += i_pitch - i_visible_pitch;
606             p_in_v += i_pitch - i_visible_pitch;
607             p_out += i_pitch - i_visible_pitch;
608             p_out_v += i_pitch - i_visible_pitch;
609         }
610 #undef WRITE_UV_CLIP
611     }
612     else
613     {
614 #define WRITE_UV() \
615     i_u = *p_in; p_in += 4; i_v = *p_in_v; p_in_v += 4; \
616     *p_out = (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \
617                        * i_sat) >> 8) + 128; \
618     p_out += 4; \
619     *p_out_v = (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \
620                        * i_sat) >> 8) + 128; \
621     p_out_v += 4
622
623         uint8_t i_u, i_v;
624
625         for( ; p_in < p_in_end ; )
626         {
627             p_line_end = p_in + i_visible_pitch - 8 * 4;
628
629             for( ; p_in < p_line_end ; )
630             {
631                 /* Do 8 pixels at a time */
632                 WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV();
633                 WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV();
634             }
635
636             p_line_end += 8 * 4;
637
638             for( ; p_in < p_line_end ; )
639             {
640                 WRITE_UV();
641             }
642
643             p_in += i_pitch - i_visible_pitch;
644             p_in_v += i_pitch - i_visible_pitch;
645             p_out += i_pitch - i_visible_pitch;
646             p_out_v += i_pitch - i_visible_pitch;
647         }
648 #undef WRITE_UV
649     }
650
651     return CopyInfoAndRelease( p_outpic, p_pic );
652 }
653
654 static int AdjustCallback( vlc_object_t *p_this, char const *psz_var,
655                            vlc_value_t oldval, vlc_value_t newval,
656                            void *p_data )
657 {
658     VLC_UNUSED(p_this); VLC_UNUSED(oldval);
659     filter_sys_t *p_sys = (filter_sys_t *)p_data;
660
661     if( !strcmp( psz_var, "contrast" ) )
662         p_sys->f_contrast = newval.f_float;
663     else if( !strcmp( psz_var, "brightness" ) )
664         p_sys->f_brightness = newval.f_float;
665     else if( !strcmp( psz_var, "hue" ) )
666         p_sys->i_hue = newval.i_int;
667     else if( !strcmp( psz_var, "saturation" ) )
668         p_sys->f_saturation = newval.f_float;
669     else if( !strcmp( psz_var, "gamma" ) )
670         p_sys->f_gamma = newval.f_float;
671     else if( !strcmp( psz_var, "brightness-threshold" ) )
672         p_sys->b_brightness_threshold = newval.b_bool;
673     else
674         return VLC_EGENERIC;
675     return VLC_SUCCESS;
676 }