VideoEffects.m 53 KB
Newer Older
1 2 3
/*****************************************************************************
 * VideoEffects.m: MacOS X interface module
 *****************************************************************************
4
 * Copyright (C) 2011-2015 Felix Paul Kühne
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU 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
#import "CompatibilityFixes.h"
25 26
#import "intf.h"
#import "VideoEffects.h"
27
#import "SharedDialogs.h"
28
#import "CoreInteraction.h"
29

30 31 32 33
@interface VLCVideoEffects()
{
    NSInteger i_old_profile_index;
}
34 35
@end

36
#pragma mark -
37
#pragma mark Initialization
38

39 40
@implementation VLCVideoEffects

41 42
+ (void)initialize
{
43 44
    NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:[NSArray arrayWithObject:@";;;0;1.000000;1.000000;1.000000;1.000000;0.050000;16;2.000000;OTA=;4;4;16711680;20;15;120;Z3JhZGllbnQ=;1;0;16711680;6;80;VkxD;-1;;-1;255;2;3;3"], @"VideoEffectProfiles",
                                 [NSArray arrayWithObject:_NS("Default")], @"VideoEffectProfileNames", nil];
45 46 47
    [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
}

48 49
- (id)init
{
50 51 52
    self = [super initWithWindowNibName:@"VideoEffects"];
    if (self) {
        i_old_profile_index = -1;
53 54 55

        self.popupPanel = [[VLCPopupPanelController alloc] init];
        self.textfieldPanel = [[VLCTextfieldPanelController alloc] init];
56
    }
57

58
    return self;
59 60
}

61
- (void)windowDidLoad
62
{
63 64 65
    [self.window setTitle: _NS("Video Effects")];
    [self.window setExcludedFromWindowsMenu:YES];
    [self.window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
66

67 68 69 70 71
    [[_tabView tabViewItemAtIndex:[_tabView indexOfTabViewItemWithIdentifier:@"basic"]] setLabel:_NS("Basic")];
    [[_tabView tabViewItemAtIndex:[_tabView indexOfTabViewItemWithIdentifier:@"crop"]] setLabel:_NS("Crop")];
    [[_tabView tabViewItemAtIndex:[_tabView indexOfTabViewItemWithIdentifier:@"geometry"]] setLabel:_NS("Geometry")];
    [[_tabView tabViewItemAtIndex:[_tabView indexOfTabViewItemWithIdentifier:@"color"]] setLabel:_NS("Color")];
    [[_tabView tabViewItemAtIndex:[_tabView indexOfTabViewItemWithIdentifier:@"misc"]] setLabel:_NS("Miscellaneous")];
72

73 74
    [self resetProfileSelector];

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
    [_adjustCheckbox setTitle:_NS("Image Adjust")];
    [_adjustHueLabel setStringValue:_NS("Hue")];
    [_adjustContrastLabel setStringValue:_NS("Contrast")];
    [_adjustBrightnessLabel setStringValue:_NS("Brightness")];
    [_adjustBrightnessCheckbox setTitle:_NS("Brightness Threshold")];
    [_adjustSaturationLabel setStringValue:_NS("Saturation")];
    [_adjustGammaLabel setStringValue:_NS("Gamma")];
    [_adjustResetButton setTitle: _NS("Reset")];
    [_sharpenCheckbox setTitle:_NS("Sharpen")];
    [_sharpenLabel setStringValue:_NS("Sigma")];
    [_bandingCheckbox setTitle:_NS("Banding removal")];
    [_bandingLabel setStringValue:_NS("Radius")];
    [_grainCheckbox setTitle:_NS("Film Grain")];
    [_grainLabel setStringValue:_NS("Variance")];
    [_cropTopLabel setStringValue:_NS("Top")];
    [_cropLeftLabel setStringValue:_NS("Left")];
    [_cropRightLabel setStringValue:_NS("Right")];
    [_cropBottomLabel setStringValue:_NS("Bottom")];
    [_cropSyncTopBottomCheckbox setTitle:_NS("Synchronize top and bottom")];
    [_cropSyncLeftRightCheckbox setTitle:_NS("Synchronize left and right")];

    [_transformCheckbox setTitle:_NS("Transform")];
    [_transformPopup removeAllItems];
    [_transformPopup addItemWithTitle: _NS("Rotate by 90 degrees")];
    [[_transformPopup lastItem] setTag: 90];
    [_transformPopup addItemWithTitle: _NS("Rotate by 180 degrees")];
    [[_transformPopup lastItem] setTag: 180];
    [_transformPopup addItemWithTitle: _NS("Rotate by 270 degrees")];
    [[_transformPopup lastItem] setTag: 270];
    [_transformPopup addItemWithTitle: _NS("Flip horizontally")];
    [[_transformPopup lastItem] setTag: 1];
    [_transformPopup addItemWithTitle: _NS("Flip vertically")];
    [[_transformPopup lastItem] setTag: 2];
    [_zoomCheckbox setTitle:_NS("Magnification/Zoom")];
    [_puzzleCheckbox setTitle:_NS("Puzzle game")];
    [_puzzleRowsLabel setStringValue:_NS("Rows")];
    [_puzzleColumnsLabel setStringValue:_NS("Columns")];
    [_cloneCheckbox setTitle:_NS("Clone")];
    [_cloneNumberLabel setStringValue:_NS("Number of clones")];
    [_wallCheckbox setTitle:_NS("Wall")];
    [_wallNumbersOfRowsLabel setStringValue:_NS("Rows")];
    [_wallNumberOfColumnsLabel setStringValue:_NS("Columns")];

    [_thresholdCheckbox setTitle:_NS("Color threshold")];
    [_thresholdColorLabel setStringValue:_NS("Color")];
    [_thresholdSaturationLabel setStringValue:_NS("Saturation")];
    [_thresholdSimilarityLabel setStringValue:_NS("Similarity")];
    [_sepiaCheckbox setTitle:_NS("Sepia")];
    [_sepiaLabel setStringValue:_NS("Intensity")];
    [_noiseCheckbox setTitle:_NS("Noise")];
    [_gradientCheckbox setTitle:_NS("Gradient")];
    [_gradientModeLabel setStringValue:_NS("Mode")];
    [_gradientModePopup removeAllItems];
    [_gradientModePopup addItemWithTitle: _NS("Gradient")];
    [[_gradientModePopup lastItem] setTag: 1];
    [_gradientModePopup addItemWithTitle: _NS("Edge")];
    [[_gradientModePopup lastItem] setTag: 2];
    [_gradientModePopup addItemWithTitle: _NS("Hough")];
    [[_gradientModePopup lastItem] setTag: 3];
    [_gradientColorCheckbox setTitle:_NS("Color")];
    [_gradientCartoonCheckbox setTitle:_NS("Cartoon")];
    [_extractCheckbox setTitle:_NS("Color extraction")];
    [_extractLabel setStringValue:_NS("Color")];
    [_invertCheckbox setTitle:_NS("Invert colors")];
    [_posterizeCheckbox setTitle:_NS("Posterize")];
    [_posterizeLabel setStringValue:_NS("Posterize level")];
    [_blurCheckbox setTitle:_NS("Motion blur")];
    [_blurLabel setStringValue:_NS("Factor")];
    [_motiondetectCheckbox setTitle:_NS("Motion Detect")];
    [_watereffectCheckbox setTitle:_NS("Water effect")];
    [_wavesCheckbox setTitle:_NS("Waves")];
    [_psychedelicCheckbox setTitle:_NS("Psychedelic")];
    [_anaglyphCheckbox setTitle:_NS("Anaglyph")];

    [_addTextCheckbox setTitle:_NS("Add text")];
    [_addTextTextLabel setStringValue:_NS("Text")];
    [_addTextPositionLabel setStringValue:_NS("Position")];
    [_addTextPositionPopup removeAllItems];
    [_addTextPositionPopup addItemWithTitle: _NS("Center")];
    [[_addTextPositionPopup lastItem] setTag: 0];
    [_addTextPositionPopup addItemWithTitle: _NS("Left")];
    [[_addTextPositionPopup lastItem] setTag: 1];
    [_addTextPositionPopup addItemWithTitle: _NS("Right")];
    [[_addTextPositionPopup lastItem] setTag: 2];
    [_addTextPositionPopup addItemWithTitle: _NS("Top")];
    [[_addTextPositionPopup lastItem] setTag: 4];
    [_addTextPositionPopup addItemWithTitle: _NS("Bottom")];
    [[_addTextPositionPopup lastItem] setTag: 8];
    [_addTextPositionPopup addItemWithTitle: _NS("Top-Left")];
    [[_addTextPositionPopup lastItem] setTag: 5];
    [_addTextPositionPopup addItemWithTitle: _NS("Top-Right")];
    [[_addTextPositionPopup lastItem] setTag: 6];
    [_addTextPositionPopup addItemWithTitle: _NS("Bottom-Left")];
    [[_addTextPositionPopup lastItem] setTag: 9];
    [_addTextPositionPopup addItemWithTitle: _NS("Bottom-Right")];
    [[_addTextPositionPopup lastItem] setTag: 10];
    [_addLogoCheckbox setTitle:_NS("Add logo")];
    [_addLogoLogoLabel setStringValue:_NS("Logo")];
    [_addLogoPositionLabel setStringValue:_NS("Position")];
    [_addLogoPositionPopup removeAllItems];
    [_addLogoPositionPopup addItemWithTitle: _NS("Center")];
    [[_addLogoPositionPopup lastItem] setTag: 0];
    [_addLogoPositionPopup addItemWithTitle: _NS("Left")];
    [[_addLogoPositionPopup lastItem] setTag: 1];
    [_addLogoPositionPopup addItemWithTitle: _NS("Right")];
    [[_addLogoPositionPopup lastItem] setTag: 2];
    [_addLogoPositionPopup addItemWithTitle: _NS("Top")];
    [[_addLogoPositionPopup lastItem] setTag: 4];
    [_addLogoPositionPopup addItemWithTitle: _NS("Bottom")];
    [[_addLogoPositionPopup lastItem] setTag: 8];
    [_addLogoPositionPopup addItemWithTitle: _NS("Top-Left")];
    [[_addLogoPositionPopup lastItem] setTag: 5];
    [_addLogoPositionPopup addItemWithTitle: _NS("Top-Right")];
    [[_addLogoPositionPopup lastItem] setTag: 6];
    [_addLogoPositionPopup addItemWithTitle: _NS("Bottom-Left")];
    [[_addLogoPositionPopup lastItem] setTag: 9];
    [_addLogoPositionPopup addItemWithTitle: _NS("Bottom-Right")];
    [[_addLogoPositionPopup lastItem] setTag: 10];
    [_addLogoTransparencyLabel setStringValue:_NS("Transparency")];

    [_tabView selectFirstTabViewItem:self];
196

197 198 199 200 201 202
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(inputChangedEvent:)
                                                 name:VLCInputChangedNotification
                                               object:nil];


203 204 205
    [self resetValues];
}

206 207 208 209 210
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

211 212
- (void)updateCocoaWindowLevel:(NSInteger)i_level
{
213 214
    if (self.window && [self.window isVisible] && [self.window level] != i_level)
        [self.window setLevel: i_level];
215 216
}

217 218
#pragma mark -
#pragma mark internal functions
219 220 221 222 223 224 225 226 227 228

-(void)inputChangedEvent:(NSNotification *)o_notification
{
    // reset crop values when input changed
    [self setCropBottomValue:0];
    [self setCropTopValue:0];
    [self setCropLeftValue:0];
    [self setCropRightValue:0];
}

229 230 231
- (void)resetProfileSelector
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
232
    [_profilePopup removeAllItems];
233

234 235
    NSArray *profileNames = [defaults objectForKey:@"VideoEffectProfileNames"];
    [_profilePopup addItemsWithTitles:profileNames];
236

237 238 239 240
    [[_profilePopup menu] addItem:[NSMenuItem separatorItem]];
    [_profilePopup addItemWithTitle:_NS("Duplicate current profile...")];
    [[_profilePopup lastItem] setTarget: self];
    [[_profilePopup lastItem] setAction: @selector(addProfile:)];
241 242

    if ([profileNames count] > 1) {
243 244 245
        [_profilePopup addItemWithTitle:_NS("Organize profiles...")];
        [[_profilePopup lastItem] setTarget: self];
        [[_profilePopup lastItem] setAction: @selector(removeProfile:)];
246 247
    }

248
    [_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]];
249 250 251
    [self profileSelectorAction:self];
}

252 253
- (void)resetValues
{
254
    intf_thread_t *p_intf = VLCIntf;
255
    NSString *tmpString;
256
    char *tmpChar;
257 258
    BOOL b_state;

259 260
    /* do we have any filter enabled? if yes, show it. */
    char * psz_vfilters;
