adjust.c 21.1 KB
Newer Older
1
/*****************************************************************************
2
 * adjust.c : Contrast/Hue/Saturation/Brightness video plugin for vlc
3
 *****************************************************************************
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
4
 * Copyright (C) 2000-2006 VLC authors and VideoLAN
5
 * $Id$
6
 *
7
 * Authors: Simon Latapie <garf@via.ecp.fr>
8
 *          Antoine Cellerier <dionoea -at- videolan d0t org>
9
 *          Martin Briza <gamajun@seznam.cz> (SSE)
10
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
11 12 13
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
14
 * (at your option) any later version.
15
 *
16 17
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
18 19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
20
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
21 22 23
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 25 26 27 28 29
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

30 31 32 33
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

34 35
#include <math.h>

36
#include <vlc_common.h>
37
#include <vlc_atomic.h>
38
#include <vlc_plugin.h>
Rémi Duraffort's avatar
Rémi Duraffort committed
39
#include <vlc_filter.h>
40
#include <vlc_picture.h>
41
#include "filter_picture.h"
42

43 44
#include "adjust_sat_hue.h"

45 46 47 48 49 50
/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
static int  Create    ( vlc_object_t * );
static void Destroy   ( vlc_object_t * );

51 52
static picture_t *FilterPlanar( filter_t *, picture_t * );
static picture_t *FilterPacked( filter_t *, picture_t * );
53 54 55
static int AdjustCallback( vlc_object_t *p_this, char const *psz_var,
                           vlc_value_t oldval, vlc_value_t newval,
                           void *p_data );
56

57 58 59 60
/*****************************************************************************
 * Module descriptor
 *****************************************************************************/

61 62
#define THRES_TEXT N_("Brightness threshold")
#define THRES_LONGTEXT N_("When this mode is enabled, pixels will be " \
Pierre Ynard's avatar
Pierre Ynard committed
63
        "shown as black or white. The threshold value will be the brightness " \
64
        "defined below." )
65
#define CONT_TEXT N_("Image contrast (0-2)")
66
#define CONT_LONGTEXT N_("Set the image contrast, between 0 and 2. Defaults to 1.")
67 68
#define HUE_TEXT N_("Image hue (-180..180)")
#define HUE_LONGTEXT N_("Set the image hue, between -180 and 180. Defaults to 0.")
69
#define SAT_TEXT N_("Image saturation (0-3)")
70
#define SAT_LONGTEXT N_("Set the image saturation, between 0 and 3. Defaults to 1.")
71
#define LUM_TEXT N_("Image brightness (0-2)")
72
#define LUM_LONGTEXT N_("Set the image brightness, between 0 and 2. Defaults to 1.")
73
#define GAMMA_TEXT N_("Image gamma (0-10)")
74
#define GAMMA_LONGTEXT N_("Set the image gamma, between 0.01 and 10. Defaults to 1.")
75

76 77 78 79 80
vlc_module_begin ()
    set_description( N_("Image properties filter") )
    set_shortname( N_("Image adjust" ))
    set_category( CAT_VIDEO )
    set_subcategory( SUBCAT_VIDEO_VFILTER )
81
    set_capability( "video filter", 0 )
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
82

83
    add_float_with_range( "contrast", 1.0, 0.0, 2.0,
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
84
                          CONT_TEXT, CONT_LONGTEXT, false )
85
        change_safe()
86
    add_float_with_range( "brightness", 1.0, 0.0, 2.0,
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
87
                           LUM_TEXT, LUM_LONGTEXT, false )
88
        change_safe()
89
    add_float_with_range( "hue", 0, -180., +180.,
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
90
                            HUE_TEXT, HUE_LONGTEXT, false )
91
        change_safe()
92
    add_float_with_range( "saturation", 1.0, 0.0, 3.0,
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
93
                          SAT_TEXT, SAT_LONGTEXT, false )
94
        change_safe()
95
    add_float_with_range( "gamma", 1.0, 0.01, 10.0,
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
96
                          GAMMA_TEXT, GAMMA_LONGTEXT, false )
