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