261 262
    psz_vfilters = config_GetPsz(p_intf, "video-filter");
    if (psz_vfilters) {
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
        [_adjustCheckbox setState: (NSInteger)strstr(psz_vfilters, "adjust")];
        [_sharpenCheckbox setState: (NSInteger)strstr(psz_vfilters, "sharpen")];
        [_bandingCheckbox setState: (NSInteger)strstr(psz_vfilters, "gradfun")];
        [_grainCheckbox setState: (NSInteger)strstr(psz_vfilters, "grain")];
        [_transformCheckbox setState: (NSInteger)strstr(psz_vfilters, "transform")];
        [_zoomCheckbox setState: (NSInteger)strstr(psz_vfilters, "magnify")];
        [_puzzleCheckbox setState: (NSInteger)strstr(psz_vfilters, "puzzle")];
        [_thresholdCheckbox setState: (NSInteger)strstr(psz_vfilters, "colorthres")];
        [_sepiaCheckbox setState: (NSInteger)strstr(psz_vfilters, "sepia")];
        [_noiseCheckbox setState: (NSInteger)strstr(psz_vfilters, "noise")];
        [_gradientCheckbox setState: (NSInteger)strstr(psz_vfilters, "gradient")];
        [_extractCheckbox setState: (NSInteger)strstr(psz_vfilters, "extract")];
        [_invertCheckbox setState: (NSInteger)strstr(psz_vfilters, "invert")];
        [_posterizeCheckbox setState: (NSInteger)strstr(psz_vfilters, "posterize")];
        [_blurCheckbox setState: (NSInteger)strstr(psz_vfilters, "motionblur")];
        [_motiondetectCheckbox setState: (NSInteger)strstr(psz_vfilters, "motiondetect")];
        [_watereffectCheckbox setState: (NSInteger)strstr(psz_vfilters, "ripple")];
        [_wavesCheckbox setState: (NSInteger)strstr(psz_vfilters, "wave")];
        [_psychedelicCheckbox setState: (NSInteger)strstr(psz_vfilters, "psychedelic")];
        [_anaglyphCheckbox setState: (NSInteger)strstr(psz_vfilters, "anaglyph")];
283
        free(psz_vfilters);
284
    } else {
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
        [_adjustCheckbox setState: NSOffState];
        [_sharpenCheckbox setState: NSOffState];
        [_bandingCheckbox setState: NSOffState];
        [_grainCheckbox setState: NSOffState];
        [_transformCheckbox setState: NSOffState];
        [_zoomCheckbox setState: NSOffState];
        [_puzzleCheckbox setState: NSOffState];
        [_thresholdCheckbox setState: NSOffState];
        [_sepiaCheckbox setState: NSOffState];
        [_noiseCheckbox setState: NSOffState];
        [_gradientCheckbox setState: NSOffState];
        [_extractCheckbox setState: NSOffState];
        [_invertCheckbox setState: NSOffState];
        [_posterizeCheckbox setState: NSOffState];
        [_blurCheckbox setState: NSOffState];
        [_motiondetectCheckbox setState: NSOffState];
        [_watereffectCheckbox setState: NSOffState];
        [_wavesCheckbox setState: NSOffState];
        [_psychedelicCheckbox setState: NSOffState];
        [_anaglyphCheckbox setState: NSOffState];
305
    }
