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