97
        change_safe()
98
    add_bool( "brightness-threshold", false,
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
99
              THRES_TEXT, THRES_LONGTEXT, false )
100
        change_safe()
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
101

102 103 104
    add_shortcut( "adjust" )
    set_callbacks( Create, Destroy )
vlc_module_end ()
105

106
static const char *const ppsz_filter_options[] = {
107 108 109 110
    "contrast", "brightness", "hue", "saturation", "gamma",
    "brightness-threshold", NULL
};

111
/*****************************************************************************
112
 * filter_sys_t: adjust filter method descriptor
113
 *****************************************************************************/
114
struct filter_sys_t
115
{
116 117 118 119 120 121
    vlc_atomic_float f_contrast;
    vlc_atomic_float f_brightness;
    vlc_atomic_float f_hue;
    vlc_atomic_float f_saturation;
    vlc_atomic_float f_gamma;
    atomic_bool  b_brightness_threshold;
122 123 124 125
    int (*pf_process_sat_hue)( picture_t *, picture_t *, int, int, int,
                               int, int );
    int (*pf_process_sat_hue_clip)( picture_t *, picture_t *, int, int,
                                    int, int, int );
126 127 128
};

/*****************************************************************************
129
 * Create: allocates adjust video filter
130 131 132
 *****************************************************************************/
static int Create( vlc_object_t *p_this )
{
133
    filter_t *p_filter = (filter_t *)p_this;
134
    filter_sys_t *p_sys;
135 136

    if( p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma )
137
    {
138
        msg_Err( p_filter, "Input and output chromas don't match" );
139
        return VLC_EGENERIC;
140
    }
141

142 143 144 145
    /* Allocate structure */
    p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
    if( p_filter->p_sys == NULL )
        return VLC_ENOMEM;
146
    p_sys = p_filter->p_sys;
147

148 149 150 151 152 153 154 155 156 157 158
    /* Choose Planar/Packed function and pointer to a Hue/Saturation processing
     * function*/
    switch( p_filter->fmt_in.video.i_chroma )
    {
        CASE_PLANAR_YUV
            /* Planar YUV */
            p_filter->pf_video_filter = FilterPlanar;
            p_sys->pf_process_sat_hue_clip = planar_sat_hue_clip_C;
            p_sys->pf_process_sat_hue = planar_sat_hue_C;
            break;

159 160 161 162 163 164 165 166
        CASE_PLANAR_YUV10
        CASE_PLANAR_YUV9
            /* Planar YUV 9-bit or 10-bit */
            p_filter->pf_video_filter = FilterPlanar;
            p_sys->pf_process_sat_hue_clip = planar_sat_hue_clip_C_16;
            p_sys->pf_process_sat_hue = planar_sat_hue_C_16;
            break;

167 168 169 170 171 172 173 174
        CASE_PACKED_YUV_422
            /* Packed YUV 4:2:2 */
            p_filter->pf_video_filter = FilterPacked;
            p_sys->pf_process_sat_hue_clip = packed_sat_hue_clip_C;
            p_sys->pf_process_sat_hue = packed_sat_hue_C;
            break;

        default:
175
            msg_Dbg( p_filter, "Unsupported input chroma (%4.4s)",
176
                     (char*)&(p_filter->fmt_in.video.i_chroma) );
177
            free(p_sys);
178 179 180
            return VLC_EGENERIC;
    }

181 182 183 184
    /* needed to get options passed in transcode using the
     * adjust{name=value} syntax */
    config_ChainParse( p_filter, "", ppsz_filter_options, p_filter->p_cfg );

185 186 187 188 189 190 191 192 193 194 195 196
    vlc_atomic_init_float( &p_sys->f_contrast,
                           var_CreateGetFloatCommand( p_filter, "contrast" ) );
    vlc_atomic_init_float( &p_sys->f_brightness,
                           var_CreateGetFloatCommand( p_filter, "brightness" ) );
    vlc_atomic_init_float( &p_sys->f_hue,
                           var_CreateGetFloatCommand( p_filter, "hue" ) );
    vlc_atomic_init_float( &p_sys->f_saturation,
                           var_CreateGetFloatCommand( p_filter, "saturation" ) );
    vlc_atomic_init_float( &p_sys->f_gamma,
                           var_CreateGetFloatCommand( p_filter, "gamma" ) );
    atomic_init( &p_sys->b_brightness_threshold,
                 var_CreateGetBoolCommand( p_filter, "brightness-threshold" ) );
197

198 199 200 201 202 203 204
    var_AddCallback( p_filter, "contrast",   AdjustCallback, p_sys );
    var_AddCallback( p_filter, "brightness", AdjustCallback, p_sys );
    var_AddCallback( p_filter, "hue",        AdjustCallback, p_sys );
    var_AddCallback( p_filter, "saturation", AdjustCallback, p_sys );
    var_AddCallback( p_filter, "gamma",      AdjustCallback, p_sys );
    var_AddCallback( p_filter, "brightness-threshold",
                                             AdjustCallback, p_sys );
205

206
    return VLC_SUCCESS;
207 208 209
}