306

307
    psz_vfilters = config_GetPsz(p_intf, "sub-source");
308
    if (psz_vfilters) {
309 310
        [_addTextCheckbox setState: (NSInteger)strstr(psz_vfilters, "marq")];
        [_addLogoCheckbox setState: (NSInteger)strstr(psz_vfilters, "logo")];
311
        free(psz_vfilters);
312
    } else {
313 314
        [_addTextCheckbox setState: NSOffState];
        [_addLogoCheckbox setState: NSOffState];
315
    }
316

317 318
    psz_vfilters = config_GetPsz(p_intf, "video-splitter");
    if (psz_vfilters) {
319 320
        [_cloneCheckbox setState: (NSInteger)strstr(psz_vfilters, "clone")];
        [_wallCheckbox setState: (NSInteger)strstr(psz_vfilters, "wall")];
321 322
        free(psz_vfilters);
    } else {
323 324
        [_cloneCheckbox setState: NSOffState];
        [_wallCheckbox setState: NSOffState];
325 326
    }

327
    /* fetch and show the various values */
328 329 330 331 332 333 334 335 336 337 338 339
    [_adjustHueSlider setFloatValue: config_GetFloat(p_intf, "hue")];
    [_adjustContrastSlider setFloatValue: config_GetFloat(p_intf, "contrast")];
    [_adjustBrightnessSlider setFloatValue: config_GetFloat(p_intf, "brightness")];
    [_adjustSaturationSlider setFloatValue: config_GetFloat(p_intf, "saturation")];
    [_adjustBrightnessCheckbox setState:(config_GetInt(p_intf, "brightness-threshold") != 0 ? NSOnState : NSOffState)];
    [_adjustGammaSlider setFloatValue: config_GetFloat(p_intf, "gamma")];
    [_adjustBrightnessSlider setToolTip: [NSString stringWithFormat:@"%0.3f", config_GetFloat(p_intf, "brightness")]];
    [_adjustContrastSlider setToolTip: [NSString stringWithFormat:@"%0.3f", config_GetFloat(p_intf, "contrast")]];
    [_adjustGammaSlider setToolTip: [NSString stringWithFormat:@"%0.3f", config_GetFloat(p_intf, "gamma")]];
    [_adjustHueSlider setToolTip: [NSString stringWithFormat:@"%.0f", config_GetFloat(p_intf, "hue")]];
    [_adjustSaturationSlider setToolTip: [NSString stringWithFormat:@"%0.3f", config_GetFloat(p_intf, "saturation")]];
    b_state = [_adjustCheckbox state];
340

341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
    [_adjustBrightnessSlider setEnabled: b_state];
    [_adjustBrightnessCheckbox setEnabled: b_state];
    [_adjustContrastSlider setEnabled: b_state];
    [_adjustGammaSlider setEnabled: b_state];
    [_adjustHueSlider setEnabled: b_state];
    [_adjustSaturationSlider setEnabled: b_state];
    [_adjustBrightnessLabel setEnabled: b_state];
    [_adjustContrastLabel setEnabled: b_state];
    [_adjustGammaLabel setEnabled: b_state];
    [_adjustHueLabel setEnabled: b_state];
    [_adjustSaturationLabel setEnabled: b_state];
    [_adjustResetButton setEnabled: b_state];

    [_sharpenSlider setFloatValue: config_GetFloat(p_intf, "sharpen-sigma")];
    [_sharpenSlider setToolTip: [NSString stringWithFormat:@"%0.3f", config_GetFloat(p_intf, "sharpen-sigma")]];
    [_sharpenSlider setEnabled: [_sharpenCheckbox state]];
    [_sharpenLabel setEnabled: [_sharpenCheckbox state]];

    [_bandingSlider setIntValue: config_GetInt(p_intf, "gradfun-radius")];
    [_bandingSlider setToolTip: [NSString stringWithFormat:@"%lli", config_GetInt(p_intf, "gradfun-radius")]];
    [_bandingSlider setEnabled: [_bandingCheckbox state]];
    [_bandingLabel setEnabled: [_bandingCheckbox state]];

    [_grainSlider setFloatValue: config_GetFloat(p_intf, "grain-variance")];
    [_grainSlider setToolTip: [NSString stringWithFormat:@"%0.3f", config_GetFloat(p_intf, "grain-variance")]];
    [_grainSlider setEnabled: [_grainCheckbox state]];
    [_grainLabel setEnabled: [_grainCheckbox state]];
368

369 370 371 372
    [self setCropLeftValue: 0];
    [self setCropTopValue: 0];
    [self setCropRightValue: 0];
    [self setCropBottomValue: 0];
373 374
    [_cropSyncTopBottomCheckbox setState: NSOffState];
    [_cropSyncLeftRightCheckbox setState: NSOffState];
375

376
    tmpChar = config_GetPsz(p_intf, "transform-type");
377
    tmpString = toNSStr(tmpChar);
378
    if ([tmpString isEqualToString:@"hflip"])
379
        [_transformPopup selectItemWithTag: 1];
380
    else if ([tmpString isEqualToString:@"vflip"])
381
        [_transformPopup selectItemWithTag: 2];
382
    else
383
        [_transformPopup selectItemWithTag:[tmpString intValue]];
384
    FREENULL(tmpChar);
385
    [_transformPopup setEnabled: [_transformCheckbox state]];
386 387 388

    [self setPuzzleColumnsValue: config_GetInt(p_intf, "puzzle-cols")];
    [self setPuzzleRowsValue: config_GetInt(p_intf, "puzzle-rows")];
389 390 391 392 393 394 395 396
    b_state = [_puzzleCheckbox state];
    [_puzzleRowsTextField setEnabled: b_state];
    [_puzzleRowsStepper setEnabled: b_state];
    [_puzzleRowsLabel setEnabled: b_state];
    [_puzzleColumnsTextField setEnabled: b_state];
    [_puzzleColumnsStepper setEnabled: b_state];
    [_puzzleColumnsLabel setEnabled: b_state];

