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