/*****************************************************************************
210
 * Destroy: destroy adjust video filter
211 212
 *****************************************************************************/
static void Destroy( vlc_object_t *p_this )
213
{
214
    filter_t *p_filter = (filter_t *)p_this;
215 216 217 218 219 220 221 222 223 224 225
    filter_sys_t *p_sys = p_filter->p_sys;

    var_DelCallback( p_filter, "contrast",   AdjustCallback, p_sys );
    var_DelCallback( p_filter, "brightness", AdjustCallback, p_sys );
    var_DelCallback( p_filter, "hue",        AdjustCallback, p_sys );
    var_DelCallback( p_filter, "saturation", AdjustCallback, p_sys );
    var_DelCallback( p_filter, "gamma",      AdjustCallback, p_sys );
    var_DelCallback( p_filter, "brightness-threshold",
                                             AdjustCallback, p_sys );

    free( p_sys );
226 227 228
}

/*****************************************************************************
229
 * Run the filter on a Planar YUV picture
230
 *****************************************************************************/
231
static picture_t *FilterPlanar( filter_t *p_filter, picture_t *p_pic )
232
{
233 234 235
    /* The full range will only be used for 10-bit */
    int pi_luma[1024];
    int pi_gamma[1024];
236

237 238
    picture_t *p_outpic;

239
    filter_sys_t *p_sys = p_filter->p_sys;
240

241 242
    if( !p_pic ) return NULL;

Laurent Aimar's avatar
Laurent Aimar committed
243
    p_outpic = filter_NewPicture( p_filter );
244
    if( !p_outpic )
245
    {
246
        picture_Release( p_pic );
247
        return NULL;
248
    }
249

250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
    bool b_16bit;
    float f_range;
    switch( p_filter->fmt_in.video.i_chroma )
    {
        CASE_PLANAR_YUV10
            b_16bit = true;
            f_range = 1024.f;
            break;
        CASE_PLANAR_YUV9
            b_16bit = true;
            f_range = 512.f;
            break;
        default:
            b_16bit = false;
            f_range = 256.f;
    }

    const float f_max = f_range - 1.f;
    const unsigned i_max = f_max;
    const int i_range = f_range;
    const unsigned i_size = i_range;
    const unsigned i_mid = i_range >> 1;

273
    /* Get variables */
274 275 276 277 278
    int32_t i_cont = lroundf( vlc_atomic_load_float( &p_sys->f_contrast ) * f_max );
    int32_t i_lum = lroundf( (vlc_atomic_load_float( &p_sys->f_brightness ) - 1.f) * f_max );
    float f_hue = vlc_atomic_load_float( &p_sys->f_hue ) * (float)(M_PI / 180.);
    int i_sat = (int)( vlc_atomic_load_float( &p_sys->f_saturation ) * f_range );
    float f_gamma = 1.f / vlc_atomic_load_float( &p_sys->f_gamma );
279

280 281 282
    /*
     * Threshold mode drops out everything about luma, contrast and gamma.
     */
283
    if( !atomic_load( &p_sys->b_brightness_threshold ) )
284 285
    {

286 287
        /* Contrast is a fast but kludged function, so I put this gap to be
         * cleaner :) */
288
        i_lum += i_mid - i_cont / 2;
289 290

        /* Fill the gamma lookup table */
291
        for( unsigned i = 0 ; i < i_size; i++ )
292
        {
293
            pi_gamma[ i ] = VLC_CLIP( powf(i / f_max, f_gamma) * f_max, 0, i_max );
294 295 296
        }

        /* Fill the luma lookup table */
297
        for( unsigned i = 0 ; i < i_size; i++ )
298
        {
299
            pi_luma[ i ] = pi_gamma[VLC_CLIP( (int)(i_lum + i_cont * i / i_range), 0, i_max )];
300 301 302
        }
    }
    else
303
    {
304 305 306 307
        /*
         * We get luma as threshold value: the higher it is, the darker is
         * the image. Should I reverse this?
         */
308
        for( int i = 0 ; i < i_range; i++ )
309
        {
310
            pi_luma[ i ] = (i < i_lum) ? 0 : i_max;
311 312 313 314 315 316
        }

        /*
         * Desaturates image to avoid that strange yellow halo...
         */
        i_sat = 0;
317 318
    }

319 320 321
    /*
     * Do the Y plane
     */
322
    if ( b_16bit )
323
    {
324 325 326 327 328 329 330
        uint16_t *p_in, *p_in_end, *p_line_end;
        uint16_t *p_out;
        p_in = (uint16_t *) p_pic->p[Y_PLANE].p_pixels;
        p_in_end = p_in + p_pic->p[Y_PLANE].i_visible_lines
            * (p_pic->p[Y_PLANE].i_pitch >> 1) - 8;

        p_out = (uint16_t *) p_outpic->p[Y_PLANE].p_pixels;
331

332
        for( ; p_in < p_in_end ; )
333
        {
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
            p_line_end = p_in + (p_pic->p[Y_PLANE].i_visible_pitch >> 1) - 8;

            for( ; p_in < p_line_end ; )
            {
                /* Do 8 pixels at a time */
                *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
                *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
                *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
                *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
            }

            p_line_end += 8;

            for( ; p_in < p_line_end ; )
            {
                *p_out++ = pi_luma[ *p_in++ ];
            }

            p_in += (p_pic->p[Y_PLANE].i_pitch >> 1)
                - (p_pic->p[Y_PLANE].i_visible_pitch >> 1);
            p_out += (p_outpic->p[Y_PLANE].i_pitch >> 1)
                - (p_outpic->p[Y_PLANE].i_visible_pitch >> 1);
356
        }
357 358 359 360 361 362 363 364
    }
    else
    {
        uint8_t *p_in, *p_in_end, *p_line_end;
        uint8_t *p_out;
        p_in = p_pic->p[Y_PLANE].p_pixels;
        p_in_end = p_in + p_pic->p[Y_PLANE].i_visible_lines
                 * p_pic->p[Y_PLANE].i_pitch - 8;
365

366
        p_out = p_outpic->p[Y_PLANE].p_pixels;
367

368
        for( ; p_in < p_in_end ; )
369
        {
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
            p_line_end = p_in + p_pic->p[Y_PLANE].i_visible_pitch - 8;

            for( ; p_in < p_line_end ; )
            {
                /* Do 8 pixels at a time */
                *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
                *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
                *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
                *p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ];
            }

            p_line_end += 8;

            for( ; p_in < p_line_end ; )
            {
                *p_out++ = pi_luma[ *p_in++ ];
            }

            p_in += p_pic->p[Y_PLANE].i_pitch
                  - p_pic->p[Y_PLANE].i_visible_pitch;
            p_out += p_outpic->p[Y_PLANE].i_pitch
                   - p_outpic->p[Y_PLANE].i_visible_pitch;
392
        }
393
    }