397
    [self setCloneValue: config_GetInt(p_intf, "clone-count")];
398 399 400 401
    b_state = [_cloneCheckbox state];
    [_cloneNumberLabel setEnabled: b_state];
    [_cloneNumberTextField setEnabled: b_state];
    [_cloneNumberStepper setEnabled: b_state];
402

403
    b_state = [_wallCheckbox state];
404
    [self setWallRowsValue: config_GetInt(p_intf, "wall-rows")];
405 406 407
    [_wallNumbersOfRowsLabel setEnabled: b_state];
    [_wallNumbersOfRowsTextField setEnabled: b_state];
    [_wallNumbersOfRowsStepper setEnabled: b_state];
408
    [self setWallColumnsValue: config_GetInt(p_intf, "wall-cols")];
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
    [_wallNumberOfColumnsLabel setEnabled: b_state];
    [_wallNumberOfColumnsTextField setEnabled: b_state];
    [_wallNumberOfColumnsStepper setEnabled: b_state];

    [_thresholdColorTextField setStringValue: [[NSString stringWithFormat:@"%llx", config_GetInt(p_intf, "colorthres-color")] uppercaseString]];
    [_thresholdSaturationSlider setIntValue: config_GetInt(p_intf, "colorthres-saturationthres")];
    [_thresholdSaturationSlider setToolTip: [NSString stringWithFormat:@"%lli", config_GetInt(p_intf, "colorthres-saturationthres")]];
    [_thresholdSimilaritySlider setIntValue: config_GetInt(p_intf, "colorthres-similaritythres")];
    [_thresholdSimilaritySlider setToolTip: [NSString stringWithFormat:@"%lli", config_GetInt(p_intf, "colorthres-similaritythres")]];

    b_state = [_thresholdCheckbox state];
    [_thresholdColorTextField setEnabled: b_state];
    [_thresholdColorLabel setEnabled: b_state];
    [_thresholdSaturationSlider setEnabled: b_state];
    [_thresholdSaturationLabel setEnabled: b_state];
    [_thresholdSimilaritySlider setEnabled: b_state];
    [_thresholdSimilarityLabel setEnabled: b_state];
426

427
    [self setSepiaValue: config_GetInt(p_intf, "sepia-intensity")];
428 429 430 431
    b_state = [_sepiaCheckbox state];
    [_sepiaTextField setEnabled: b_state];
    [_sepiaStepper setEnabled: b_state];
    [_sepiaLabel setEnabled: b_state];
432

433
    tmpChar = config_GetPsz(p_intf, "gradient-mode");
434
    tmpString = toNSStr(tmpChar);
435
    if ([tmpString isEqualToString:@"hough"])
436
        [_gradientModePopup selectItemWithTag: 3];
437
    else if ([tmpString isEqualToString:@"edge"])
438
        [_gradientModePopup selectItemWithTag: 2];
439
    else
440
        [_gradientModePopup selectItemWithTag: 1];
441
    FREENULL(tmpChar);
442 443 444 445 446 447 448
    [_gradientCartoonCheckbox setState: config_GetInt(p_intf, "gradient-cartoon")];
    [_gradientColorCheckbox setState: config_GetInt(p_intf, "gradient-type")];
    b_state = [_gradientCheckbox state];
    [_gradientModePopup setEnabled: b_state];
    [_gradientModeLabel setEnabled: b_state];
    [_gradientCartoonCheckbox setEnabled: b_state];
    [_gradientColorCheckbox setEnabled: b_state];
449

450 451 452
    [_extractTextField setStringValue: [[NSString stringWithFormat:@"%llx", config_GetInt(p_intf, "extract-component")] uppercaseString]];
    [_extractTextField setEnabled: [_extractCheckbox state]];
    [_extractLabel setEnabled: [_extractCheckbox state]];
453 454

    [self setPosterizeValue: config_GetInt(p_intf, "posterize-level")];
455 456 457 458
    b_state = [_posterizeCheckbox state];
    [_posterizeTextField setEnabled: b_state];
    [_posterizeStepper setEnabled: b_state];
    [_posterizeLabel setEnabled: b_state];
459

460 461 462 463
    [_blurSlider setIntValue: config_GetInt(p_intf, "blur-factor")];
    [_blurSlider setToolTip: [NSString stringWithFormat:@"%lli", config_GetInt(p_intf, "blur-factor")]];
    [_blurSlider setEnabled: [_blurCheckbox state]];
    [_blurLabel setEnabled: [_blurCheckbox state]];
464

465
    tmpChar = config_GetPsz(p_intf, "marq-marquee");
466 467
    [_addTextTextTextField setStringValue:toNSStr(tmpChar)];
    if (tmpChar)
468
        FREENULL(tmpChar);
469 470 471 472 473 474
    [_addTextPositionPopup selectItemWithTag: config_GetInt(p_intf, "marq-position")];
    b_state = [_addTextCheckbox state];
    [_addTextPositionPopup setEnabled: b_state];
    [_addTextPositionLabel setEnabled: b_state];
    [_addTextTextLabel setEnabled: b_state];
    [_addTextTextTextField setEnabled: b_state];
475

476
    tmpChar = config_GetPsz(p_intf, "logo-file");
477 478
    [_addLogoLogoTextField setStringValue: toNSStr(tmpChar)];
    if (tmpChar)
479
        FREENULL(tmpChar);
480 481 482 483 484 485 486 487 488 489
    [_addLogoPositionPopup selectItemWithTag: config_GetInt(p_intf, "logo-position")];
    [_addLogoTransparencySlider setIntValue: config_GetInt(p_intf, "logo-opacity")];
    [_addLogoTransparencySlider setToolTip: [NSString stringWithFormat:@"%lli", config_GetInt(p_intf, "logo-opacity")]];
    b_state = [_addLogoCheckbox state];
    [_addLogoPositionPopup setEnabled: b_state];
    [_addLogoPositionLabel setEnabled: b_state];
    [_addLogoLogoTextField setEnabled: b_state];
    [_addLogoLogoLabel setEnabled: b_state];
    [_addLogoTransparencySlider setEnabled: b_state];
    [_addLogoTransparencyLabel setEnabled: b_state];
490 491
}

