]> git.sesse.net Git - vlc/blob - modules/video_filter/adjust.c
macosx: fixed menubar appearance in fullscreen mode by partially reverting [46c93c9cc...
[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     vlc_mutex_t lock;
117     double     f_contrast;
118     double     f_brightness;
119     int        i_hue;
120     double     f_saturation;
121     double     f_gamma;
122     bool b_brightness_threshold;
123 };
124
125 /*****************************************************************************
126  * Create: allocates adjust video filter
127  *****************************************************************************/
128 static int Create( vlc_object_t *p_this )
129 {
130     filter_t *p_filter = (filter_t *)p_this;
131     filter_sys_t *p_sys;
132
133     switch( p_filter->fmt_in.video.i_chroma )
134     {
135         CASE_PLANAR_YUV
136             /* Planar YUV */
137             p_filter->pf_video_filter = FilterPlanar;
138             break;
139
140         CASE_PACKED_YUV_422
141             /* Packed YUV 4:2:2 */
142             p_filter->pf_video_filter = FilterPacked;
143             break;
144
145         default:
146             msg_Err( p_filter, "Unsupported input chroma (%4s)",
147                      (char*)&(p_filter->fmt_in.video.i_chroma) );
148             return VLC_EGENERIC;
149     }
150
151     if( p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma )
152     {
153         msg_Err( p_filter, "Input and output chromas don't match" );
154         return VLC_EGENERIC;
155     }
156
157     /* Allocate structure */
158     p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
159     if( p_filter->p_sys == NULL )
160         return VLC_ENOMEM;
161     p_sys = p_filter->p_sys;
162
163     /* needed to get options passed in transcode using the
164      * adjust{name=value} syntax */
165     config_ChainParse( p_filter, "", ppsz_filter_options,
166                    p_filter->p_cfg );
167
168     p_sys->f_contrast = var_CreateGetFloatCommand( p_filter, "contrast" );
169     p_sys->f_brightness = var_CreateGetFloatCommand( p_filter, "brightness" );
170     p_sys->i_hue = var_CreateGetIntegerCommand( p_filter, "hue" );
171     p_sys->f_saturation = var_CreateGetFloatCommand( p_filter, "saturation" );
172     p_sys->f_gamma = var_CreateGetFloatCommand( p_filter, "gamma" );
173     p_sys->b_brightness_threshold =
174         var_CreateGetBoolCommand( p_filter, "brightness-threshold" );
175
176     vlc_mutex_init( &p_sys->lock );
177     var_AddCallback( p_filter, "contrast",   AdjustCallback, p_sys );
178     var_AddCallback( p_filter, "brightness", AdjustCallback, p_sys );
179     var_AddCallback( p_filter, "hue",        AdjustCallback, p_sys );
180     var_AddCallback( p_filter, "saturation", AdjustCallback, p_sys );
181     var_AddCallback( p_filter, "gamma",      AdjustCallback, p_sys );
182     var_AddCallback( p_filter, "brightness-threshold",
183                                              AdjustCallback, p_sys );
184
185     return VLC_SUCCESS;
186 }
187
188 /*****************************************************************************
189  * Destroy: destroy adjust video filter
190  *****************************************************************************/
191 static void Destroy( vlc_object_t *p_this )
192 {
193     filter_t *p_filter = (filter_t *)p_this;
194     filter_sys_t *p_sys = p_filter->p_sys;
195
196     var_DelCallback( p_filter, "contrast",   AdjustCallback, p_sys );
197     var_DelCallback( p_filter, "brightness", AdjustCallback, p_sys );
198     var_DelCallback( p_filter, "hue",        AdjustCallback, p_sys );
199     var_DelCallback( p_filter, "saturation", AdjustCallback, p_sys );
200     var_DelCallback( p_filter, "gamma",      AdjustCallback, p_sys );
201     var_DelCallback( p_filter, "brightness-threshold",
202                                              AdjustCallback, p_sys );
203
204     vlc_mutex_destroy( &p_sys->lock );
205     free( p_sys );
206 }
207
208 /*****************************************************************************
209  * Run the filter on a Planar YUV picture
210  *****************************************************************************/
211 static picture_t *FilterPlanar( filter_t *p_filter, picture_t *p_pic )
212 {
213     int pi_luma[256];
214     int pi_gamma[256];
215
216     picture_t *p_outpic;
217     uint8_t *p_in, *p_in_v, *p_in_end, *p_line_end;
218     uint8_t *p_out, *p_out_v;
219
220     bool b_thres;
221     double  f_hue;
222     double  f_gamma;
223     int32_t i_cont, i_lum;
224     int i_sat, i_sin, i_cos, i_x, i_y;
225     int i;
226
227     filter_sys_t *p_sys = p_filter->p_sys;
228
229     if( !p_pic ) return NULL;
230
231     p_outpic = filter_NewPicture( p_filter );
232     if( !p_outpic )
233     {
234         picture_Release( p_pic );
235         return NULL;
236     }
237
238     /* Get variables */
239     vlc_mutex_lock( &p_sys->lock );
240     i_cont = (int)( p_sys->f_contrast * 255 );
241     i_lum = (int)( (p_sys->f_brightness - 1.0)*255 );
242     f_hue = (float)( p_sys->i_hue * M_PI / 180 );
243     i_sat = (int)( p_sys->f_saturation * 256 );
244     f_gamma = 1.0 / p_sys->f_gamma;
245     b_thres = p_sys->b_brightness_threshold;
246     vlc_mutex_unlock( &p_sys->lock );
247
248     /*
249      * Threshold mode drops out everything about luma, contrast and gamma.
250      */
251     if( b_thres != true )
252     {
253
254         /* Contrast is a fast but kludged function, so I put this gap to be
255          * cleaner :) */
256         i_lum += 128 - i_cont / 2;
257
258         /* Fill the gamma lookup table */
259         for( i = 0 ; i < 256 ; i++ )
260         {
261           pi_gamma[ i ] = clip_uint8_vlc( pow(i / 255.0, f_gamma) * 255.0);
262         }
263
264         /* Fill the luma lookup table */
265         for( i = 0 ; i < 256 ; i++ )
266         {
267             pi_luma[ i ] = pi_gamma[clip_uint8_vlc( i_lum + i_cont * i / 256)];
268         }
269     }
270     else
271     {
272         /*
273          * We get luma as threshold value: the higher it is, the darker is
274          * the image. Should I reverse this?
275          */
276         for( i = 0 ; i < 256 ; i++ )
277         {
278             pi_luma[ i ] = (i < i_lum) ? 0 : 255;
279         }
280
281         /*
282          * Desaturates image to avoid that strange yellow halo...
283          */
284         i_sat = 0;
285     }
286
287     /*
288      * Do the Y plane
289      */
290
291     p_in = p_pic->p[Y_PLANE].p_pixels;
292     p_in_end = p_in + p_pic->p[Y_PLANE].i_visible_lines
293                       * p_pic->p[Y_PLANE].i_pitch - 8;
294
295     p_out = p_outpic->p[Y_PLANE].p_pixels;
296
297     for( ; p_in < p_in_end ; )
298     {
299         p_line_end = p_in + p_pic->p[Y_PLANE].i_visible_pitch - 8;
300
301         for( ; p_in < p_line_end ; )
302         {
303             /* Do 8 pixels at a time */
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             *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
307             *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
308         }
309
310         p_line_end += 8;
311
312         for( ; p_in < p_line_end ; )
313         {
314             *p_out++ = pi_luma[ *p_in++ ];
315         }
316
317         p_in += p_pic->p[Y_PLANE].i_pitch
318               - p_pic->p[Y_PLANE].i_visible_pitch;
319         p_out += p_outpic->p[Y_PLANE].i_pitch
320                - p_outpic->p[Y_PLANE].i_visible_pitch;
321     }
322
323     /*
324      * Do the U and V planes
325      */
326
327     p_in = p_pic->p[U_PLANE].p_pixels;
328     p_in_v = p_pic->p[V_PLANE].p_pixels;
329     p_in_end = p_in + p_pic->p[U_PLANE].i_visible_lines
330                       * p_pic->p[U_PLANE].i_pitch - 8;
331
332     p_out = p_outpic->p[U_PLANE].p_pixels;
333     p_out_v = p_outpic->p[V_PLANE].p_pixels;
334
335     i_sin = sin(f_hue) * 256;
336     i_cos = cos(f_hue) * 256;
337
338     i_x = ( cos(f_hue) + sin(f_hue) ) * 32768;
339     i_y = ( cos(f_hue) - sin(f_hue) ) * 32768;
340
341     if ( i_sat > 256 )
342     {
343 #define WRITE_UV_CLIP() \
344     i_u = *p_in++ ; i_v = *p_in_v++ ; \
345     *p_out++ = clip_uint8_vlc( (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \
346                            * i_sat) >> 8) + 128); \
347     *p_out_v++ = clip_uint8_vlc( (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \
348                            * i_sat) >> 8) + 128)
349
350         uint8_t i_u, i_v;
351
352         for( ; p_in < p_in_end ; )
353         {
354             p_line_end = p_in + p_pic->p[U_PLANE].i_visible_pitch - 8;
355
356             for( ; p_in < p_line_end ; )
357             {
358                 /* Do 8 pixels at a time */
359                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
360                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
361                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
362                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
363             }
364
365             p_line_end += 8;
366
367             for( ; p_in < p_line_end ; )
368             {
369                 WRITE_UV_CLIP();
370             }
371
372             p_in += p_pic->p[U_PLANE].i_pitch
373                   - p_pic->p[U_PLANE].i_visible_pitch;
374             p_in_v += p_pic->p[V_PLANE].i_pitch
375                     - p_pic->p[V_PLANE].i_visible_pitch;
376             p_out += p_outpic->p[U_PLANE].i_pitch
377                    - p_outpic->p[U_PLANE].i_visible_pitch;
378             p_out_v += p_outpic->p[V_PLANE].i_pitch
379                      - p_outpic->p[V_PLANE].i_visible_pitch;
380         }
381 #undef WRITE_UV_CLIP
382     }
383     else
384     {
385 #define WRITE_UV() \
386     i_u = *p_in++ ; i_v = *p_in_v++ ; \
387     *p_out++ = (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \
388                        * i_sat) >> 8) + 128; \
389     *p_out_v++ = (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \
390                        * i_sat) >> 8) + 128
391
392         uint8_t i_u, i_v;
393
394         for( ; p_in < p_in_end ; )
395         {
396             p_line_end = p_in + p_pic->p[U_PLANE].i_visible_pitch - 8;
397
398             for( ; p_in < p_line_end ; )
399             {
400                 /* Do 8 pixels at a time */
401                 WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV();
402                 WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV();
403             }
404
405             p_line_end += 8;
406
407             for( ; p_in < p_line_end ; )
408             {
409                 WRITE_UV();
410             }
411
412             p_in += p_pic->p[U_PLANE].i_pitch
413                   - p_pic->p[U_PLANE].i_visible_pitch;
414             p_in_v += p_pic->p[V_PLANE].i_pitch
415                     - p_pic->p[V_PLANE].i_visible_pitch;
416             p_out += p_outpic->p[U_PLANE].i_pitch
417                    - p_outpic->p[U_PLANE].i_visible_pitch;
418             p_out_v += p_outpic->p[V_PLANE].i_pitch
419                      - p_outpic->p[V_PLANE].i_visible_pitch;
420         }
421 #undef WRITE_UV
422     }
423
424     return CopyInfoAndRelease( p_outpic, p_pic );
425 }
426
427 /*****************************************************************************
428  * Run the filter on a Packed YUV picture
429  *****************************************************************************/
430 static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic )
431 {
432     int pi_luma[256];
433     int pi_gamma[256];
434
435     picture_t *p_outpic;
436     uint8_t *p_in, *p_in_v, *p_in_end, *p_line_end;
437     uint8_t *p_out, *p_out_v;
438     int i_y_offset, i_u_offset, i_v_offset;
439
440     int i_lines, i_visible_lines, i_pitch, i_visible_pitch;
441
442     bool b_thres;
443     double  f_hue;
444     double  f_gamma;
445     int32_t i_cont, i_lum;
446     int i_sat, i_sin, i_cos, i_x, i_y;
447     int i;
448
449     filter_sys_t *p_sys = p_filter->p_sys;
450
451     if( !p_pic ) return NULL;
452
453     i_lines = p_pic->p->i_lines;
454     i_visible_lines = p_pic->p->i_visible_lines;
455     i_pitch = p_pic->p->i_pitch;
456     i_visible_pitch = p_pic->p->i_visible_pitch;
457
458     if( GetPackedYuvOffsets( p_pic->format.i_chroma, &i_y_offset,
459                              &i_u_offset, &i_v_offset ) != VLC_SUCCESS )
460     {
461         msg_Warn( p_filter, "Unsupported input chroma (%4s)",
462                   (char*)&(p_pic->format.i_chroma) );
463
464         picture_Release( p_pic );
465         return NULL;
466     }
467
468     p_outpic = p_filter->pf_vout_buffer_new( p_filter );
469     if( !p_outpic )
470     {
471         msg_Warn( p_filter, "can't get output picture" );
472
473         picture_Release( p_pic );
474         return NULL;
475     }
476
477     /* Get variables */
478     vlc_mutex_lock( &p_sys->lock );
479     i_cont = (int)( p_sys->f_contrast * 255 );
480     i_lum = (int)( (p_sys->f_brightness - 1.0)*255 );
481     f_hue = (float)( p_sys->i_hue * M_PI / 180 );
482     i_sat = (int)( p_sys->f_saturation * 256 );
483     f_gamma = 1.0 / p_sys->f_gamma;
484     b_thres = p_sys->b_brightness_threshold;
485     vlc_mutex_unlock( &p_sys->lock );
486
487     /*
488      * Threshold mode drops out everything about luma, contrast and gamma.
489      */
490     if( b_thres != true )
491     {
492
493         /* Contrast is a fast but kludged function, so I put this gap to be
494          * cleaner :) */
495         i_lum += 128 - i_cont / 2;
496
497         /* Fill the gamma lookup table */
498         for( i = 0 ; i < 256 ; i++ )
499         {
500           pi_gamma[ i ] = clip_uint8_vlc( pow(i / 255.0, f_gamma) * 255.0);
501         }
502
503         /* Fill the luma lookup table */
504         for( i = 0 ; i < 256 ; i++ )
505         {
506             pi_luma[ i ] = pi_gamma[clip_uint8_vlc( i_lum + i_cont * i / 256)];
507         }
508     }
509     else
510     {
511         /*
512          * We get luma as threshold value: the higher it is, the darker is
513          * the image. Should I reverse this?
514          */
515         for( i = 0 ; i < 256 ; i++ )
516         {
517             pi_luma[ i ] = (i < i_lum) ? 0 : 255;
518         }
519
520         /*
521          * Desaturates image to avoid that strange yellow halo...
522          */
523         i_sat = 0;
524     }
525
526     /*
527      * Do the Y plane
528      */
529
530     p_in = p_pic->p->p_pixels + i_y_offset;
531     p_in_end = p_in + p_pic->p->i_visible_lines * p_pic->p->i_pitch - 8 * 4;
532
533     p_out = p_outpic->p->p_pixels + i_y_offset;
534
535     for( ; p_in < p_in_end ; )
536     {
537         p_line_end = p_in + i_visible_pitch - 8 * 4;
538
539         for( ; p_in < p_line_end ; )
540         {
541             /* Do 8 pixels at a time */
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             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
548             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
549             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
550         }
551
552         p_line_end += 8 * 4;
553
554         for( ; p_in < p_line_end ; )
555         {
556             *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
557         }
558
559         p_in += i_pitch - p_pic->p->i_visible_pitch;
560         p_out += i_pitch - p_outpic->p->i_visible_pitch;
561     }
562
563     /*
564      * Do the U and V planes
565      */
566
567     p_in = p_pic->p->p_pixels + i_u_offset;
568     p_in_v = p_pic->p->p_pixels + i_v_offset;
569     p_in_end = p_in + i_visible_lines * i_pitch - 8 * 4;
570
571     p_out = p_outpic->p->p_pixels + i_u_offset;
572     p_out_v = p_outpic->p->p_pixels + i_v_offset;
573
574     i_sin = sin(f_hue) * 256;
575     i_cos = cos(f_hue) * 256;
576
577     i_x = ( cos(f_hue) + sin(f_hue) ) * 32768;
578     i_y = ( cos(f_hue) - sin(f_hue) ) * 32768;
579
580     if ( i_sat > 256 )
581     {
582 #define WRITE_UV_CLIP() \
583     i_u = *p_in; p_in += 4; i_v = *p_in_v; p_in_v += 4; \
584     *p_out = clip_uint8_vlc( (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \
585                            * i_sat) >> 8) + 128); \
586     p_out += 4; \
587     *p_out_v = clip_uint8_vlc( (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \
588                            * i_sat) >> 8) + 128); \
589     p_out_v += 4
590
591         uint8_t i_u, i_v;
592
593         for( ; p_in < p_in_end ; )
594         {
595             p_line_end = p_in + i_visible_pitch - 8 * 4;
596
597             for( ; p_in < p_line_end ; )
598             {
599                 /* Do 8 pixels at a time */
600                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
601                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
602                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
603                 WRITE_UV_CLIP(); WRITE_UV_CLIP();
604             }
605
606             p_line_end += 8 * 4;
607
608             for( ; p_in < p_line_end ; )
609             {
610                 WRITE_UV_CLIP();
611             }
612
613             p_in += i_pitch - i_visible_pitch;
614             p_in_v += i_pitch - i_visible_pitch;
615             p_out += i_pitch - i_visible_pitch;
616             p_out_v += i_pitch - i_visible_pitch;
617         }
618 #undef WRITE_UV_CLIP
619     }
620     else
621     {
622 #define WRITE_UV() \
623     i_u = *p_in; p_in += 4; i_v = *p_in_v; p_in_v += 4; \
624     *p_out = (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \
625                        * i_sat) >> 8) + 128; \
626     p_out += 4; \
627     *p_out_v = (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \
628                        * i_sat) >> 8) + 128; \
629     p_out_v += 4
630
631         uint8_t i_u, i_v;
632
633         for( ; p_in < p_in_end ; )
634         {
635             p_line_end = p_in + i_visible_pitch - 8 * 4;
636
637             for( ; p_in < p_line_end ; )
638             {
639                 /* Do 8 pixels at a time */
640                 WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV();
641                 WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV();
642             }
643
644             p_line_end += 8 * 4;
645
646             for( ; p_in < p_line_end ; )
647             {
648                 WRITE_UV();
649             }
650
651             p_in += i_pitch - i_visible_pitch;
652             p_in_v += i_pitch - i_visible_pitch;
653             p_out += i_pitch - i_visible_pitch;
654             p_out_v += i_pitch - i_visible_pitch;
655         }
656 #undef WRITE_UV
657     }
658
659     return CopyInfoAndRelease( p_outpic, p_pic );
660 }
661
662 static int AdjustCallback( vlc_object_t *p_this, char const *psz_var,
663                            vlc_value_t oldval, vlc_value_t newval,
664                            void *p_data )
665 {
666     VLC_UNUSED(p_this); VLC_UNUSED(oldval);
667     filter_sys_t *p_sys = (filter_sys_t *)p_data;
668
669     vlc_mutex_lock( &p_sys->lock );
670     if( !strcmp( psz_var, "contrast" ) )
671         p_sys->f_contrast = newval.f_float;
672     else if( !strcmp( psz_var, "brightness" ) )
673         p_sys->f_brightness = newval.f_float;
674     else if( !strcmp( psz_var, "hue" ) )
675         p_sys->i_hue = newval.i_int;
676     else if( !strcmp( psz_var, "saturation" ) )
677         p_sys->f_saturation = newval.f_float;
678     else if( !strcmp( psz_var, "gamma" ) )
679         p_sys->f_gamma = newval.f_float;
680     else if( !strcmp( psz_var, "brightness-threshold" ) )
681         p_sys->b_brightness_threshold = newval.b_bool;
682     vlc_mutex_unlock( &p_sys->lock );
683
684     return VLC_SUCCESS;
685 }