394

395 396 397 398
    /*
     * Do the U and V planes
     */

399 400
    int i_sin = sinf(f_hue) * f_max;
    int i_cos = cosf(f_hue) * f_max;
401

402 403 404
    /* pow(2, (bpp * 2) - 1) */
    int i_x = ( cosf(f_hue) + sinf(f_hue) ) * f_range * i_mid;
    int i_y = ( cosf(f_hue) - sinf(f_hue) ) * f_range * i_mid;
405

406
    if ( i_sat > i_range )
407
    {
408 409 410 411
        /* Currently no errors are implemented in the function, if any are added
         * check them here */
        p_sys->pf_process_sat_hue_clip( p_pic, p_outpic, i_sin, i_cos, i_sat,
                                        i_x, i_y );
412 413 414
    }
    else
    {
415 416 417 418
        /* Currently no errors are implemented in the function, if any are added
         * check them here */
        p_sys->pf_process_sat_hue( p_pic, p_outpic, i_sin, i_cos, i_sat,
                                        i_x, i_y );
419 420
    }

421
    return CopyInfoAndRelease( p_outpic, p_pic );
422 423 424 425 426 427 428 429 430 431 432
}

/*****************************************************************************
 * Run the filter on a Packed YUV picture
 *****************************************************************************/
static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic )
{
    int pi_luma[256];
    int pi_gamma[256];

    picture_t *p_outpic;
433 434
    uint8_t *p_in, *p_in_end, *p_line_end;
    uint8_t *p_out;
435 436
    int i_y_offset, i_u_offset, i_v_offset;

437
    int i_pitch, i_visible_pitch;
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453

    double  f_hue;
    double  f_gamma;
    int32_t i_cont, i_lum;
    int i_sat, i_sin, i_cos, i_x, i_y;

    filter_sys_t *p_sys = p_filter->p_sys;

    if( !p_pic ) return NULL;

    i_pitch = p_pic->p->i_pitch;
    i_visible_pitch = p_pic->p->i_visible_pitch;

    if( GetPackedYuvOffsets( p_pic->format.i_chroma, &i_y_offset,
                             &i_u_offset, &i_v_offset ) != VLC_SUCCESS )
    {
454
        msg_Warn( p_filter, "Unsupported input chroma (%4.4s)",
455
                  (char*)&(p_pic->format.i_chroma) );
456 457

        picture_Release( p_pic );
458 459 460
        return NULL;
    }

461
    p_outpic = filter_NewPicture( p_filter );
462 463 464
    if( !p_outpic )
    {
        msg_Warn( p_filter, "can't get output picture" );
465 466

        picture_Release( p_pic );
467 468 469
        return NULL;
    }

470
    /* Get variables */
471 472 473 474 475
    i_cont = (int)( vlc_atomic_load_float( &p_sys->f_contrast ) * 255 );
    i_lum = (int)( (vlc_atomic_load_float( &p_sys->f_brightness ) - 1.0)*255 );
    f_hue = vlc_atomic_load_float( &p_sys->f_hue ) * (float)(M_PI / 180.);
    i_sat = (int)( vlc_atomic_load_float( &p_sys->f_saturation ) * 256 );
    f_gamma = 1.0 / vlc_atomic_load_float( &p_sys->f_gamma );
476 477 478 479

    /*
     * Threshold mode drops out everything about luma, contrast and gamma.
     */
480
    if( !atomic_load( &p_sys->b_brightness_threshold ) )
481 482 483 484 485 486 487
    {

        /* Contrast is a fast but kludged function, so I put this gap to be
         * cleaner :) */
        i_lum += 128 - i_cont / 2;

        /* Fill the gamma lookup table */
488
        for( int i = 0 ; i < 256 ; i++ )
489 490 491 492 493
        {
          pi_gamma[ i ] = clip_uint8_vlc( pow(i / 255.0, f_gamma) * 255.0);
        }

        /* Fill the luma lookup table */
494
        for( int i = 0 ; i < 256 ; i++ )
495 496 497 498 499 500 501 502 503 504
        {
            pi_luma[ i ] = pi_gamma[clip_uint8_vlc( i_lum + i_cont * i / 256)];
        }
    }
    else
    {
        /*
         * We get luma as threshold value: the higher it is, the darker is
         * the image. Should I reverse this?
         */
505
        for( int i = 0 ; i < 256 ; i++ )
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
        {
            pi_luma[ i ] = (i < i_lum) ? 0 : 255;
        }

        /*
         * Desaturates image to avoid that strange yellow halo...
         */
        i_sat = 0;
    }

    /*
     * Do the Y plane
     */

    p_in = p_pic->p->p_pixels + i_y_offset;
    p_in_end = p_in + p_pic->p->i_visible_lines * p_pic->p->i_pitch - 8 * 4;

    p_out = p_outpic->p->p_pixels + i_y_offset;

    for( ; p_in < p_in_end ; )
    {
        p_line_end = p_in + i_visible_pitch - 8 * 4;

        for( ; p_in < p_line_end ; )
        {
            /* Do 8 pixels at a time */
            *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
            *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
            *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
            *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
            *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
            *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
            *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
            *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
        }

        p_line_end += 8 * 4;

        for( ; p_in < p_line_end ; )
        {
            *p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2;
        }

        p_in += i_pitch - p_pic->p->i_visible_pitch;
        p_out += i_pitch - p_outpic->p->i_visible_pitch;
    }

    /*
     * Do the U and V planes
     */

    i_sin = sin(f_hue) * 256;
    i_cos = cos(f_hue) * 256;

    i_x = ( cos(f_hue) + sin(f_hue) ) * 32768;
    i_y = ( cos(f_hue) - sin(f_hue) ) * 32768;

    if ( i_sat > 256 )
    {
565 566
        if ( p_sys->pf_process_sat_hue_clip( p_pic, p_outpic, i_sin, i_cos, i_sat,
                                             i_x, i_y ) != VLC_SUCCESS )
567
        {
568 569 570 571 572 573
            /* Currently only one error can happen in the function, but if there
             * will be more of them, this message must go away */
            msg_Warn( p_filter, "Unsupported input chroma (%4.4s)",
                      (char*)&(p_pic->format.i_chroma) );
            picture_Release( p_pic );
            return NULL;
574 575 576 577
        }
    }
    else
    {
578 579
        if ( p_sys->pf_process_sat_hue( p_pic, p_outpic, i_sin, i_cos, i_sat,
                                        i_x, i_y ) != VLC_SUCCESS )
580
        {
581 582 583 584 585 586
            /* Currently only one error can happen in the function, but if there
             * will be more of them, this message must go away */
            msg_Warn( p_filter, "Unsupported input chroma (%4.4s)",
                      (char*)&(p_pic->format.i_chroma) );
            picture_Release( p_pic );
            return NULL;
587
        }
588 589
    }

590
    return CopyInfoAndRelease( p_outpic, p_pic );
591
}
592 593 594 595 596