492 493
- (NSString *)generateProfileString
{
494
    intf_thread_t *p_intf = VLCIntf;
495
    return [NSString stringWithFormat:@"%@;%@;%@;%lli;%f;%f;%f;%f;%f;%lli;%f;%@;%lli;%lli;%lli;%lli;%lli;%lli;%@;%lli;%lli;%lli;%lli;%lli;%@;%lli;%@;%lli;%lli;%lli;%lli;%lli;%lli;%f",
496 497 498
            B64EncAndFree(config_GetPsz(p_intf, "video-filter")),
            B64EncAndFree(config_GetPsz(p_intf, "sub-source")),
            B64EncAndFree(config_GetPsz(p_intf, "video-splitter")),
499
            0LL, // former "hue" value, deprecated since 3.0.0
500 501 502 503 504 505 506
            config_GetFloat(p_intf, "contrast"),
            config_GetFloat(p_intf, "brightness"),
            config_GetFloat(p_intf, "saturation"),
            config_GetFloat(p_intf, "gamma"),
            config_GetFloat(p_intf, "sharpen-sigma"),
            config_GetInt(p_intf, "gradfun-radius"),
            config_GetFloat(p_intf, "grain-variance"),
507
            B64EncAndFree(config_GetPsz(p_intf, "transform-type")),
508 509 510 511 512 513
            config_GetInt(p_intf, "puzzle-rows"),
            config_GetInt(p_intf, "puzzle-cols"),
            config_GetInt(p_intf, "colorthres-color"),
            config_GetInt(p_intf, "colorthres-saturationthres"),
            config_GetInt(p_intf, "colorthres-similaritythres"),
            config_GetInt(p_intf, "sepia-intensity"),
514
            B64EncAndFree(config_GetPsz(p_intf, "gradient-mode")),
515 516 517 518 519
            config_GetInt(p_intf, "gradient-cartoon"),
            config_GetInt(p_intf, "gradient-type"),
            config_GetInt(p_intf, "extract-component"),
            config_GetInt(p_intf, "posterize-level"),
            config_GetInt(p_intf, "blur-factor"),
520
            B64EncAndFree(config_GetPsz(p_intf, "marq-marquee")),
521
            config_GetInt(p_intf, "marq-position"),
522
            B64EncAndFree(config_GetPsz(p_intf, "logo-file")),
523
            config_GetInt(p_intf, "logo-position"),
524 525 526
            config_GetInt(p_intf, "logo-opacity"),
            config_GetInt(p_intf, "clone-count"),
            config_GetInt(p_intf, "wall-rows"),
527 528
            config_GetInt(p_intf, "wall-cols"),
            // version 2 of profile string:
529 530 531
            config_GetInt(p_intf, "brightness-threshold"), // index: 32
            // version 3 of profile string: (vlc-3.0.0)
            config_GetFloat(p_intf, "hue") // index: 33
532 533 534 535 536
            ];
}

#pragma mark -
#pragma mark generic UI code
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555

