]> git.sesse.net Git - vlc/blob - modules/video_filter/adjust.c
Change brighness to brightness
[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 <math.h>
34
35 #include <vlc_common.h>
36 #include <vlc_plugin.h>
37 #include <vlc_sout.h>
38
39 #include <vlc_filter.h>
40 #include "filter_picture.h"
41
42 #ifndef M_PI
43 #   define M_PI 3.14159265358979323846
44 #endif
45
46 #define eight_times( x )    x x x x x x x x
47
48 /*****************************************************************************
49  * Local prototypes
50  *****************************************************************************/
51 static int  Create    ( vlc_object_t * );
52 static void Destroy   ( vlc_object_t * );
53
54 static picture_t *FilterPlanar( filter_t *, picture_t * );
55 static picture_t *FilterPacked( filter_t *, picture_t * );
56 static int AdjustCallback( vlc_object_t *p_this, char const *psz_var,
57                            vlc_value_t oldval, vlc_value_t newval,
58                            void *p_data );
59
60 /*****************************************************************************
61  * Module descriptor
62  *****************************************************************************/
63
64 #define THRES_TEXT N_("Brightness threshold")
65 #define THRES_LONGTEXT N_("When this mode is enabled, pixels will be " \
66         "shown as black or white. The threshold value will be the brightness " \
67         "defined below." )
68 #define CONT_TEXT N_("Image contrast (0-2)")
69 #define CONT_LONGTEXT N_("Set the image contrast, between 0 and 2. Defaults to 1.")
70 #define HUE_TEXT N_("Image hue (0-360)")
71 #define HUE_LONGTEXT N_("Set the image hue, between 0 and 360. Defaults to 0.")
72 #define SAT_TEXT N_("Image saturation (0-3)")
73 #define SAT_LONGTEXT N_("Set the image saturation, between 0 and 3. Defaults to 1.")
74 #define LUM_TEXT N_("Image brightness (0-2)")
75 #define LUM_LONGTEXT N_("Set the image brightness, between 0 and 2. Defaults to 1.")
76 #define GAMMA_TEXT N_("Image gamma (0-10)")
77 #define GAMMA_LONGTEXT N_("Set the image gamma, between 0.01 and 10. Defaults to 1.")
78
79 vlc_module_begin ()
80     set_description( N_("Image properties filter") )
81     set_shortname( N_("Image adjust" ))
82     set_category( CAT_VIDEO )
83     set_subcategory( SUBCAT_VIDEO_VFILTER )
84     set_capability( "video filter2", 0 )
85
86     add_float_with_range( "contrast", 1.0, 0.0, 2.0,
87                           CONT_TEXT, CONT_LONGTEXT, false )
88     add_float_with_range( "brightness", 1.0, 0.0, 2.0,
89                            LUM_TEXT, LUM_LONGTEXT, false )
90     add_integer_with_range( "hue", 0, 0, 360,
91                             HUE_TEXT, HUE_LONGTEXT, false )
92     add_float_with_range( "saturation", 1.0, 0.0, 3.0,
93                           SAT_TEXT, SAT_LONGTEXT, false )
94     add_float_with_range( "gamma", 1.0, 0.01, 10.0,
95                           GAMMA_TEXT, GAMMA_LONGTEXT, false )
96
97     add_bool( "brightness-threshold", false,
98               THRES_TEXT, THRES_LONGTEXT, false )
99
100     add_shortcut( "adjust" )
101     set_callbacks( Create, Destroy )
102 vlc_module_end ()
103
104 static const char *const ppsz_filter_options[] = {
105     "contrast", "brightness", "hue", "saturation", "gamma",
106     "brightness-threshold", NULL
107 };
108
109 /*****************************************************************************
110  * filter_sys_t: adjust filter method descriptor
111  *****************************************************************************/
112 struct filter_sys_t
113 {
114     vlc_mutex_t lock;
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 (%4.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     vlc_mutex_init( &p_sys->lock );
175     var_AddCallback( p_filter, "contrast",   AdjustCallback, p_sys );
176     var_AddCallback( p_filter, "brightness", AdjustCallback, p_sys );
177     var_AddCallback( p_filter, "hue",        AdjustCallback, p_sys );
178     var_AddCallback( p_filter, "saturation", AdjustCallback, p_sys );
179     var_AddCallback( p_filter, "gamma",      AdjustCallback, p_sys );
180     var_AddCallback( p_filter, "brightness-threshold",
181                                              AdjustCallback, p_sys );
182
183     return VLC_SUCCESS;
184 }
185
186 /*****************************************************************************
187  * Destroy: destroy adjust video filter
188  *****************************************************************************/
189 static void Destroy( vlc_object_t *p_this )
190 {
191     filter_t *p_filter = (filter_t *)p_this;
192     filter_sys_t *p_sys = p_filter->p_sys;
193
194     var_DelCallback( p_filter, "contrast",   AdjustCallback, p_sys );
195     var_DelCallback( p_filter, "brightness", AdjustCallback, p_sys );
196     var_DelCallback( p_filter, "hue",        AdjustCallback, p_sys );
197     var_DelCallback( p_filter, "saturation", AdjustCallback, p_sys );
198     var_DelCallback( p_filter, "gamma",      AdjustCallback, p_sys );
199     var_DelCallback( p_filter, "brightness-threshold",
200                                              AdjustCallback, p_sys );
201
202     vlc_mutex_destroy( &p_sys->lock );
203     free( p_sys );
204 }
205
206 /*****************************************************************************
207  * Run the filter on a Planar YUV picture
208  *****************************************************************************/
209 static picture_t *FilterPlanar( filter_t *p_filter, picture_t *p_pic )
210 {
211     int pi_luma[256];
212     int pi_gamma[256];
213
214     picture_t *p_outpic;
215     uint8_t *p_in, *p_in_v, *p_in_end, *p_line_end;
216     uint8_t *p_out, *p_out_v;
217
218     bool b_thres;
219     double  f_hue;
220     double  f_gamma;
221     int32_t i_cont, i_lum;
222     int i_sat, i_sin, i_cos, i_x, i_y;
223     int i;
224
225     filter_sys_t *p_sys = p_filter->p_sys;
226
227     if( !p_pic ) return NULL;
228
229     p_outpic = filter_NewPicture( p_filter );
230     if( !p_outpic )
231     {
232         picture_Release( p_pic );
233         return NULL;
234     }
235
236     /* Get variables */
237     vlc_mutex_lock( &p_sys->lock );
238     i_cont = (int)( p_sys->f_contrast * 255 );
239     i_lum = (int)( (p_sys->f_brightness - 1.0)*255 );
240     f_hue = (float)( p_sys->i_hue * M_PI / 180 );
241     i_sat = (int)( p_sys->f_saturation * 256 );
242     f_gamma = 1.0 / p_sys->f_gamma;
243     b_thres = p_sys->b_brightness_threshold;
244     vlc_mutex_unlock( &p_sys->lock );
245
246     /*
247      * Threshold mode drops out everything about luma, contrast and gamma.
248      */
249     if( !b_thres )
250     {
251
252         /* Contrast is a fast but kludged function, so I put this gap to be
253          * cleaner :) */
254         i_lum += 128 - i_cont / 2;
255
256         /* Fill the gamma lookup table */
257         for( i = 0 ; i < 256 ; i++ )
258         {
259             pi_gamma[ i ] = clip_uint8_vlc( pow(i / 255.0, f_gamma) * 255.0);
260         }
261
262         /* Fill the luma lookup table */
263         for( i = 0 ; i < 256 ; i++ )
264         {
265             pi_luma[ i ] = pi_gamma[clip_uint8_vlc( i_lum + i_cont * i / 256)];
266         }
267     }
268     else
269     {
270         /*
271          * We get luma as threshold value: the higher it is, the darker is
272          * the image. Should I reverse this?
273          */
274         for( i = 0 ; i < 256 ; i++ )
275         {
276             pi_luma[ i ] = (i < i_lum) ? 0 : 255;
277         }
278
279         /*
280          * Desaturates image to avoid that strange yellow halo...
281          */
282         i_sat = 0;
283     }
284
285     /*
286      * Do the Y plane
287      */
288
289     p_in = p_pic->p[Y_PLANE].p_pixels;
290     p_in_end = p_in + p_pic->p[Y_PLANE].i_visible_lines
291                       * p_pic->p[Y_PLANE].i_pitch - 8;
292
293     p_out = p_outpic->p[Y_PLANE].p_pixels;
294
295     for( ; p_in < p_in_end ; )
296     {
297         p_line_end = p_in + p_pic->p[Y_PLANE].i_visible_pitch - 8;
298
299         for( ; p_in < p_line_end ; )
300         {
301             /* Do 8 pixels at a time */
302             *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
303             *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
304             *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
305             *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
306         }
307
308         p_line_end += 8;
309
310         for( ; p_in < p_line_end ; )
311         {
312             *p_out++ = pi_luma[ *p_in++ ];
313         }
314
315         p_in += p_pic->p[Y_PLANE].i_pitch
316               - p_pic->p[Y_PLANE].i_visible_pitch;
317         p_out += p_outpic->p[Y_PLANE].i_pitch
318                - p_outpic->p[Y_PLANE].i_visible_pitch;
319     }
320
321     /*
322      * Do the U and V planes
323      */
324
325     p_in = p_pic->p[U_PLANE].p_pixels;
326     p_in_v = p_pic->p[V_PLANE].p_pixels;
327     p_in_end = p_in + p_pic->p[U_PLANE].i_visible_lines
328                       * p_pic->p[U_PLANE].i_pitch - 8;
329
330     p_out = p_outpic->p[U_PLANE].p_pixels;
331     p_out_v = p_outpic->p[V_PLANE].p_pixels;
332
333     i_sin = sin(f_hue) * 256;
334     i_cos = cos(f_hue) * 256;
335
336     i_x = ( cos(f_hue) + sin(f_hue) ) * 32768;
337     i_y = ( cos(f_hue) - sin(f_hue) ) * 32768;
338
339     if ( i_sat > 256 )
340     {
341 #define WRITE_UV_CLIP() \
342     i_u = *p_in++ ; i_v = *p_in_v++ ; \
343     *p_out++ = clip_uint8_vlc( (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \
344                            * i_sat) >> 8) + 128); \
345     *p_out_v++ = clip_uint8_vlc( (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \
346                            * i_sat) >> 8) + 128)
347
348         uint8_t i_u, i_v;
349
350         for( ; p_in < p_in_end ; )
351         {
352             p_line_end = p_in + p_pic->p[U_PLANE].i_visible_pitch - 8;
353
354             for( ; p_in < p_line_end ; )
355             {
356                 /* Do 8 pixels at a time */
357                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
358                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
359                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
360                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
361             }
362
363             p_line_end += 8;
364
365             for( ; p_in < p_line_end ; )
366             {
367                 WRITE_UV_CLIP();
368             }
369
370             p_in += p_pic->p[U_PLANE].i_pitch
371                   - p_pic->p[U_PLANE].i_visible_pitch;
372             p_in_v += p_pic->p[V_PLANE].i_pitch
373                     - p_pic->p[V_PLANE].i_visible_pitch;
374             p_out += p_outpic->p[U_PLANE].i_pitch
375                    - p_outpic->p[U_PLANE].i_visible_pitch;
376             p_out_v += p_outpic->p[V_PLANE].i_pitch
377                      - p_outpic->p[V_PLANE].i_visible_pitch;
378         }
379 #undef WRITE_UV_CLIP
380     }
381     else
382     {
383 #define WRITE_UV() \
384     i_u = *p_in++ ; i_v = *p_in_v++ ; \
385     *p_out++ = (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \
386                        * i_sat) >> 8) + 128; \
387     *p_out_v++ = (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \
388                        * i_sat) >> 8) + 128
389
390         uint8_t i_u, i_v;
391
392         for( ; p_in < p_in_end ; )
393         {
394             p_line_end = p_in + p_pic->p[U_PLANE].i_visible_pitch - 8;
395
396             for( ; p_in < p_line_end ; )
397             {
398                 /* Do 8 pixels at a time */
399                 WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV();
400                 WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV();
401             }
402
403             p_line_end += 8;
404
405             for( ; p_in < p_line_end ; )
406             {
407                 WRITE_UV();
408             }
409
410             p_in += p_pic->p[U_PLANE].i_pitch
411                   - p_pic->p[U_PLANE].i_visible_pitch;
412             p_in_v += p_pic->p[V_PLANE].i_pitch
413                     - p_pic->p[V_PLANE].i_visible_pitch;
414             p_out += p_outpic->p[U_PLANE].i_pitch
415                    - p_outpic->p[U_PLANE].i_visible_pitch;
416             p_out_v += p_outpic->p[V_PLANE].i_pitch
417                      - p_outpic->p[V_PLANE].i_visible_pitch;
418         }
419 #undef WRITE_UV
420     }
421
422     return CopyInfoAndRelease( p_outpic, p_pic );
423 }
424
425 /*****************************************************************************
426  * Run the filter on a Packed YUV picture
427  *****************************************************************************/
428 static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic )
429 {
430     int pi_luma[256];
431     int pi_gamma[256];
432
433     picture_t *p_outpic;
434     uint8_t *p_in, *p_in_v, *p_in_end, *p_line_end;
435     uint8_t *p_out, *p_out_v;
436     int i_y_offset, i_u_offset, i_v_offset;
437
438     int i_visible_lines, i_pitch, i_visible_pitch;
439
440     bool b_thres;
441     double  f_hue;
442     double  f_gamma;
443     int32_t i_cont, i_lum;
444     int i_sat, i_sin, i_cos, i_x, i_y;
445     int i;
446
447     filter_sys_t *p_sys = p_filter->p_sys;
448
449     if( !p_pic ) return NULL;
450
451     i_visible_lines = p_pic->p->i_visible_lines;
452     i_pitch = p_pic->p->i_pitch;
453     i_visible_pitch = p_pic->p->i_visible_pitch;
454
455     if( GetPackedYuvOffsets( p_pic->format.i_chroma, &i_y_offset,
456                              &i_u_offset, &i_v_offset ) != VLC_SUCCESS )
457     {
458         msg_Warn( p_filter, "Unsupported input chroma (%4.4s)",
459                   (char*)&(p_pic->format.i_chroma) );
460
461         picture_Release( p_pic );
462         return NULL;
463     }
464
465     p_outpic = filter_NewPicture( p_filter );
466     if( !p_outpic )
467     {
468         msg_Warn( p_filter, "can't get output picture" );
469
470         picture_Release( p_pic );
471         return NULL;
472     }
473
474     /* Get variables */
475     vlc_mutex_lock( &p_sys->lock );
476     i_cont = (int)( p_sys->f_contrast * 255 );
477     i_lum = (int)( (p_sys->f_brightness - 1.0)*255 );
478     f_hue = (float)( p_sys->i_hue * M_PI / 180 );
479     i_sat = (int)( p_sys->f_saturation * 256 );
480     f_gamma = 1.0 / p_sys->f_gamma;
481     b_thres = p_sys->b_brightness_threshold;
482     vlc_mutex_unlock( &p_sys->lock );
483
484     /*
485      * Threshold mode drops out everything about luma, contrast and gamma.
486      */
487     if( !b_thres )
488     {
489
490         /* Contrast is a fast but kludged function, so I put this gap to be
491          * cleaner :) */
492         i_lum += 128 - i_cont / 2;
493
494         /* Fill the gamma lookup table */
495         for( i = 0 ; i < 256 ; i++ )
496         {
497           pi_gamma[ i ] = clip_uint8_vlc( pow(i / 255.0, f_gamma) * 255.0);
498         }
499
500         /* Fill the luma lookup table */
501         for( i = 0 ; i < 256 ; i++ )
502         {
503             pi_luma[ i ] = pi_gamma[clip_uint8_vlc( i_lum + i_cont * i / 256)];
504         }
505     }
506     else
507     {
508         /*
509          * We get luma as threshold value: the higher it is, the darker is
510          * the image. Should I reverse this?
511          */
512         for( i = 0 ; i < 256 ; i++ )
513         {
514             pi_luma[ i ] = (i < i_lum) ? 0 : 255;
515         }
516
517         /*
518          * Desaturates image to avoid that strange yellow halo...
519          */
520         i_sat = 0;
521     }
522
523     /*
524      * Do the Y plane
525      */
526
527     p_in = p_pic->p->p_pixels + i_y_offset;
528     p_in_end = p_in + p_pic->p->i_visible_lines * p_pic->p->i_pitch - 8 * 4;
529
530     p_out = p_outpic->p->p_pixels + i_y_offset;
531
532     for( ; p_in < p_in_end ; )
533     {
534         p_line_end = p_in + i_visible_pitch - 8 * 4;
535
536         for( ; p_in < p_line_end ; )
537         {
538             /* Do 8 pixels at a time */
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             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
543             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
544             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
545             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
546             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
547         }
548
549         p_line_end += 8 * 4;
550
551         for( ; p_in < p_line_end ; )
552         {
553             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
554         }
555
556         p_in += i_pitch - p_pic->p->i_visible_pitch;
557         p_out += i_pitch - p_outpic->p->i_visible_pitch;
558     }
559
560     /*
561      * Do the U and V planes
562      */
563
564     p_in = p_pic->p->p_pixels + i_u_offset;
565     p_in_v = p_pic->p->p_pixels + i_v_offset;
566     p_in_end = p_in + i_visible_lines * i_pitch - 8 * 4;
567
568     p_out = p_outpic->p->p_pixels + i_u_offset;
569     p_out_v = p_outpic->p->p_pixels + i_v_offset;
570
571     i_sin = sin(f_hue) * 256;
572     i_cos = cos(f_hue) * 256;
573
574     i_x = ( cos(f_hue) + sin(f_hue) ) * 32768;
575     i_y = ( cos(f_hue) - sin(f_hue) ) * 32768;
576
577     if ( i_sat > 256 )
578     {
579 #define WRITE_UV_CLIP() \
580     i_u = *p_in; p_in += 4; i_v = *p_in_v; p_in_v += 4; \
581     *p_out = clip_uint8_vlc( (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \
582                            * i_sat) >> 8) + 128); \
583     p_out += 4; \
584     *p_out_v = clip_uint8_vlc( (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \
585                            * i_sat) >> 8) + 128); \
586     p_out_v += 4
587
588         uint8_t i_u, i_v;
589
590         for( ; p_in < p_in_end ; )
591         {
592             p_line_end = p_in + i_visible_pitch - 8 * 4;
593
594             for( ; p_in < p_line_end ; )
595             {
596                 /* Do 8 pixels at a time */
597                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
598                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
599                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
600                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
601             }
602
603             p_line_end += 8 * 4;
604
605             for( ; p_in < p_line_end ; )
606             {
607                 WRITE_UV_CLIP();
608             }
609
610             p_in += i_pitch - i_visible_pitch;
611             p_in_v += i_pitch - i_visible_pitch;
612             p_out += i_pitch - i_visible_pitch;
613             p_out_v += i_pitch - i_visible_pitch;
614         }
615 #undef WRITE_UV_CLIP
616     }
617     else
618     {
619 #define WRITE_UV() \
620     i_u = *p_in; p_in += 4; i_v = *p_in_v; p_in_v += 4; \
621     *p_out = (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \
622                        * i_sat) >> 8) + 128; \
623     p_out += 4; \
624     *p_out_v = (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \
625                        * i_sat) >> 8) + 128; \
626     p_out_v += 4
627
628         uint8_t i_u, i_v;
629
630         for( ; p_in < p_in_end ; )
631         {
632             p_line_end = p_in + i_visible_pitch - 8 * 4;
633
634             for( ; p_in < p_line_end ; )
635             {
636                 /* Do 8 pixels at a time */
637                 WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV();
638                 WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV();
639             }
640
641             p_line_end += 8 * 4;
642
643             for( ; p_in < p_line_end ; )
644             {
645                 WRITE_UV();
646             }
647
648             p_in += i_pitch - i_visible_pitch;
649             p_in_v += i_pitch - i_visible_pitch;
650             p_out += i_pitch - i_visible_pitch;
651             p_out_v += i_pitch - i_visible_pitch;
652         }
653 #undef WRITE_UV
654     }
655
656     return CopyInfoAndRelease( p_outpic, p_pic );
657 }
658
659 static int AdjustCallback( vlc_object_t *p_this, char const *psz_var,
660                            vlc_value_t oldval, vlc_value_t newval,
661                            void *p_data )
662 {
663     VLC_UNUSED(p_this); VLC_UNUSED(oldval);
664     filter_sys_t *p_sys = (filter_sys_t *)p_data;
665
666     vlc_mutex_lock( &p_sys->lock );
667     if( !strcmp( psz_var, "contrast" ) )
668         p_sys->f_contrast = newval.f_float;
669     else if( !strcmp( psz_var, "brightness" ) )
670         p_sys->f_brightness = newval.f_float;
671     else if( !strcmp( psz_var, "hue" ) )
672         p_sys->i_hue = newval.i_int;
673     else if( !strcmp( psz_var, "saturation" ) )
674         p_sys->f_saturation = newval.f_float;
675     else if( !strcmp( psz_var, "gamma" ) )
676         p_sys->f_gamma = newval.f_float;
677     else if( !strcmp( psz_var, "brightness-threshold" ) )
678         p_sys->b_brightness_threshold = newval.b_bool;
679     vlc_mutex_unlock( &p_sys->lock );
680
681     return VLC_SUCCESS;
682 }