static int AdjustCallback( vlc_object_t *p_this, char const *psz_var,
                           vlc_value_t oldval, vlc_value_t newval,
                           void *p_data )
{
597
    VLC_UNUSED(p_this); VLC_UNUSED(oldval);
598 599 600
    filter_sys_t *p_sys = (filter_sys_t *)p_data;

    if( !strcmp( psz_var, "contrast" ) )
601
        vlc_atomic_store_float( &p_sys->f_contrast, newval.f_float );
602
    else if( !strcmp( psz_var, "brightness" ) )
603
        vlc_atomic_store_float( &p_sys->f_brightness, newval.f_float );
604
    else if( !strcmp( psz_var, "hue" ) )
605
        vlc_atomic_store_float( &p_sys->f_hue, newval.f_float );
606
    else if( !strcmp( psz_var, "saturation" ) )
607
        vlc_atomic_store_float( &p_sys->f_saturation, newval.f_float );
608
    else if( !strcmp( psz_var, "gamma" ) )
609
        vlc_atomic_store_float( &p_sys->f_gamma, newval.f_float );
610
    else if( !strcmp( psz_var, "brightness-threshold" ) )
611
        atomic_store( &p_sys->b_brightness_threshold, newval.b_bool );
612

613 614
    return VLC_SUCCESS;
}