- (void)saveCurrentProfile
{
    if (i_old_profile_index == -1)
        return;

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    /* fetch all the current settings in a uniform string */
    NSString *newProfile = [self generateProfileString];

    NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfiles"]];
    if (i_old_profile_index >= [workArray count])
        return;

    [workArray replaceObjectAtIndex:i_old_profile_index withObject:newProfile];
    [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"];
    [defaults synchronize];
}

556 557
- (IBAction)toggleWindow:(id)sender
{
558 559
    if ([self.window isKeyWindow])
        [self.window orderOut:sender];
560
    else {
561 562
        [self.window setLevel: [[[VLCMain sharedInstance] voutController] currentStatusWindowLevel]];
        [self.window makeKeyAndOrderFront:sender];
563
    }
564 565 566 567
}

- (IBAction)profileSelectorAction:(id)sender
{
568
    intf_thread_t *p_intf = VLCIntf;
569
    [self saveCurrentProfile];
570
    i_old_profile_index = [_profilePopup indexOfSelectedItem];
571
    VLCCoreInteraction *vci_si = [VLCCoreInteraction sharedInstance];
572

573
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
574
    NSUInteger selectedProfile = [_profilePopup indexOfSelectedItem];
575 576

    /* fetch preset */
577
    NSArray *items = [[[defaults objectForKey:@"VideoEffectProfiles"] objectAtIndex:selectedProfile] componentsSeparatedByString:@";"];
578

579 580 581 582 583 584 585
    // version 1 of profile string has 32 entries
    if ([items count] < 32) {
        msg_Err(p_intf, "Error in parsing profile string");
        [self resetValues];
        return;
    }

586
    /* filter handling */
587
    NSString *tempString = B64DecNSStr([items firstObject]);
588
    vout_thread_t *p_vout = getVout();
589

590
    /* enable the new filters */
591 592 593
    config_PutPsz(p_intf, "video-filter", [tempString UTF8String]);
    if (p_vout) {
        var_SetString(p_vout, "video-filter", [tempString UTF8String]);
594
    }
595

596
    tempString = B64DecNSStr([items objectAtIndex:1]);
597
    /* enable another round of new filters */
598 599 600 601 602 603 604
    config_PutPsz(p_intf, "sub-source", [tempString UTF8String]);
    if (p_vout) {
        var_SetString(p_vout, "sub-source", [tempString UTF8String]);
    }

    if (p_vout) {
        vlc_object_release(p_vout);
605
    }
606

607
    tempString = B64DecNSStr([items objectAtIndex:2]);
608
    /* enable another round of new filters */
609
    char *psz_current_splitter = var_GetString(pl_Get(p_intf), "video-splitter");
610
    bool b_filter_changed = ![tempString isEqualToString:toNSStr(psz_current_splitter)];
611 612 613 614 615
    free(psz_current_splitter);

    if (b_filter_changed) {
        config_PutPsz(p_intf, "video-splitter", [tempString UTF8String]);
        var_SetString(pl_Get(p_intf), "video-splitter", [tempString UTF8String]);
616
    }
617 618

    /* try to set filter values on-the-fly and store them appropriately */
619
    // index 3 is deprecated
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
    [vci_si setVideoFilterProperty:"contrast" forFilter:"adjust" float:[[items objectAtIndex:4] floatValue]];
    [vci_si setVideoFilterProperty:"brightness" forFilter:"adjust" float:[[items objectAtIndex:5] floatValue]];
    [vci_si setVideoFilterProperty:"saturation" forFilter:"adjust" float:[[items objectAtIndex:6] floatValue]];
    [vci_si setVideoFilterProperty:"gamma" forFilter:"adjust" float:[[items objectAtIndex:7] floatValue]];
    [vci_si setVideoFilterProperty:"sharpen-sigma" forFilter:"sharpen" float:[[items objectAtIndex:8] floatValue]];
    [vci_si setVideoFilterProperty:"gradfun-radius" forFilter:"gradfun" integer:[[items objectAtIndex:9] intValue]];
    [vci_si setVideoFilterProperty:"grain-variance" forFilter:"grain" float:[[items objectAtIndex:10] floatValue]];
    [vci_si setVideoFilterProperty:"transform-type" forFilter:"transform" string:[B64DecNSStr([items objectAtIndex:11]) UTF8String]];
    [vci_si setVideoFilterProperty:"puzzle-rows" forFilter:"puzzle" integer:[[items objectAtIndex:12] intValue]];
    [vci_si setVideoFilterProperty:"puzzle-cols" forFilter:"puzzle" integer:[[items objectAtIndex:13] intValue]];
    [vci_si setVideoFilterProperty:"colorthres-color" forFilter:"colorthres" integer:[[items objectAtIndex:14] intValue]];
    [vci_si setVideoFilterProperty:"colorthres-saturationthres" forFilter:"colorthres" integer:[[items objectAtIndex:15] intValue]];
    [vci_si setVideoFilterProperty:"colorthres-similaritythres" forFilter:"colorthres" integer:[[items objectAtIndex:16] intValue]];
    [vci_si setVideoFilterProperty:"sepia-intensity" forFilter:"sepia" integer:[[items objectAtIndex:17] intValue]];
    [vci_si setVideoFilterProperty:"gradient-mode" forFilter:"gradient" string:[B64DecNSStr([items objectAtIndex:18]) UTF8String]];
635
    [vci_si setVideoFilterProperty:"gradient-cartoon" forFilter:"gradient" boolean:[[items objectAtIndex:19] intValue]];
636 637 638 639 640 641 642 643 644 645 646 647
    [vci_si setVideoFilterProperty:"gradient-type" forFilter:"gradient" integer:[[items objectAtIndex:20] intValue]];
    [vci_si setVideoFilterProperty:"extract-component" forFilter:"extract" integer:[[items objectAtIndex:21] intValue]];
    [vci_si setVideoFilterProperty:"posterize-level" forFilter:"posterize" integer:[[items objectAtIndex:22] intValue]];
    [vci_si setVideoFilterProperty:"blur-factor" forFilter:"motionblur" integer:[[items objectAtIndex:23] intValue]];
    [vci_si setVideoFilterProperty:"marq-marquee" forFilter:"marq" string:[B64DecNSStr([items objectAtIndex:24]) UTF8String]];
    [vci_si setVideoFilterProperty:"marq-position" forFilter:"marq" integer:[[items objectAtIndex:25] intValue]];
    [vci_si setVideoFilterProperty:"logo-file" forFilter:"logo" string:[B64DecNSStr([items objectAtIndex:26]) UTF8String]];
    [vci_si setVideoFilterProperty:"logo-position" forFilter:"logo" integer:[[items objectAtIndex:27] intValue]];
    [vci_si setVideoFilterProperty:"logo-opacity" forFilter:"logo" integer:[[items objectAtIndex:28] intValue]];
    [vci_si setVideoFilterProperty:"clone-count" forFilter:"clone" integer:[[items objectAtIndex:29] intValue]];
    [vci_si setVideoFilterProperty:"wall-rows" forFilter:"wall" integer:[[items objectAtIndex:30] intValue]];
    [vci_si setVideoFilterProperty:"wall-cols" forFilter:"wall" integer:[[items objectAtIndex:31] intValue]];
648

649 650 651 652
    if ([items count] >= 33) { // version >=2 of profile string
        [vci_si setVideoFilterProperty: "brightness-threshold" forFilter: "adjust" boolean: [[items objectAtIndex:32] intValue]];
    }

653 654 655 656 657 658 659 660 661 662
    float hueValue;
    if ([items count] >= 34) { // version >=3 of profile string
        hueValue = [[items objectAtIndex:33] floatValue];
    } else {
        hueValue = [[items objectAtIndex:3] intValue]; // deprecated since 3.0.0
        // convert to new scale ([0,360] --> [-180,180])
        hueValue -= 180;
    }
    [vci_si setVideoFilterProperty:"hue" forFilter:"adjust" float:hueValue];

663 664 665 666 667 668
    [defaults setInteger:selectedProfile forKey:@"VideoEffectSelectedProfile"];
    [defaults synchronize];

    [self resetValues];
}

669
- (void)addProfile:(id)sender
670 671
{
    /* show panel */
672 673 674 675 676
    [_textfieldPanel setTitle: _NS("Duplicate current profile for a new profile")];
    [_textfieldPanel setSubTitle: _NS("Enter a name for the new profile:")];
    [_textfieldPanel setCancelButtonLabel: _NS("Cancel")];
    [_textfieldPanel setOKButtonLabel: _NS("Save")];

677 678
    __weak typeof(self) _self = self;
    [_textfieldPanel runModalForWindow:self.window completionHandler:^(NSInteger returnCode, NSString *resultingText) {
679

680
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
681

682 683 684 685
        if (returnCode != NSOKButton) {
            [_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]];
            return;
        }
686

687
        NSArray *profileNames = [defaults objectForKey:@"VideoEffectProfileNames"];
688

689 690 691
        // duplicate names are not allowed in the popup control
        if ([resultingText length] == 0 || [profileNames containsObject:resultingText]) {
            [_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]];
692

693 694 695 696
            NSAlert *alert = [[NSAlert alloc] init];
            [alert setAlertStyle:NSCriticalAlertStyle];
            [alert setMessageText:_NS("Please enter a unique name for the new profile.")];
            [alert setInformativeText:_NS("Multiple profiles with the same name are not allowed.")];
697

698 699 700 701 702 703
            [alert beginSheetModalForWindow:_self.window
                              modalDelegate:nil
                             didEndSelector:nil
                                contextInfo:nil];
            return;
        }
704

705 706
        /* fetch all the current settings in a uniform string */
        NSString *newProfile = [_self generateProfileString];
707

708
        /* add string to user defaults as well as a label */
709

710 711 712 713
        NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfiles"]];
        [workArray addObject:newProfile];
        [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"];
        [defaults setInteger:[workArray count] - 1 forKey:@"VideoEffectSelectedProfile"];
714

715 716 717
        workArray = [[NSMutableArray alloc] initWithArray:[defaults objectForKey:@"VideoEffectProfileNames"]];
        [workArray addObject:resultingText];
        [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfileNames"];
718

719 720
        /* save defaults */
        [defaults synchronize];
721

722 723 724
        /* refresh UI */
        [_self resetProfileSelector];
    }];
725 726
}

727
- (void)removeProfile:(id)sender
728 729
{
    /* show panel */
730 731 732 733 734 735 736 737
    [_popupPanel setTitle:_NS("Remove a preset")];
    [_popupPanel setSubTitle:_NS("Select the preset you would like to remove:")];
    [_popupPanel setOKButtonLabel:_NS("Remove")];
    [_popupPanel setCancelButtonLabel:_NS("Cancel")];
    [_popupPanel setPopupButtonContent:[[NSUserDefaults standardUserDefaults] objectForKey:@"VideoEffectProfileNames"]];
    [_popupPanel setTarget:self];

    [_popupPanel runModalForWindow:self.window];
738 739
}

740
- (void)panel:(VLCPopupPanelController *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
741
{
742 743 744
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    if (value != NSOKButton) {
745
        [_profilePopup selectItemAtIndex:[defaults integerForKey:@"VideoEffectSelectedProfile"]];
746
        return;
747 748
    }

749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765
    /* remove selected profile from settings */
    NSMutableArray *workArray = [[NSMutableArray alloc] initWithArray: [defaults objectForKey:@"VideoEffectProfiles"]];
    [workArray removeObjectAtIndex:item];
    [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfiles"];

    workArray = [[NSMutableArray alloc] initWithArray: [defaults objectForKey:@"VideoEffectProfileNames"]];
    [workArray removeObjectAtIndex:item];
    [defaults setObject:[NSArray arrayWithArray:workArray] forKey:@"VideoEffectProfileNames"];

    if (i_old_profile_index >= item)
        [defaults setInteger:i_old_profile_index - 1 forKey:@"VideoEffectSelectedProfile"];

    /* save defaults */
    [defaults synchronize];

    /* do not save deleted profile */
    i_old_profile_index = -1;
766 767 768 769
    /* refresh UI */
    [self resetProfileSelector];
}

770 771 772 773
#pragma mark -
#pragma mark basic
- (IBAction)enableAdjust:(id)sender
{
774
    BOOL b_state = [_adjustCheckbox state];
775

776
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "adjust" on: b_state];
777 778 779 780 781 782 783 784 785 786 787 788
    [_adjustBrightnessSlider setEnabled: b_state];
    [_adjustBrightnessCheckbox setEnabled: b_state];
    [_adjustBrightnessLabel setEnabled: b_state];
    [_adjustContrastSlider setEnabled: b_state];
    [_adjustContrastLabel setEnabled: b_state];
    [_adjustGammaSlider setEnabled: b_state];
    [_adjustGammaLabel setEnabled: b_state];
    [_adjustHueSlider setEnabled: b_state];
    [_adjustHueLabel setEnabled: b_state];
    [_adjustSaturationSlider setEnabled: b_state];
    [_adjustSaturationLabel setEnabled: b_state];
    [_adjustResetButton setEnabled: b_state];
789 790 791 792
}

- (IBAction)adjustSliderChanged:(id)sender
{
793 794 795 796 797 798 799 800 801 802 803 804 805
    if (sender == _adjustBrightnessSlider)
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "brightness" forFilter: "adjust" float: [_adjustBrightnessSlider floatValue]];
    else if (sender == _adjustContrastSlider)
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "contrast" forFilter: "adjust" float: [_adjustContrastSlider floatValue]];
    else if (sender == _adjustGammaSlider)
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "gamma" forFilter: "adjust" float: [_adjustGammaSlider floatValue]];
    else if (sender == _adjustHueSlider)
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "hue" forFilter: "adjust" float: [_adjustHueSlider floatValue]];
    else if (sender == _adjustSaturationSlider)
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "saturation" forFilter: "adjust" float: [_adjustSaturationSlider floatValue]];

    if (sender == _adjustHueSlider)
        [_adjustHueSlider setToolTip: [NSString stringWithFormat:@"%.0f", [_adjustHueSlider floatValue]]];
