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