]> git.sesse.net Git - vlc/blob - modules/gui/macosx/VideoEffects.m
macosx: fixed a 300 byte memory leak
[vlc] / modules / gui / macosx / VideoEffects.m
1 /*****************************************************************************
2  * VideoEffects.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2011 Felix Paul Kühne
5  * $Id$
6  *
7  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #import "intf.h"
25 #import <vlc_common.h>
26 #import "VideoEffects.h"
27
28 #pragma mark -
29 #pragma mark Initialization & Generic code
30
31 @implementation VLCVideoEffects
32 static VLCVideoEffects *_o_sharedInstance = nil;
33
34 + (VLCVideoEffects *)sharedInstance
35 {
36     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
37 }
38
39 - (id)init
40 {
41     if (_o_sharedInstance) {
42         [self dealloc];
43     } else {
44         p_intf = VLCIntf;
45         _o_sharedInstance = [super init];
46     }
47     
48     return _o_sharedInstance;
49 }
50
51 - (IBAction)toggleWindow:(id)sender
52 {
53     if( [o_window isVisible] )
54         [o_window orderOut:sender];
55     else
56         [o_window makeKeyAndOrderFront:sender];
57 }
58
59 - (void)awakeFromNib
60 {
61     [o_window setTitle: _NS("Video Effects")];
62     [o_window setExcludedFromWindowsMenu:YES];
63     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"basic"]] setLabel:_NS("Basic")];
64     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"crop"]] setLabel:_NS("Crop")];
65     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"geometry"]] setLabel:_NS("Geometry")];
66     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"color"]] setLabel:_NS("Color")];
67     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"overlay"]] setLabel:_NS("Video output/Overlay")];
68     [[o_tableView tabViewItemAtIndex:[o_tableView indexOfTabViewItemWithIdentifier:@"logo"]] setLabel:_NS("Logo")];
69
70     [o_adjust_ckb setTitle:_NS("Image Adjust")];
71     [o_adjust_hue_lbl setStringValue:_NS("Hue")];
72     [o_adjust_contrast_lbl setStringValue:_NS("Contrast")];
73     [o_adjust_brightness_lbl setStringValue:_NS("Brightness")];
74     [o_adjust_brightness_ckb setTitle:_NS("Brightness Threshold")];
75     [o_adjust_saturation_lbl setStringValue:_NS("Saturation")];
76     [o_adjust_gamma_lbl setStringValue:_NS("Gamma")];
77     [o_adjust_opaque_lbl setStringValue:_NS("Opaqueness")];
78     [o_sharpen_ckb setTitle:_NS("Sharpen")];
79     [o_sharpen_lbl setStringValue:_NS("Sigma")];
80     [o_banding_ckb setTitle:_NS("Banding removal")];
81     [o_banding_lbl setStringValue:_NS("Radius")];
82     [o_grain_ckb setTitle:_NS("Film Grain")];
83     [o_grain_lbl setStringValue:_NS("Variance")];
84     [o_crop_top_lbl setStringValue:_NS("Top")];
85     [o_crop_left_lbl setStringValue:_NS("Left")];
86     [o_crop_right_lbl setStringValue:_NS("Right")];
87     [o_crop_bottom_lbl setStringValue:_NS("Bottom")];
88     [o_crop_sync_top_bottom_ckb setTitle:_NS("Synchronize top and bottom")];
89     [o_crop_sync_left_right_ckb setTitle:_NS("Synchronize left and right")];
90
91     [o_transform_ckb setTitle:_NS("Transform")];
92     [o_transform_pop removeAllItems];
93     [o_transform_pop addItemWithTitle: _NS("Rotate by 90 degrees")];
94     [[o_transform_pop lastItem] setTag: 90];
95     [o_transform_pop addItemWithTitle: _NS("Rotate by 180 degrees")];
96     [[o_transform_pop lastItem] setTag: 180];
97     [o_transform_pop addItemWithTitle: _NS("Rotate by 270 degrees")];
98     [[o_transform_pop lastItem] setTag: 270];
99     [o_transform_pop addItemWithTitle: _NS("Flip horizontally")];
100     [[o_transform_pop lastItem] setTag: 1];
101     [o_transform_pop addItemWithTitle: _NS("Flip vertically")];
102     [[o_transform_pop lastItem] setTag: 2];
103     [o_zoom_ckb setTitle:_NS("Magnification/Zoom")];
104     [o_puzzle_ckb setTitle:_NS("Puzzle game")];
105     [o_puzzle_rows_lbl setStringValue:_NS("Rows")];
106     [o_puzzle_columns_lbl setStringValue:_NS("Columns")];
107     [o_puzzle_blackslot_ckb setTitle:_NS("Black Slot")];
108
109     [o_threshold_ckb setTitle:_NS("Color threshold")];
110     [o_threshold_color_lbl setStringValue:_NS("Color")];
111     [o_threshold_saturation_lbl setStringValue:_NS("Saturation")];
112     [o_threshold_similarity_lbl setStringValue:_NS("Similarity")];
113     [o_sepia_ckb setTitle:_NS("Sepia")];
114     [o_sepia_lbl setStringValue:_NS("Intensity")];
115     [o_noise_ckb setTitle:_NS("Noise")];
116     [o_gradient_ckb setTitle:_NS("Gradient")];
117     [o_gradient_mode_lbl setStringValue:_NS("Mode")];
118     [o_gradient_mode_pop removeAllItems];
119     [o_gradient_mode_pop addItemWithTitle: _NS("Gradient")];
120     [[o_gradient_mode_pop lastItem] setTag: 1];
121     [o_gradient_mode_pop addItemWithTitle: _NS("Edge")];
122     [[o_gradient_mode_pop lastItem] setTag: 2];
123     [o_gradient_mode_pop addItemWithTitle: _NS("Hough")];
124     [[o_gradient_mode_pop lastItem] setTag: 3];
125     [o_gradient_color_ckb setTitle:_NS("Color")];
126     [o_gradient_cartoon_ckb setTitle:_NS("Cartoon")];
127     [o_extract_ckb setTitle:_NS("Color extraction")];
128     [o_extract_lbl setStringValue:_NS("Color")];
129     [o_invert_ckb setTitle:_NS("Invert colors")];
130     [o_posterize_ckb setTitle:_NS("Posterize")];
131     [o_posterize_lbl setStringValue:_NS("Posterize level")];
132     [o_blur_ckb setTitle:_NS("Motion blue")];
133     [o_blur_lbl setStringValue:_NS("Factor")];
134     [o_motiondetect_ckb setTitle:_NS("Motion Detect")];
135     [o_watereffect_ckb setTitle:_NS("Water effect")];
136     [o_waves_ckb setTitle:_NS("Waves")];
137     [o_psychedelic_ckb setTitle:_NS("Psychedelic")];
138
139     [o_clone_ckb setTitle:_NS("Image clone")];
140     [o_clone_lbl setStringValue:_NS("Number of clones")];
141     [o_addtext_ckb setTitle:_NS("Add text")];
142     [o_addtext_text_lbl setStringValue:_NS("Text")];
143     [o_addtext_pos_lbl setStringValue:_NS("Position")];
144     [o_addtext_pos_pop removeAllItems];
145     [o_addtext_pos_pop addItemWithTitle: _NS("Center")];
146     [[o_addtext_pos_pop lastItem] setTag: 0];
147     [o_addtext_pos_pop addItemWithTitle: _NS("Left")];
148     [[o_addtext_pos_pop lastItem] setTag: 1];
149     [o_addtext_pos_pop addItemWithTitle: _NS("Right")];
150     [[o_addtext_pos_pop lastItem] setTag: 2];
151     [o_addtext_pos_pop addItemWithTitle: _NS("Top")];
152     [[o_addtext_pos_pop lastItem] setTag: 4];
153     [o_addtext_pos_pop addItemWithTitle: _NS("Bottom")];
154     [[o_addtext_pos_pop lastItem] setTag: 8];
155     [o_addtext_pos_pop addItemWithTitle: _NS("Top-Left")];
156     [[o_addtext_pos_pop lastItem] setTag: 5];
157     [o_addtext_pos_pop addItemWithTitle: _NS("Top-Right")];
158     [[o_addtext_pos_pop lastItem] setTag: 6];
159     [o_addtext_pos_pop addItemWithTitle: _NS("Bottom-Left")];
160     [[o_addtext_pos_pop lastItem] setTag: 9];
161     [o_addtext_pos_pop addItemWithTitle: _NS("Bottom-Right")];
162     [[o_addtext_pos_pop lastItem] setTag: 10];
163
164     [o_addlogo_ckb setTitle:_NS("Add logo")];
165     [o_addlogo_logo_lbl setStringValue:_NS("Logo")];
166     [o_addlogo_top_lbl setStringValue:_NS("Top")];
167     [o_addlogo_left_lbl setStringValue:_NS("Left")];
168     [o_addlogo_transparency_lbl setStringValue:_NS("Transparency")];
169     [o_eraselogo_ckb setTitle:_NS("Logo erase")];
170     [o_eraselogo_mask_lbl setStringValue:_NS("Mask")];
171     [o_eraselogo_top_lbl setStringValue:_NS("Top")];
172     [o_eraselogo_left_lbl setStringValue:_NS("Left")];
173
174     [o_tableView selectFirstTabViewItem:self];
175
176     [self resetValues];
177 }
178
179 - (void)resetValues
180 {
181     NSString *tmpString;
182     /* do we have any filter enabled? if yes, show it. */
183     char * psz_vfilters;
184     psz_vfilters = config_GetPsz( p_intf, "video-filter" );
185     if( psz_vfilters ) {
186         [o_adjust_ckb setState: (NSInteger)strstr( psz_vfilters, "adjust")];
187         [o_sharpen_ckb setState: (NSInteger)strstr( psz_vfilters, "sharpen")];
188         [o_banding_ckb setState: (NSInteger)strstr( psz_vfilters, "gradfun")];
189         [o_grain_ckb setState: (NSInteger)strstr( psz_vfilters, "grain")];
190         [o_transform_ckb setState: (NSInteger)strstr( psz_vfilters, "transform")];
191         [o_zoom_ckb setState: (NSInteger)strstr( psz_vfilters, "magnify")];
192         [o_puzzle_ckb setState: (NSInteger)strstr( psz_vfilters, "puzzle")];
193         [o_threshold_ckb setState: (NSInteger)strstr( psz_vfilters, "colorthres")];
194         [o_sepia_ckb setState: (NSInteger)strstr( psz_vfilters, "sepia")];
195         [o_noise_ckb setState: (NSInteger)strstr( psz_vfilters, "noise")];
196         [o_gradient_ckb setState: (NSInteger)strstr( psz_vfilters, "gradient")];
197         [o_extract_ckb setState: (NSInteger)strstr( psz_vfilters, "extract")];
198         [o_invert_ckb setState: (NSInteger)strstr( psz_vfilters, "invert")];
199         [o_posterize_ckb setState: (NSInteger)strstr( psz_vfilters, "posterize")];
200         [o_blur_ckb setState: (NSInteger)strstr( psz_vfilters, "motionblur")];
201         [o_motiondetect_ckb setState: (NSInteger)strstr( psz_vfilters, "motiondetect")];
202         [o_watereffect_ckb setState: (NSInteger)strstr( psz_vfilters, "ripple")];
203         [o_waves_ckb setState: (NSInteger)strstr( psz_vfilters, "wave")];
204         [o_psychedelic_ckb setState: (NSInteger)strstr( psz_vfilters, "psychedelic")];
205         [o_clone_ckb setState: (NSInteger)strstr( psz_vfilters, "clone")];
206         free( psz_vfilters );
207     }
208     // TODO: don't forget about o_addtext_ckb, o_addlogo_ckb, o_eraselogo_ckb
209
210     /* fetch and show the various values */
211     [o_adjust_hue_sld setIntValue: config_GetInt( p_intf, "hue" )];
212     [o_adjust_contrast_sld setFloatValue: config_GetFloat( p_intf, "contrast" )];
213     [o_adjust_brightness_sld setFloatValue: config_GetFloat( p_intf, "brightness" )];
214     [o_adjust_saturation_sld setFloatValue: config_GetFloat( p_intf, "saturation" )];
215     [o_adjust_gamma_sld setFloatValue: config_GetFloat( p_intf, "gamma" )];
216     [o_adjust_brightness_sld setEnabled: [o_adjust_ckb state]];
217     [o_adjust_brightness_ckb setEnabled: [o_adjust_ckb state]];
218     [o_adjust_contrast_sld setEnabled: [o_adjust_ckb state]];
219     [o_adjust_gamma_sld setEnabled: [o_adjust_ckb state]];
220     [o_adjust_hue_sld setEnabled: [o_adjust_ckb state]];
221     [o_adjust_saturation_sld setEnabled: [o_adjust_ckb state]];
222     [o_adjust_brightness_lbl setEnabled: [o_adjust_ckb state]];
223     [o_adjust_contrast_lbl setEnabled: [o_adjust_ckb state]];
224     [o_adjust_gamma_lbl setEnabled: [o_adjust_ckb state]];
225     [o_adjust_hue_lbl setEnabled: [o_adjust_ckb state]];
226     [o_adjust_saturation_lbl setEnabled: [o_adjust_ckb state]];
227     [o_adjust_opaque_sld setFloatValue: config_GetFloat( p_intf, "macosx-opaqueness" )];
228     [o_adjust_opaque_sld setEnabled: [o_adjust_ckb state]];
229     [o_adjust_opaque_lbl setEnabled: [o_adjust_ckb state]];
230     [o_sharpen_sld setFloatValue: config_GetFloat( p_intf, "sharpen-sigma" )];
231     [o_sharpen_sld setEnabled: [o_sharpen_ckb state]];
232     [o_sharpen_lbl setEnabled: [o_sharpen_ckb state]];
233     [o_banding_sld setIntValue: config_GetInt( p_intf, "gradfun-radius" )];
234     [o_banding_sld setEnabled: [o_banding_ckb state]];
235     [o_banding_lbl setEnabled: [o_banding_ckb state]];
236     [o_grain_sld setFloatValue: config_GetFloat( p_intf, "grain-variance" )];
237     [o_grain_sld setEnabled: [o_grain_ckb state]];
238     [o_grain_lbl setEnabled: [o_grain_ckb state]];
239
240     [o_crop_top_fld setIntValue: 0];
241     [o_crop_left_fld setIntValue: 0];
242     [o_crop_right_fld setIntValue: 0];
243     [o_crop_bottom_fld setIntValue: 0];
244     [o_crop_sync_top_bottom_ckb setState: NSOffState];
245     [o_crop_sync_left_right_ckb setState: NSOffState];
246
247     tmpString = [NSString stringWithUTF8String: config_GetPsz( p_intf, "transform-type" )];
248     if( [tmpString isEqualToString:@"hflip"] )
249         [o_transform_pop selectItemWithTag: 1];
250     else if( [tmpString isEqualToString:@"vflip"] )
251         [o_transform_pop selectItemWithTag: 2];
252     else
253         [o_transform_pop selectItemWithTag:[tmpString intValue]];
254     [o_transform_pop setEnabled: [o_transform_ckb state]];
255     [o_puzzle_rows_fld setIntValue: config_GetInt( p_intf, "puzzle-rows" )];
256     [o_puzzle_columns_fld setIntValue: config_GetInt( p_intf, "puzzle-cols" )];
257     [o_puzzle_blackslot_ckb setState: config_GetInt( p_intf, "puzzle-black-slot" )];
258     [o_puzzle_rows_fld setEnabled: [o_puzzle_ckb state]];
259     [o_puzzle_rows_lbl setEnabled: [o_puzzle_ckb state]];
260     [o_puzzle_columns_fld setEnabled: [o_puzzle_ckb state]];
261     [o_puzzle_columns_lbl setEnabled: [o_puzzle_ckb state]];
262     [o_puzzle_blackslot_ckb setEnabled: [o_puzzle_ckb state]];
263
264     [o_threshold_color_fld setStringValue: [[NSString stringWithFormat:@"%x", config_GetInt( p_intf, "colorthres-color" )] uppercaseString]];
265     [o_threshold_saturation_sld setIntValue: config_GetInt( p_intf, "colorthres-saturationthres" )];
266     [o_threshold_similarity_sld setIntValue: config_GetInt( p_intf, "colorthres-similaritythres" )];
267     [o_threshold_color_fld setEnabled: [o_threshold_ckb state]];
268     [o_threshold_color_lbl setEnabled: [o_threshold_ckb state]];
269     [o_threshold_saturation_sld setEnabled: [o_threshold_ckb state]];
270     [o_threshold_saturation_lbl setEnabled: [o_threshold_ckb state]];
271     [o_threshold_similarity_sld setEnabled: [o_threshold_ckb state]];
272     [o_threshold_similarity_lbl setEnabled: [o_threshold_ckb state]];
273     [o_sepia_fld setIntValue: config_GetInt( p_intf, "sepia-intensity" )];
274     [o_sepia_fld setEnabled: [o_sepia_ckb state]];
275     [o_sepia_lbl setEnabled: [o_sepia_ckb state]];
276     tmpString = [NSString stringWithUTF8String: config_GetPsz( p_intf, "gradient-mode" )];
277     if( [tmpString isEqualToString:@"hough"] )
278         [o_gradient_mode_pop selectItemWithTag: 3];
279     else if( [tmpString isEqualToString:@"edge"] )
280         [o_gradient_mode_pop selectItemWithTag: 2];
281     else
282         [o_gradient_mode_pop selectItemWithTag: 1];
283     [o_gradient_cartoon_ckb setState: config_GetInt( p_intf, "gradient-cartoon" )];
284     [o_gradient_color_ckb setState: config_GetInt( p_intf, "gradient-type" )];
285     [o_gradient_mode_pop setEnabled: [o_gradient_ckb state]];
286     [o_gradient_mode_lbl setEnabled: [o_gradient_ckb state]];
287     [o_gradient_cartoon_ckb setEnabled: [o_gradient_ckb state]];
288     [o_gradient_color_ckb setEnabled: [o_gradient_ckb state]];
289     [o_extract_fld setStringValue: [[NSString stringWithFormat:@"%x", config_GetInt( p_intf, "extract-component" )] uppercaseString]];
290     [o_extract_fld setEnabled: [o_extract_ckb state]];
291     [o_extract_lbl setEnabled: [o_extract_ckb state]];
292     [o_posterize_fld setIntValue: config_GetInt( p_intf, "posterize-level" )];
293     [o_posterize_fld setEnabled: [o_posterize_ckb state]];
294     [o_posterize_lbl setEnabled: [o_posterize_ckb state]];
295     [o_blur_sld setIntValue: config_GetInt( p_intf, "blur-factor" )];
296     [o_blur_sld setEnabled: [o_blur_ckb state]];
297     [o_blur_lbl setEnabled: [o_blur_ckb state]];
298
299     [o_clone_fld setIntValue: config_GetInt( p_intf, "clone-count" )];
300     [o_clone_fld setEnabled: [o_clone_ckb state]];
301     [o_clone_lbl setEnabled: [o_clone_ckb state]];
302     if( config_GetPsz( p_intf, "marq-marquee" ) )
303         [o_addtext_text_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "marq-marquee" )]];
304     [o_addtext_pos_pop selectItemWithTag: config_GetInt( p_intf, "marq-position" )];
305     [o_addtext_pos_pop setEnabled: [o_addtext_ckb state]];
306     [o_addtext_pos_lbl setEnabled: [o_addtext_ckb state]];
307     [o_addtext_text_lbl setEnabled: [o_addtext_ckb state]];
308     [o_addtext_text_fld setEnabled: [o_addtext_ckb state]];
309
310     if( config_GetPsz( p_intf, "logo-file" ) )
311        [o_addlogo_logo_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "logo-file" )]];
312     [o_addlogo_top_fld setIntValue: config_GetInt( p_intf, "logo-x" )];
313     [o_addlogo_left_fld setIntValue: config_GetInt( p_intf, "logo-y" )];
314     [o_addlogo_transparency_sld setIntValue: config_GetInt( p_intf, "logo-opacity" )];
315     [o_addlogo_logo_fld setEnabled: [o_addlogo_ckb state]];
316     [o_addlogo_logo_lbl setEnabled: [o_addlogo_ckb state]];
317     [o_addlogo_left_fld setEnabled: [o_addlogo_ckb state]];
318     [o_addlogo_left_lbl setEnabled: [o_addlogo_ckb state]];
319     [o_addlogo_top_fld setEnabled: [o_addlogo_ckb state]];
320     [o_addlogo_top_lbl setEnabled: [o_addlogo_ckb state]];
321     [o_addlogo_transparency_sld setEnabled: [o_addlogo_ckb state]];
322     [o_addlogo_transparency_lbl setEnabled: [o_addlogo_ckb state]];
323     if( config_GetPsz( p_intf, "erase-mask" ) )
324         [o_eraselogo_mask_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "erase-mask" )]];
325     [o_eraselogo_top_fld setIntValue: config_GetInt( p_intf, "erase-x" )];
326     [o_eraselogo_left_fld setIntValue: config_GetInt( p_intf, "erase-y" )];
327     [o_eraselogo_mask_fld setEnabled: [o_eraselogo_ckb state]];
328     [o_eraselogo_mask_lbl setEnabled: [o_eraselogo_ckb state]];
329     [o_eraselogo_left_fld setEnabled: [o_eraselogo_ckb state]];
330     [o_eraselogo_left_lbl setEnabled: [o_eraselogo_ckb state]];
331     [o_eraselogo_top_fld setEnabled: [o_eraselogo_ckb state]];
332     [o_eraselogo_top_lbl setEnabled: [o_eraselogo_ckb state]];
333
334     if (psz_vfilters)
335         free(psz_vfilters);
336 }
337
338 - (void)setVideoFilter: (char *)psz_name on:(BOOL)b_on
339 {
340     char *psz_tmp;
341     vout_thread_t * p_vout = getVout();
342     if( p_vout )
343         psz_tmp = var_GetNonEmptyString( p_vout, "video-filter" );
344     else
345         psz_tmp = config_GetPsz( p_intf, "video-filter" );
346
347     if( b_on )
348     {
349         if(! psz_tmp)
350             config_PutPsz( p_intf, "video-filter", psz_name );
351         else if( (NSInteger)strstr( psz_tmp, psz_name ) == NO )
352         {
353             psz_tmp = (char *)[[NSString stringWithFormat: @"%s:%s", psz_tmp, psz_name] UTF8String];
354             config_PutPsz( p_intf, "video-filter", psz_tmp );
355         }
356     } else {
357         if( psz_tmp )
358         {
359             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithFormat:@":%s",psz_name]]] UTF8String];
360             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithFormat:@"%s:",psz_name]]] UTF8String];
361             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithUTF8String:psz_name]]] UTF8String];
362             config_PutPsz( p_intf, "video-filter", psz_tmp );
363         }
364     }
365
366     if( p_vout ) {
367         var_SetString( p_vout, "video-filter", psz_tmp );
368         vlc_object_release( p_vout );
369     }
370 }
371
372 - (void)setVideoFilterProperty: (char *)psz_name forFilter: (char *)psz_filter integer: (int)i_value
373 {
374     vout_thread_t *p_vout = getVout();
375     vlc_object_t *p_filter;
376
377     if( p_vout == NULL ) {
378         config_PutInt( p_intf , psz_name , i_value );
379     } else {
380         p_filter = vlc_object_find_name( pl_Get(p_intf), psz_filter );
381
382         if(! p_filter ) {
383             msg_Err( p_intf, "we're unable to find the filter '%s'", psz_filter );
384             vlc_object_release( p_vout );
385             return;
386         }
387         var_SetFloat( p_filter, psz_name, i_value );
388         config_PutFloat( p_intf, psz_name, i_value );
389         vlc_object_release( p_vout );
390     }
391 }
392
393 - (void)setVideoFilterProperty: (char *)psz_name forFilter: (char *)psz_filter float: (float)f_value
394 {
395     vout_thread_t *p_vout = getVout();
396     vlc_object_t *p_filter;
397
398     if( p_vout == NULL ) {
399         config_PutFloat( p_intf , psz_name , f_value );
400     } else {
401         p_filter = vlc_object_find_name( pl_Get(p_intf), psz_filter );
402
403         if(! p_filter ) {
404             msg_Err( p_intf, "we're unable to find the filter '%s'", psz_filter );
405             vlc_object_release( p_vout );
406             return;
407         }
408         var_SetFloat( p_filter, psz_name, f_value );
409         config_PutFloat( p_intf, psz_name, f_value );
410         vlc_object_release( p_vout );
411     }
412 }
413
414 - (void)setVideoFilterProperty: (char *)psz_name forFilter: (char *)psz_filter string: (char *)psz_value
415 {
416     vout_thread_t *p_vout = getVout();
417     vlc_object_t *p_filter;
418
419     if( p_vout == NULL ) {
420         config_PutPsz( p_intf, psz_name, psz_value );
421     } else {
422         p_filter = vlc_object_find_name( pl_Get(p_intf), psz_filter );
423
424         if(! p_filter ) {
425             msg_Err( p_intf, "we're unable to find the filter '%s'", psz_filter );
426             vlc_object_release( p_vout );
427             return;
428         }
429         var_SetString( p_filter, psz_name, psz_value );
430         config_PutPsz( p_intf, psz_name, psz_value );
431         vlc_object_release( p_vout );
432     }
433 }
434
435 - (void)setVideoFilterProperty: (char *)psz_name forFilter: (char *)psz_filter boolean: (BOOL)b_value
436 {
437     vout_thread_t *p_vout = getVout();
438     vlc_object_t *p_filter;
439
440     if( p_vout == NULL ) {
441         config_PutInt( p_intf, psz_name, b_value );
442     } else {
443         p_filter = vlc_object_find_name( pl_Get(p_intf), psz_filter );
444
445         if(! p_filter ) {
446             msg_Err( p_intf, "we're unable to find the filter '%s'", psz_filter );
447             vlc_object_release( p_vout );
448             return;
449         }
450         var_SetBool( p_filter, psz_name, b_value );
451         config_PutInt( p_intf, psz_name, b_value );
452         vlc_object_release( p_vout );
453     }
454 }
455
456 #pragma mark -
457 #pragma mark basic
458 - (IBAction)enableAdjust:(id)sender
459 {
460     BOOL state = [o_adjust_ckb state];
461     [self setVideoFilter: "adjust" on:[o_adjust_ckb state]];
462     [o_adjust_brightness_sld setEnabled: state];
463     [o_adjust_brightness_ckb setEnabled: state];
464     [o_adjust_brightness_lbl setEnabled: state];
465     [o_adjust_contrast_sld setEnabled: state];
466     [o_adjust_contrast_lbl setEnabled: state];
467     [o_adjust_gamma_sld setEnabled: state];
468     [o_adjust_gamma_lbl setEnabled: state];
469     [o_adjust_hue_sld setEnabled: state];
470     [o_adjust_hue_lbl setEnabled: state];
471     [o_adjust_saturation_sld setEnabled: state];
472     [o_adjust_saturation_lbl setEnabled: state];
473     [o_adjust_opaque_sld setEnabled: state];
474     [o_adjust_opaque_lbl setEnabled: state];
475 }
476
477 - (IBAction)adjustSliderChanged:(id)sender
478 {
479     if( sender == o_adjust_opaque_sld ){
480         vlc_value_t val;
481         id o_tmpWindow = [NSApp keyWindow];
482         NSArray *o_windows = [NSApp orderedWindows];
483         NSEnumerator *o_enumerator = [o_windows objectEnumerator];
484         playlist_t * p_playlist = pl_Get( p_intf );
485         vout_thread_t *p_vout = getVout();
486         vout_thread_t *p_real_vout;
487
488         val.f_float = [o_adjust_opaque_sld floatValue];
489
490         if( p_vout != NULL )
491         {
492             //FIXME: update this implementation once the vout is fixed
493             #if 0
494                 p_real_vout = [VLCVoutView realVout: p_vout];
495                 var_Set( p_real_vout, "macosx-opaqueness", val );
496
497                 while ((o_tmpWindow = [o_enumerator nextObject]))
498                 {
499                     if( [[o_tmpWindow className] isEqualToString: @"VLCVoutWindow"] ||
500                        [[[VLCMain sharedInstance] embeddedList] windowContainsEmbedded: o_tmpWindow])
501                     {
502                         [o_tmpWindow setAlphaValue: val.f_float];
503                     }
504                     break;
505                 }
506             #endif
507             vlc_object_release( p_vout );
508         }
509
510         config_PutFloat( p_playlist , "macosx-opaqueness" , val.f_float );
511     } else {
512         if( sender == o_adjust_brightness_sld )
513             [self setVideoFilterProperty: "brightness" forFilter: "adjust" float: [o_adjust_brightness_sld floatValue]];
514         else if( sender == o_adjust_contrast_sld )
515             [self setVideoFilterProperty: "contrast" forFilter: "adjust" float: [o_adjust_contrast_sld floatValue]];
516         else if( sender == o_adjust_gamma_sld )
517             [self setVideoFilterProperty: "gamma" forFilter: "adjust" float: [o_adjust_gamma_sld floatValue]];
518         else if( sender == o_adjust_hue_sld )
519             [self setVideoFilterProperty: "hue" forFilter: "adjust" integer: [o_adjust_hue_sld intValue]];
520         else if( sender == o_adjust_saturation_sld )
521             [self setVideoFilterProperty: "saturation" forFilter: "adjust" float: [o_adjust_saturation_sld floatValue]];
522     }
523 }
524
525 - (IBAction)enableAdjustBrightnessThreshold:(id)sender
526 {
527     config_PutInt( p_intf, "brightness-threshold", [o_adjust_brightness_ckb state] );
528 }
529
530 - (IBAction)enableSharpen:(id)sender
531 {
532     [self setVideoFilter: "sharpen" on: [o_sharpen_ckb state]];
533     [o_sharpen_sld setEnabled: [o_sharpen_ckb state]];
534     [o_sharpen_lbl setEnabled: [o_sharpen_ckb state]];
535 }
536
537 - (IBAction)sharpenSliderChanged:(id)sender
538 {
539     [self setVideoFilterProperty: "sharpen-sigma" forFilter: "sharpen" float: [o_sharpen_sld floatValue]];
540 }
541
542 - (IBAction)enableBanding:(id)sender
543 {
544     [self setVideoFilter: "gradfun" on: [o_banding_ckb state]];
545     [o_banding_sld setEnabled: [o_banding_ckb state]];
546     [o_banding_lbl setEnabled: [o_banding_ckb state]];
547 }
548
549 - (IBAction)bandingSliderChanged:(id)sender
550 {
551     [self setVideoFilterProperty: "gradfun-radius" forFilter: "gradfun" integer: [o_banding_sld intValue]];
552 }
553
554 - (IBAction)enableGrain:(id)sender
555 {
556     [self setVideoFilter: "grain" on: [o_grain_ckb state]];
557     [o_grain_sld setEnabled: [o_grain_ckb state]];
558     [o_grain_lbl setEnabled: [o_grain_ckb state]];
559 }
560
561 - (IBAction)grainSliderChanged:(id)sender
562 {
563     [self setVideoFilterProperty: "grain-variance" forFilter: "grain" float: [o_grain_sld floatValue]];
564 }
565
566
567 #pragma mark -
568 #pragma mark crop
569 - (IBAction)cropObjectChanged:(id)sender
570 {
571     if( [o_crop_sync_top_bottom_ckb state] )
572         [o_crop_bottom_fld setIntValue: [o_crop_top_fld intValue]];
573     if( [o_crop_sync_left_right_ckb state] )
574         [o_crop_right_fld setIntValue: [o_crop_left_fld intValue]];
575
576     vout_thread_t *p_vout = getVout();
577     if( p_vout ) {
578         var_SetInteger( p_vout, "crop-top", [o_crop_top_fld intValue] );
579         var_SetInteger( p_vout, "crop-bottom", [o_crop_bottom_fld intValue] );
580         var_SetInteger( p_vout, "crop-left", [o_crop_left_fld intValue] );
581         var_SetInteger( p_vout, "crop-right", [o_crop_right_fld intValue] );
582         vlc_object_release( p_vout );
583     }
584 }
585
586 #pragma mark -
587 #pragma mark geometry
588 - (IBAction)enableTransform:(id)sender
589 {
590     [self setVideoFilter: "transform" on: [o_transform_ckb state]];
591     [o_transform_pop setEnabled: [o_transform_ckb state]];
592 }
593
594 - (IBAction)transformModifierChanged:(id)sender
595 {
596     if( [[o_transform_pop selectedItem] tag] == 1 )
597         config_PutPsz( p_intf, "transform-type", "hflip" );
598     else if( [[o_transform_pop selectedItem] tag] == 2 )
599         config_PutPsz( p_intf, "transform-type", "vflip" );
600     else
601         config_PutPsz( p_intf, "transform-type", (char *)[o_transform_pop tag] );
602 }
603
604 - (IBAction)enableZoom:(id)sender
605 {
606     [self setVideoFilter: "magnify" on: [o_zoom_ckb state]];
607 }
608
609 - (IBAction)enablePuzzle:(id)sender
610 {
611     BOOL state = [o_puzzle_ckb state];
612     [self setVideoFilter: "puzzle" on: state];
613     [o_puzzle_columns_fld setEnabled: state];
614     [o_puzzle_columns_lbl setEnabled: state];
615     [o_puzzle_rows_fld setEnabled: state];
616     [o_puzzle_rows_lbl setEnabled: state];
617     [o_puzzle_blackslot_ckb setEnabled: state];
618 }
619
620 - (IBAction)puzzleModifierChanged:(id)sender
621 {
622     if( sender == o_puzzle_blackslot_ckb )
623         [self setVideoFilterProperty: "puzzle-black-slot" forFilter: "puzzle" boolean: [o_puzzle_blackslot_ckb state]];
624     else if( sender == o_puzzle_columns_fld )
625         [self setVideoFilterProperty: "puzzle-cols" forFilter: "puzzle" integer: [o_puzzle_columns_fld intValue]];
626     else
627         [self setVideoFilterProperty: "puzzle-rows" forFilter: "puzzle" integer: [o_puzzle_rows_fld intValue]];
628 }
629
630
631 #pragma mark -
632 #pragma mark color
633 - (IBAction)enableThreshold:(id)sender
634 {
635     BOOL state = [o_threshold_ckb state];
636     [self setVideoFilter: "colorthres" on: state];
637     [o_threshold_color_fld setEnabled: state];
638     [o_threshold_color_lbl setEnabled: state];
639     [o_threshold_saturation_sld setEnabled: state];
640     [o_threshold_saturation_lbl setEnabled: state];
641     [o_threshold_similarity_sld setEnabled: state];
642     [o_threshold_similarity_lbl setEnabled: state];
643 }
644
645 - (IBAction)thresholdModifierChanged:(id)sender
646 {
647     if( sender == o_threshold_color_fld )
648         [self setVideoFilterProperty: "colorthres-color" forFilter: "colorthres" integer: [o_threshold_color_fld intValue]];
649     else if( sender == o_threshold_saturation_sld )
650         [self setVideoFilterProperty: "colorthres-saturationthres" forFilter: "colorthres" integer: [o_threshold_saturation_sld intValue]];
651     else
652         [self setVideoFilterProperty: "colorthres-similaritythres" forFilter: "colorthres" integer: [o_threshold_similarity_sld intValue]];
653 }
654
655 - (IBAction)enableSepia:(id)sender
656 {
657     [self setVideoFilter: "sepia" on: [o_sepia_ckb state]];
658     [o_sepia_fld setEnabled: [o_sepia_ckb state]];
659     [o_sepia_lbl setEnabled: [o_sepia_ckb state]];
660 }
661
662 - (IBAction)sepiaModifierChanged:(id)sender
663 {
664     [self setVideoFilterProperty: "sepia-intensity" forFilter: "sepia" integer: [o_sepia_fld intValue]];
665 }
666
667 - (IBAction)enableNoise:(id)sender
668 {
669     [self setVideoFilter: "noise" on: [o_noise_ckb state]];
670 }
671
672 - (IBAction)enableGradient:(id)sender
673 {
674     BOOL state = [o_gradient_ckb state];
675     [self setVideoFilter: "gradient" on: state];
676     [o_gradient_mode_pop setEnabled: state];
677     [o_gradient_mode_lbl setEnabled: state];
678     [o_gradient_color_ckb setEnabled: state];
679     [o_gradient_cartoon_ckb setEnabled: state];
680 }
681
682 - (IBAction)gradientModifierChanged:(id)sender
683 {
684     if( sender == o_gradient_mode_pop ) {
685         if( [[o_gradient_mode_pop selectedItem] tag] == 3 )
686             [self setVideoFilterProperty: "gradient-mode" forFilter: "gradient" string: "hough"];
687         else if( [[o_gradient_mode_pop selectedItem] tag] == 2 )
688             [self setVideoFilterProperty: "gradient-mode" forFilter: "gradient" string: "edge"];
689         else
690             [self setVideoFilterProperty: "gradient-mode" forFilter: "gradient" string: "gradient"];
691     }
692     else if( sender == o_gradient_color_ckb )
693         [self setVideoFilterProperty: "gradient-type" forFilter: "gradient" integer: [o_gradient_color_ckb state]];
694     else
695         [self setVideoFilterProperty: "gradient-cartoon" forFilter: "gradient" boolean: [o_gradient_cartoon_ckb state]];
696 }
697
698 - (IBAction)enableExtract:(id)sender
699 {
700     [self setVideoFilter: "extract" on: [o_extract_ckb state]];
701     [o_extract_fld setEnabled: [o_extract_ckb state]];
702     [o_extract_lbl setEnabled: [o_extract_ckb state]];
703 }
704
705 - (IBAction)extractModifierChanged:(id)sender
706 {
707     [self setVideoFilterProperty: "extract-component" forFilter: "extract" integer: [o_extract_fld intValue]];  
708 }
709
710 - (IBAction)enableInvert:(id)sender
711 {
712     [self setVideoFilter: "invert" on: [o_invert_ckb state]];
713 }
714
715 - (IBAction)enablePosterize:(id)sender
716 {
717     [self setVideoFilter: "posterize" on: [o_posterize_ckb state]];
718     [o_posterize_fld setEnabled: [o_posterize_ckb state]];
719     [o_posterize_lbl setEnabled: [o_posterize_ckb state]];
720 }
721
722 - (IBAction)posterizeModifierChanged:(id)sender
723 {
724     [self setVideoFilterProperty: "posterize-level" forFilter: "posterize" integer: [o_extract_fld intValue]];
725 }
726
727 - (IBAction)enableBlur:(id)sender
728 {
729     [self setVideoFilter: "motionblur" on: [o_blur_ckb state]];
730     [o_blur_sld setEnabled: [o_blur_ckb state]];
731     [o_blur_lbl setEnabled: [o_blur_ckb state]];
732 }
733
734 - (IBAction)blurModifierChanged:(id)sender
735 {
736     [self setVideoFilterProperty: "blur-factor" forFilter: "motionblur" integer: [o_blur_sld intValue]];
737 }
738
739 - (IBAction)enableMotionDetect:(id)sender
740 {
741     [self setVideoFilter: "motiondetect" on: [o_motiondetect_ckb state]];
742 }
743
744 - (IBAction)enableWaterEffect:(id)sender
745 {
746     [self setVideoFilter: "ripple" on: [o_watereffect_ckb state]];
747 }
748
749 - (IBAction)enableWaves:(id)sender
750 {
751     [self setVideoFilter: "wave" on: [o_waves_ckb state]];
752 }
753
754 - (IBAction)enablePsychedelic:(id)sender
755 {
756     [self setVideoFilter: "psychedelic" on: [o_psychedelic_ckb state]];
757 }
758
759
760 #pragma mark -
761 #pragma mark video output & overlay
762 - (IBAction)enableClone:(id)sender
763 {
764     msg_Dbg( p_intf, "not yet implemented" );
765 }
766
767 - (IBAction)cloneModifierChanged:(id)sender
768 {
769     msg_Dbg( p_intf, "not yet implemented" );
770 }
771
772 - (IBAction)enableAddText:(id)sender
773 {
774     msg_Dbg( p_intf, "not yet implemented" );
775 }
776
777 - (IBAction)addTextModifierChanged:(id)sender
778 {
779     msg_Dbg( p_intf, "not yet implemented" );
780 }
781
782
783 #pragma mark -
784 #pragma mark logo
785 - (IBAction)enableAddLogo:(id)sender
786 {
787     msg_Dbg( p_intf, "not yet implemented" );
788 }
789
790 - (IBAction)addLogoModifierChanged:(id)sender
791 {
792     msg_Dbg( p_intf, "not yet implemented" );
793 }
794
795 - (IBAction)enableEraseLogo:(id)sender
796 {
797     msg_Dbg( p_intf, "not yet implemented" );
798 }
799
800 - (IBAction)eraseLogoModifierChanged:(id)sender
801 {
802     msg_Dbg( p_intf, "not yet implemented" );
803 }
804
805
806 @end