806 807
    else
        [sender setToolTip: [NSString stringWithFormat:@"%0.3f", [sender floatValue]]];
808 809 810 811
}

- (IBAction)enableAdjustBrightnessThreshold:(id)sender
{
812 813
    VLCCoreInteraction *vci_si = [VLCCoreInteraction sharedInstance];

814 815 816 817 818 819 820 821 822 823 824
    if (sender == _adjustResetButton) {
        [_adjustBrightnessSlider setFloatValue: 1.0];
        [_adjustContrastSlider setFloatValue: 1.0];
        [_adjustGammaSlider setFloatValue: 1.0];
        [_adjustHueSlider setFloatValue: 0];
        [_adjustSaturationSlider setFloatValue: 1.0];
        [_adjustBrightnessSlider setToolTip: [NSString stringWithFormat:@"%0.3f", 1.0]];
        [_adjustContrastSlider setToolTip: [NSString stringWithFormat:@"%0.3f", 1.0]];
        [_adjustGammaSlider setToolTip: [NSString stringWithFormat:@"%0.3f", 1.0]];
        [_adjustHueSlider setToolTip: [NSString stringWithFormat:@"%.0f", 0.0]];
        [_adjustSaturationSlider setToolTip: [NSString stringWithFormat:@"%0.3f", 1.0]];
825 826 827
        [vci_si setVideoFilterProperty: "brightness" forFilter: "adjust" float: 1.0];
        [vci_si setVideoFilterProperty: "contrast" forFilter: "adjust" float: 1.0];
        [vci_si setVideoFilterProperty: "gamma" forFilter: "adjust" float: 1.0];
828
        [vci_si setVideoFilterProperty: "hue" forFilter: "adjust" float: 0.0];
829
        [vci_si setVideoFilterProperty: "saturation" forFilter: "adjust" float: 1.0];
830
    } else
831
        [vci_si setVideoFilterProperty: "brightness-threshold" forFilter: "adjust" boolean: [_adjustBrightnessCheckbox state]];
832

833 834 835 836
}

- (IBAction)enableSharpen:(id)sender
{
837
    BOOL b_state = [_sharpenCheckbox state];
838

839
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "sharpen" on: b_state];
840 841
    [_sharpenSlider setEnabled: b_state];
    [_sharpenLabel setEnabled: b_state];
842 843 844 845
}

- (IBAction)sharpenSliderChanged:(id)sender
{
846
    [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "sharpen-sigma" forFilter: "sharpen" float: [sender floatValue]];
847
    [sender setToolTip: [NSString stringWithFormat:@"%0.3f", [sender floatValue]]];
848 849 850 851
}

- (IBAction)enableBanding:(id)sender
{
852
    BOOL b_state = [_bandingCheckbox state];
853

854
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "gradfun" on: b_state];
855 856
    [_bandingSlider setEnabled: b_state];
    [_bandingLabel setEnabled: b_state];
857 858 859 860
}

- (IBAction)bandingSliderChanged:(id)sender
{
861
    [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "gradfun-radius" forFilter: "gradfun" integer: [sender intValue]];
862
    [sender setToolTip: [NSString stringWithFormat:@"%i", [sender intValue]]];
863 864 865 866
}

- (IBAction)enableGrain:(id)sender
{
867
    BOOL b_state = [_grainCheckbox state];
868

869
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "grain" on: b_state];
870 871
    [_grainSlider setEnabled: b_state];
    [_grainLabel setEnabled: b_state];
872 873 874 875
}

- (IBAction)grainSliderChanged:(id)sender
{
876
    [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "grain-variance" forFilter: "grain" float: [sender floatValue]];
877
    [sender setToolTip: [NSString stringWithFormat:@"%0.3f", [sender floatValue]]];
878 879 880 881 882
}


#pragma mark -
#pragma mark crop
883

884
- (IBAction)cropObjectChanged:(id)sender
885
{
886 887
    if ([_cropSyncTopBottomCheckbox state]) {
        if (sender == _cropBottomTextField || sender == _cropBottomStepper)
888 889 890
            [self setCropTopValue: [self cropBottomValue]];
        else
            [self setCropBottomValue: [self cropTopValue]];
891
    }
892 893
    if ([_cropSyncLeftRightCheckbox state]) {
        if (sender == _cropRightTextField || sender == _cropRightStepper)
894 895 896
            [self setCropLeftValue: [self cropRightValue]];
        else
            [self setCropRightValue: [self cropLeftValue]];
897
    }
898

899
    vout_thread_t *p_vout = getVout();
900
    if (p_vout) {
901 902 903 904
        var_SetInteger(p_vout, "crop-top", [_cropTopTextField intValue]);
        var_SetInteger(p_vout, "crop-bottom", [_cropBottomTextField intValue]);
        var_SetInteger(p_vout, "crop-left", [_cropLeftTextField intValue]);
        var_SetInteger(p_vout, "crop-right", [_cropRightTextField intValue]);
905
        vlc_object_release(p_vout);
906
    }
907 908 909 910 911 912
}

#pragma mark -
#pragma mark geometry
- (IBAction)enableTransform:(id)sender
{
913 914
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "transform" on: [_transformCheckbox state]];
    [_transformPopup setEnabled: [_transformCheckbox state]];
915 916 917 918
}

- (IBAction)transformModifierChanged:(id)sender
{
919
    NSInteger tag = [[_transformPopup selectedItem] tag];
920
    const char *psz_string = [[NSString stringWithFormat:@"%li", tag] UTF8String];
921
    if (tag == 1)
922
        psz_string = "hflip";
923
    else if (tag == 2)
924
        psz_string = "vflip";
925

926
    [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "transform-type" forFilter: "transform" string: psz_string];
927 928 929 930
}

- (IBAction)enableZoom:(id)sender
{
931
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "magnify" on: [_zoomCheckbox state]];
932 933 934 935
}

- (IBAction)enablePuzzle:(id)sender
{
936
    BOOL b_state = [_puzzleCheckbox state];
937

938
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "puzzle" on: b_state];
939 940 941 942 943 944
    [_puzzleColumnsTextField setEnabled: b_state];
    [_puzzleColumnsStepper setEnabled: b_state];
    [_puzzleColumnsLabel setEnabled: b_state];
    [_puzzleRowsTextField setEnabled: b_state];
    [_puzzleRowsStepper setEnabled: b_state];
    [_puzzleRowsLabel setEnabled: b_state];
945 946 947 948
}

- (IBAction)puzzleModifierChanged:(id)sender
{
949
    if (sender == _puzzleColumnsTextField || sender == _puzzleColumnsStepper)
950
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "puzzle-cols" forFilter: "puzzle" integer: [sender intValue]];
951
    else
952
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "puzzle-rows" forFilter: "puzzle" integer: [sender intValue]];
953 954
}

955 956
- (IBAction)enableClone:(id)sender
{
957
    BOOL b_state = [_cloneCheckbox state];
958

959 960 961
    if (b_state && [_wallCheckbox state]) {
        [_wallCheckbox setState: NSOffState];
        [self enableWall:_wallCheckbox];
962 963
    }

964
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "clone" on: b_state];
965 966 967
    [_cloneNumberLabel setEnabled: b_state];
    [_cloneNumberTextField setEnabled: b_state];
    [_cloneNumberStepper setEnabled: b_state];
968 969 970 971
}

- (IBAction)cloneModifierChanged:(id)sender
{
972
    [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "clone-count" forFilter: "clone" integer: [_cloneNumberTextField intValue]];
973 974 975 976
}

- (IBAction)enableWall:(id)sender
{
977
    BOOL b_state = [_wallCheckbox state];
978

979 980 981
    if (b_state && [_cloneCheckbox state]) {
        [_cloneCheckbox setState: NSOffState];
        [self enableClone:_cloneCheckbox];
982 983
    }

984
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "wall" on: b_state];
985 986 987
    [_wallNumberOfColumnsTextField setEnabled: b_state];
    [_wallNumberOfColumnsStepper setEnabled: b_state];
    [_wallNumberOfColumnsLabel setEnabled: b_state];
988

989 990 991
    [_wallNumbersOfRowsTextField setEnabled: b_state];
    [_wallNumbersOfRowsStepper setEnabled: b_state];
    [_wallNumbersOfRowsLabel setEnabled: b_state];
992 993 994 995
}

- (IBAction)wallModifierChanged:(id)sender
{
996
    if (sender == _wallNumberOfColumnsTextField || sender == _wallNumberOfColumnsStepper)
997
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "wall-cols" forFilter: "wall" integer: [sender intValue]];
998
    else
999
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "wall-rows" forFilter: "wall" integer: [sender intValue]];
1000
}
1001 1002 1003 1004 1005

#pragma mark -
#pragma mark color
- (IBAction)enableThreshold:(id)sender
{
1006
    BOOL b_state = [_thresholdCheckbox state];
1007

1008
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "colorthres" on: b_state];
1009 1010 1011 1012 1013 1014
    [_thresholdColorTextField setEnabled: b_state];
    [_thresholdColorLabel setEnabled: b_state];
    [_thresholdSaturationSlider setEnabled: b_state];
    [_thresholdSaturationLabel setEnabled: b_state];
    [_thresholdSimilaritySlider setEnabled: b_state];
    [_thresholdSimilarityLabel setEnabled: b_state];
1015 1016 1017 1018
}

- (IBAction)thresholdModifierChanged:(id)sender
{
1019 1020 1021 1022 1023
    if (sender == _thresholdColorTextField)
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "colorthres-color" forFilter: "colorthres" integer: [_thresholdColorTextField intValue]];
    else if (sender == _thresholdSaturationSlider) {
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "colorthres-saturationthres" forFilter: "colorthres" integer: [_thresholdSaturationSlider intValue]];
        [_thresholdSaturationSlider setToolTip: [NSString stringWithFormat:@"%i", [_thresholdSaturationSlider intValue]]];
1024
    } else {
1025 1026
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "colorthres-similaritythres" forFilter: "colorthres" integer: [_thresholdSimilaritySlider intValue]];
        [_thresholdSimilaritySlider setToolTip: [NSString stringWithFormat:@"%i", [_thresholdSimilaritySlider intValue]]];
1027
    }
1028 1029 1030 1031
}

- (IBAction)enableSepia:(id)sender
{
1032
    BOOL b_state = [_sepiaCheckbox state];
1033

1034
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "sepia" on: b_state];
1035 1036 1037
    [_sepiaTextField setEnabled: b_state];
    [_sepiaStepper setEnabled: b_state];
    [_sepiaLabel setEnabled: b_state];
1038 1039 1040 1041
}

- (IBAction)sepiaModifierChanged:(id)sender
{
1042
    [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "sepia-intensity" forFilter: "sepia" integer: [_sepiaTextField intValue]];
1043 1044 1045 1046
}

- (IBAction)enableNoise:(id)sender
{
1047
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "noise" on: [_noiseCheckbox state]];
1048 1049 1050 1051
}

- (IBAction)enableGradient:(id)sender
{
1052
    BOOL b_state = [_gradientCheckbox state];
1053

1054
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "gradient" on: b_state];
1055 1056 1057 1058
    [_gradientModePopup setEnabled: b_state];
    [_gradientModeLabel setEnabled: b_state];
    [_gradientColorCheckbox setEnabled: b_state];
    [_gradientCartoonCheckbox setEnabled: b_state];
1059 1060 1061 1062
}

- (IBAction)gradientModifierChanged:(id)sender
{
1063 1064
    if (sender == _gradientModePopup) {
        if ([[_gradientModePopup selectedItem] tag] == 3)
1065
            [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "gradient-mode" forFilter: "gradient" string: "hough"];
1066
        else if ([[_gradientModePopup selectedItem] tag] == 2)
1067
            [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "gradient-mode" forFilter: "gradient" string: "edge"];
1068
        else
1069
            [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "gradient-mode" forFilter: "gradient" string: "gradient"];
1070 1071
    } else if (sender == _gradientColorCheckbox)
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "gradient-type" forFilter: "gradient" integer: [_gradientColorCheckbox state]];
1072
    else
1073
        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "gradient-cartoon" forFilter: "gradient" boolean: [_gradientCartoonCheckbox state]];
1074 1075 1076 1077
}

- (IBAction)enableExtract:(id)sender
{
1078
    BOOL b_state = [_extractCheckbox state];
1079
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "extract" on: b_state];
1080 1081
    [_extractTextField setEnabled: b_state];
    [_extractLabel setEnabled: b_state];
1082 1083 1084 1085
}

- (IBAction)extractModifierChanged:(id)sender
{
1086
    [[VLCCoreInteraction sharedInstance] setVideoFilterProperty: "extract-component" forFilter: "extract" integer: [_extractTextField intValue]];
1087 1088 1089 1090
}

- (IBAction)enableInvert:(id)sender
{
1091
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "invert" on: [_invertCheckbox state]];
1092 1093 1094 1095
}

- (IBAction)enablePosterize:(id)sender
{
1096
    BOOL b_state = [_posterizeCheckbox state];
1097

1098
    [[VLCCoreInteraction sharedInstance] setVideoFilter: "posterize" on: b_state];