OSDN Git Service

MacGui: Custom Anamorphic
[handbrake-jp/handbrake-jp-git.git] / macosx / PictureController.mm
1 /* $Id: PictureController.mm,v 1.11 2005/08/01 15:10:44 titer Exp $
2
3    This file is part of the HandBrake source code.
4    Homepage: <http://handbrake.fr/>.
5    It may be used under the terms of the GNU General Public License. */
6
7 #import "PictureController.h"
8 #import "Controller.h"
9 #import "HBPreviewController.h"
10
11
12
13 @implementation PictureController
14
15 - (id)init
16 {
17         if (self = [super initWithWindowNibName:@"PictureSettings"])
18         {
19         // NSWindowController likes to lazily load its window. However since
20         // this controller tries to set all sorts of outlets before the window
21         // is displayed, we need it to load immediately. The correct way to do
22         // this, according to the documentation, is simply to invoke the window
23         // getter once.
24         //
25         // If/when we switch a lot of this stuff to bindings, this can probably
26         // go away.
27         [self window];
28         
29         fPreviewController = [[PreviewController alloc] init];
30     }
31         return self;
32 }
33
34 //------------------------------------------------------------------------------------
35 // Displays and brings the picture window to the front
36 //------------------------------------------------------------------------------------
37 - (IBAction) showPictureWindow: (id)sender
38 {
39     if ([fPreviewController fullScreen] == YES)
40     {
41         [self showWindow:sender];
42         [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"PictureSizeWindowIsOpen"];
43         [self setToFullScreenMode];
44     }
45     else
46     {
47         if ([[self window] isVisible])
48         {
49             [[self window] close];
50         }
51         else
52         {
53             [self showWindow:sender];
54             [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"PictureSizeWindowIsOpen"];
55             [self setToWindowedMode];
56         }
57     }
58     [self adjustFilterDisplay:nil];
59     [self adjustSizingDisplay:nil];
60 }
61
62 - (BOOL) previewFullScreenMode
63 {
64     return [fPreviewController fullScreen];
65 }
66
67 /* this method is used to detect clicking on a tab in fSizeFilterView */
68 - (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
69 {
70
71 [self resizeInspectorForTab:nil];
72
73 }
74
75 #pragma mark -
76
77 /* resizeInspectorForTab is called at launch, and each time either the 
78  * Size or Filters tab is clicked. Size gives a horizontally oriented
79  * inspector and Filters is a vertically aligned inspector.
80  */
81 - (IBAction) resizeInspectorForTab: (id)sender
82 {
83     NSRect frame = [[self window] frame];
84     NSPoint windowOrigin = [[self window] frame].origin;
85     NSSize screenSize = [[[self window] screen] frame].size;
86     NSPoint screenOrigin = [[[self window] screen] frame].origin;
87     
88     /* We base our inspector size/layout on which tab is active for fSizeFilterView */
89     /* we are 1 which is Filters*/
90     if ([fSizeFilterView indexOfTabViewItem: [fSizeFilterView selectedTabViewItem]] == 1)
91     {
92         frame.size.width = 314;
93         /* we glean the height from the size of the boxes plus the extra window space
94          * needed for non boxed display
95          */
96         frame.size.height = 110.0 + [fDetelecineBox frame].size.height + [fDecombDeinterlaceBox frame].size.height + [fDenoiseBox frame].size.height + [fDeblockBox frame].size.height;
97         /* Hide the size readout at the bottom as the vertical inspector is not wide enough */
98         [fSizeInfoField setHidden:YES];
99     }
100     else // we are Tab index 0 which is size
101     {
102         frame.size.width = 50.0 + [fPictureSizeBox frame].size.width + [fPictureCropBox frame].size.width;
103         frame.size.height = [fPictureSizeBox frame].size.height + 85;
104         /* hide the size summary field at the bottom */
105         [fSizeInfoField setHidden:NO];      
106     }
107     /* get delta's for the change in window size */
108     CGFloat deltaX = frame.size.width - [[self window] frame].size.width;
109     CGFloat deltaY = frame.size.height - [[self window] frame].size.height;
110     
111     /* Check to see if we have changed the height from current */
112     //if (frame.size.height != [[self window] frame].size.height)
113     //{
114         /* change the inspector origin via the deltaY */
115         frame.origin.y -= deltaY;
116         /* keep the inspector centered so the tabs stay in place */
117         frame.origin.x -= deltaX / 2.0;
118     //}
119     
120      /* we make sure we are not horizontally off of our screen.
121      * this would be the case if we are on the vertical filter tab
122      * and we hit the size tab and the inspector grows horizontally
123      * off the screen to the right
124     */
125     if ((frame.origin.x + frame.size.width) > (screenOrigin.x + screenSize.width))
126     {
127         /* the right side of the preview is off the screen, so shift to the left */
128         frame.origin.x = (screenOrigin.x + screenSize.width) - frame.size.width;
129     }
130     
131     [[self window] setFrame:frame display:YES animate:YES];
132 }
133
134 - (IBAction) adjustSizingDisplay: (id) sender
135 {
136     NSSize pictureSizingBoxSize = [fPictureSizeBox frame].size;
137     
138     NSPoint fPictureSizeBoxOrigin = [fPictureSizeBox frame].origin;
139     NSSize pictureCropBoxSize = [fPictureCropBox frame].size;
140     NSPoint fPictureCropBoxOrigin = [fPictureCropBox frame].origin;
141     
142     if ([fAnamorphicPopUp indexOfSelectedItem] == 3) // custom / power user jamboree
143     {
144         pictureSizingBoxSize.width = 530;
145         
146         /* Set visibility of capuj widgets */
147         [fParWidthField setHidden: NO];
148         [fParHeightField setHidden: NO];
149         [fParWidthLabel setHidden: NO];
150         [fParHeightLabel setHidden: NO];
151         [fDisplayWidthField setHidden: NO];
152         [fDisplayWidthLabel setHidden: NO];
153         [fModulusLabel setHidden: NO];
154         [fModulusPopUp setHidden: NO];
155         /* adjust/move keep ar checkbox */
156         [fRatioLabel setHidden: YES];
157         [fRatioLabel2 setHidden: NO];
158         
159         /* Optionally swith the Storage and Display width positions*/
160          /*
161          NSPoint fWidthLabelOrigin = [fWidthLabel frame].origin;
162          NSPoint fWidthFieldOrigin = [fWidthField frame].origin;
163          NSPoint fWidthStepperOrigin = [fWidthStepper frame].origin;
164          fWidthFieldOrigin.x = [fRatioLabel2 frame].origin.x + [fRatioLabel2 frame].size.width + 4;
165          [fWidthField setFrameOrigin:fWidthFieldOrigin];
166
167          fWidthStepperOrigin.x = [fWidthField frame].origin.x + [fWidthField frame].size.width + 4;
168          [fWidthStepper setFrameOrigin:fWidthStepperOrigin];
169          
170          fWidthLabelOrigin.x = [fWidthField frame].origin.x - [fWidthLabel frame].size.width - 4;
171          [fWidthLabel setFrameOrigin:fWidthLabelOrigin];
172          [fWidthLabel setStringValue:@"Storage Width:"];
173          */
174         
175         /* set the origin for fRatioCheck so origin.y == fRatioLabel2
176          * and origin.x == fDisplayWidthField
177          */
178          NSPoint fRatioCheckOrigin = [fRatioCheck frame].origin;
179          fRatioCheckOrigin.y = [fRatioLabel2 frame].origin.y - 2;
180          fRatioCheckOrigin.x = [fRatioLabel2 frame].origin.x + [fRatioLabel2 frame].size.width + 4;
181          [fRatioCheck setFrameOrigin:fRatioCheckOrigin];
182          
183     }
184     else
185     {
186         pictureSizingBoxSize.width = 200;
187         
188         /* Set visibility of capuj widgets */
189         [fParWidthField setHidden: YES];
190         [fParHeightField setHidden: YES];
191         [fParWidthLabel setHidden: YES];
192         [fParHeightLabel setHidden: YES];
193         [fDisplayWidthField setHidden: YES];
194         [fDisplayWidthLabel setHidden: YES];
195         [fModulusLabel setHidden: YES];
196         [fModulusPopUp setHidden: YES];
197         /* adjust/move keep ar checkbox */
198         [fRatioLabel setHidden: NO];
199         [fRatioLabel2 setHidden: YES];
200         
201          /* Optionally swith the Storage and Display width positions*/
202          
203          /*
204          NSPoint fWidthLabelOrigin = [fWidthLabel frame].origin;
205          NSPoint fWidthFieldOrigin = [fWidthField frame].origin;
206          NSPoint fWidthStepperOrigin = [fWidthStepper frame].origin;
207          
208          fWidthFieldOrigin.x = [fHeightField frame].origin.x;
209          [fWidthField setFrameOrigin:fWidthFieldOrigin];
210          
211          fWidthStepperOrigin.x = [fHeightStepper frame].origin.x;
212          [fWidthStepper setFrameOrigin:fWidthStepperOrigin];
213          
214          fWidthLabelOrigin.x = [fWidthField frame].origin.x - [fWidthLabel frame].size.width -4;
215          [fWidthLabel setFrameOrigin:fWidthLabelOrigin];
216          [fWidthLabel setStringValue:@"Width:"];
217          */
218         
219         
220         /* set the origin for fRatioCheck so origin.y == fRatioLabel
221          * and origin.x == fWidthStepper
222          */
223          NSPoint fRatioCheckOrigin = [fRatioCheck frame].origin;
224          fRatioCheckOrigin.y = [fRatioLabel frame].origin.y - 2;
225          fRatioCheckOrigin.x = [fWidthStepper frame].origin.x - 2;
226          [fRatioCheck setFrameOrigin:fRatioCheckOrigin];
227         
228     }
229     
230     /* Check to see if we have changed the size from current */
231     if (pictureSizingBoxSize.height != [fPictureSizeBox frame].size.height || pictureSizingBoxSize.width != [fPictureSizeBox frame].size.width)
232     {
233         /* Get our delta for the change in picture size box height */
234         CGFloat deltaYSizeBoxShift = pictureSizingBoxSize.height - [fPictureSizeBox frame].size.height;
235         fPictureSizeBoxOrigin.y -= deltaYSizeBoxShift;
236         /* Get our delta for the change in picture size box width */
237         CGFloat deltaXSizeBoxShift = pictureSizingBoxSize.width - [fPictureSizeBox frame].size.width;
238         //fPictureSizeBoxOrigin.x += deltaXSizeBoxShift;
239         /* set our new Picture size box size */
240         [fPictureSizeBox setFrameSize:pictureSizingBoxSize];
241         [fPictureSizeBox setFrameOrigin:fPictureSizeBoxOrigin];
242         
243         pictureCropBoxSize.height += deltaYSizeBoxShift;
244         fPictureCropBoxOrigin.y -= deltaYSizeBoxShift;
245         fPictureCropBoxOrigin.x += deltaXSizeBoxShift;
246         
247         [fPictureCropBox setFrameSize:pictureCropBoxSize];
248         [[fPictureCropBox animator] setFrameOrigin:fPictureCropBoxOrigin];
249     }
250
251     
252     /* now we call to resize the entire inspector window */
253    [self resizeInspectorForTab:nil];
254 }
255
256 - (IBAction) adjustFilterDisplay: (id) sender
257 {
258     
259     NSBox * filterBox = nil;
260     NSTextField * filterField;
261     if (sender == fDetelecinePopUp)
262     {
263         filterBox = fDetelecineBox;
264         filterField = fDetelecineField;
265     }
266     
267     if (sender == fDecombDeinterlaceSlider)
268     {
269         if ([fDecombDeinterlaceSlider floatValue] == 0.0)
270         {
271             filterBox = fDecombBox;
272             filterField = fDecombField;
273         }
274         else
275         {
276             filterBox = fDeinterlaceBox;
277             filterField = fDeinterlaceField;
278         }
279     }
280     
281     if (sender == fDecombPopUp)
282     {
283         filterBox = fDecombBox;
284         filterField = fDecombField;
285     }
286     if (sender == fDeinterlacePopUp)
287     {
288         filterBox = fDeinterlaceBox;
289         filterField = fDeinterlaceField;
290     }
291     
292     if (sender == fDenoisePopUp)
293     {
294         filterBox = fDenoiseBox;
295         filterField = fDenoiseField;
296     }
297     
298     NSSize currentSize = [filterBox frame].size;
299     NSRect boxFrame = [filterBox frame];
300     
301     if ([sender titleOfSelectedItem] == @"Custom")
302     {
303         
304         currentSize.height = 60;
305         
306     }
307     else
308     {
309         currentSize.height = 30;
310         
311     }
312     /* Check to see if we have changed the size from current */
313     if (currentSize.height != [filterBox frame].size.height)
314     {
315         /* We are changing the size of the box, so recalc the origin */
316         NSPoint boxOrigin = [filterBox frame].origin;
317         /* We get the deltaY here for how much we are expanding/contracting the box vertically */
318         CGFloat deltaYBoxShift = currentSize.height - [filterBox frame].size.height;
319         boxOrigin.y -= deltaYBoxShift;
320         
321         boxFrame.size.height = currentSize.height;
322         boxFrame.origin.y = boxOrigin.y;
323         [filterBox setFrame:boxFrame];
324         
325         /* go ahead and resize the box */
326         //[[filterBox animator] setFrameSize:currentSize];
327         //[[filterBox animator] setFrameOrigin:origin];
328  
329     
330         if (filterBox == fDecombBox || filterBox == fDeinterlaceBox)
331         {
332             /* fDecombDeinterlaceBox*/
333             NSSize decombDeinterlaceBoxSize = [fDecombDeinterlaceBox frame].size;
334             NSPoint decombDeinterlaceBoxOrigin = [fDecombDeinterlaceBox frame].origin;
335             
336             //decombDeinterlaceBoxSize.height = [filterBox frame].size.height + 50;
337             if (sender == fDecombDeinterlaceSlider)
338             {
339                 [fHBController writeToActivityLog: "Sender is deinterlace decomb slider"];
340             }
341             
342             if ([fDeinterlaceBox isHidden] == YES)
343             {
344                 decombDeinterlaceBoxSize.height = [fDecombBox frame].size.height + 50;
345                 [fHBController writeToActivityLog: "Resize by Decomb box"];
346             }
347             else
348             {
349                 decombDeinterlaceBoxSize.height = [fDeinterlaceBox frame].size.height + 50;
350                 [fHBController writeToActivityLog: "Resize by Deinterlace box"];
351             }
352             /* get delta's for the change in window size */
353             
354             CGFloat deltaYdecombDeinterlace = decombDeinterlaceBoxSize.height - [fDecombDeinterlaceBox frame].size.height;
355             
356             deltaYBoxShift = deltaYdecombDeinterlace;
357             
358             decombDeinterlaceBoxOrigin.y -= deltaYdecombDeinterlace;
359             
360             [fDecombDeinterlaceBox setFrameSize:decombDeinterlaceBoxSize];
361             [fDecombDeinterlaceBox setFrameOrigin:decombDeinterlaceBoxOrigin];
362         }
363
364         /* now we must reset the origin of each box below the adjusted box*/
365         NSPoint decombDeintOrigin = [fDecombDeinterlaceBox frame].origin;
366         NSPoint denoiseOrigin = [fDenoiseBox frame].origin;
367         NSPoint deblockOrigin = [fDeblockBox frame].origin;
368         if (sender == fDetelecinePopUp)
369         {
370             decombDeintOrigin.y -= deltaYBoxShift;
371             [fDecombDeinterlaceBox setFrameOrigin:decombDeintOrigin];
372             
373             denoiseOrigin.y -= deltaYBoxShift;
374             [fDenoiseBox setFrameOrigin:denoiseOrigin];
375             
376             deblockOrigin.y -= deltaYBoxShift;
377             [fDeblockBox setFrameOrigin:deblockOrigin];
378         }
379         if (sender == fDecombPopUp || sender == fDeinterlacePopUp)
380         {
381             denoiseOrigin.y -= deltaYBoxShift;
382             [fDenoiseBox setFrameOrigin:denoiseOrigin];
383             
384             deblockOrigin.y -= deltaYBoxShift;
385             [fDeblockBox setFrameOrigin:deblockOrigin];
386         }
387         
388         if (sender == fDenoisePopUp)
389         {
390             deblockOrigin.y -= deltaYBoxShift;
391             [fDeblockBox setFrameOrigin:deblockOrigin];
392         }
393         
394         /* now we call to resize the entire inspector window */
395         [self resizeInspectorForTab:nil];
396     }
397     
398 }
399
400
401 #pragma mark -
402
403 - (IBAction) previewGoWindowed: (id)sender
404 {
405     [fPreviewController goWindowedScreen:self];
406 }
407
408 - (IBAction) showPreviewWindow: (id)sender
409 {
410     [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"PreviewWindowIsOpen"];
411     [fPreviewController showWindow:sender];
412 }
413
414
415
416
417 - (void) setToFullScreenMode
418 {
419     int32_t shieldLevel = CGShieldingWindowLevel(); 
420     
421     [fPictureWindow setLevel:shieldLevel + 1]; 
422     // Show the window. 
423     [fPictureWindow makeKeyAndOrderFront:self];
424 }
425
426 - (void) setToWindowedMode
427 {
428     /* Set the window back to Floating Window mode 
429      * This will put the window always on top, but
430      * since we have Hide on Deactivate set in our
431      * xib, if other apps are put in focus we will
432      * hide properly to stay out of the way
433      */
434     [[self window] setLevel:NSFloatingWindowLevel];
435 }
436
437 - (void)setHBController: (HBController *)controller
438 {
439     fHBController = controller;
440     [fPreviewController   setHBController: controller];
441     
442 }
443
444 - (void)awakeFromNib
445 {
446     [fPictureWindow setDelegate:self];
447     if( ![[self window] setFrameUsingName:@"PictureSizing"] )
448         [[self window] center];
449     [self setWindowFrameAutosaveName:@"PictureSizing"];
450     [[self window] setExcludedFromWindowsMenu:YES];
451     
452     [self setInitialPictureFilters];
453     
454     /* Setup our layers for core animation */
455     [fSizeFilterView setWantsLayer:YES];
456     [fPictureSizeBox setWantsLayer:YES];
457     [fPictureCropBox setWantsLayer:YES];
458     
459 }
460
461
462 - (void)windowWillClose:(NSNotification *)aNotification
463 {
464 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"PictureSizeWindowIsOpen"];
465 }
466
467 - (BOOL)windowShouldClose:(id)fPictureWindow
468 {
469     return YES;
470 }
471
472 - (void) dealloc
473 {
474     [fPreviewController release];
475     [super dealloc];
476 }
477
478 - (void) SetHandle: (hb_handle_t *) handle
479 {
480     fHandle = handle;
481     
482     [fPreviewController SetHandle: fHandle];
483 }
484
485 - (void) SetTitle: (hb_title_t *) title
486 {
487     hb_job_t * job = title->job;
488
489     fTitle = title;
490     
491      modulus = 8; //modulus value of 16, 8 or 4
492     [fWidthStepper  setValueWraps: NO];
493     [fWidthStepper  setIncrement: [[fModulusPopUp titleOfSelectedItem] intValue]];
494     [fWidthStepper  setMinValue: 64];
495     [fHeightStepper setValueWraps: NO];
496     [fHeightStepper setIncrement: [[fModulusPopUp titleOfSelectedItem] intValue]];
497     [fHeightStepper setMinValue: 64];
498     
499     [fCropTopStepper    setIncrement: 2];
500     [fCropTopStepper    setMinValue:  0];
501     [fCropBottomStepper setIncrement: 2];
502     [fCropBottomStepper setMinValue:  0];
503     [fCropLeftStepper   setIncrement: 2];
504     [fCropLeftStepper   setMinValue:  0];
505     [fCropRightStepper  setIncrement: 2];
506     [fCropRightStepper  setMinValue:  0];
507     
508     [fWidthStepper      setMaxValue: title->width];
509     [fWidthStepper      setIntValue: job->width];
510     [fWidthField        setIntValue: job->width];
511     [fHeightStepper     setMaxValue: title->height];
512     [fHeightStepper     setIntValue: job->height];
513     [fHeightField       setIntValue: job->height];
514     [fRatioCheck        setState:    job->keep_ratio ? NSOnState : NSOffState];
515     [fCropTopStepper    setMaxValue: title->height/2-2];
516     [fCropBottomStepper setMaxValue: title->height/2-2];
517     [fCropLeftStepper   setMaxValue: title->width/2-2];
518     [fCropRightStepper  setMaxValue: title->width/2-2];
519
520     /* Populate the Anamorphic NSPopUp button here */
521     [fAnamorphicPopUp removeAllItems];
522     [fAnamorphicPopUp addItemWithTitle: @"None"];
523     [fAnamorphicPopUp addItemWithTitle: @"Strict"];
524     if (allowLooseAnamorphic)
525     {
526     [fAnamorphicPopUp addItemWithTitle: @"Loose"];
527     }
528     [fAnamorphicPopUp addItemWithTitle: @"Custom"];
529     [fAnamorphicPopUp selectItemAtIndex: job->anamorphic.mode];
530     
531     //[self adjustSizingDisplay:nil];
532     
533     /* populate the modulus popup here */
534     [fModulusPopUp removeAllItems];
535     [fModulusPopUp addItemWithTitle: @"16"];
536     [fModulusPopUp addItemWithTitle: @"8"];
537     [fModulusPopUp addItemWithTitle: @"4"];
538     [fModulusPopUp addItemWithTitle: @"2"];
539     if (job->anamorphic.mode == 3)
540     {
541         [fModulusPopUp selectItemWithTitle: [NSString stringWithFormat:@"%d",job->anamorphic.modulus]];
542     }
543     else
544     {
545         [fModulusPopUp selectItemWithTitle: @"16"];
546     }
547     
548     /* We initially set the previous state of keep ar to on */
549     keepAspectRatioPreviousState = 1;
550         if (!autoCrop)
551         {
552         [fCropMatrix  selectCellAtRow: 1 column:0];
553         /* If auto, lets set the crop steppers according to current job->crop values */
554         [fCropTopStepper    setIntValue: job->crop[0]];
555         [fCropTopField      setIntValue: job->crop[0]];
556         [fCropBottomStepper setIntValue: job->crop[1]];
557         [fCropBottomField   setIntValue: job->crop[1]];
558         [fCropLeftStepper   setIntValue: job->crop[2]];
559         [fCropLeftField     setIntValue: job->crop[2]];
560         [fCropRightStepper  setIntValue: job->crop[3]];
561         [fCropRightField    setIntValue: job->crop[3]];
562         }
563         else
564         {
565         [fCropMatrix  selectCellAtRow: 0 column:0];
566         }
567         
568     /* Set filters widgets according to the filters struct */
569     [fDetelecinePopUp selectItemAtIndex:fPictureFilterSettings.detelecine];
570     [fDecombPopUp selectItemAtIndex:fPictureFilterSettings.decomb];
571     [fDeinterlacePopUp selectItemAtIndex: fPictureFilterSettings.deinterlace];
572     [fDenoisePopUp selectItemAtIndex: fPictureFilterSettings.denoise];
573     [fDeblockSlider setFloatValue:fPictureFilterSettings.deblock];
574     [fGrayscaleCheck setState:fPictureFilterSettings.grayscale];
575     
576     [self deblockSliderChanged: nil];
577     
578     fPicture = 0;
579     MaxOutputWidth = title->width - job->crop[2] - job->crop[3];
580     MaxOutputHeight = title->height - job->crop[0] - job->crop[1];
581     
582     titleDarWidth = job->anamorphic.dar_width;
583     titleDarHeight = job->anamorphic.dar_height;
584     
585     titleParWidth = job->anamorphic.par_width;
586     titleParHeight = job->anamorphic.par_height;
587     
588     [self SettingsChanged: nil];
589 }
590
591 - (IBAction) storageLinkChanged: (id) sender
592 {
593     /* since we have a tickless slider, make sure we are at 0.0 or 1.0 */
594     if ([fStorageLinkSlider floatValue] < 0.50)
595     {
596         [fStorageLinkSlider setFloatValue:0.0];
597         /* set slider labels to reflect choice */
598         [fStorageLinkParLabel setEnabled:YES];
599         [fStorageLinkDisplayLabel setEnabled:NO];
600
601     }
602     else
603     {
604         [fStorageLinkSlider setFloatValue:1.0];
605         /* set slider labels to reflect choice */
606         [fStorageLinkParLabel setEnabled:NO];
607         [fStorageLinkDisplayLabel setEnabled:YES];
608     }
609     
610 }
611
612 - (IBAction) parLinkChanged: (id) sender
613 {
614     /* since we have a tickless slider, make sure we are at 0.0 or 1.0 */
615     if ([fParLinkSlider floatValue] < 0.50)
616     {
617         [fParLinkSlider setFloatValue:0.0];
618         /* set slider labels to reflect choice */
619         [fParLinkStorageLabel setEnabled:YES];
620         [fParLinkDisplayLabel setEnabled:NO];
621     }
622     else
623     {
624         [fParLinkSlider setFloatValue:1.0];
625         /* set slider labels to reflect choice */
626         [fParLinkStorageLabel setEnabled:NO];
627         [fParLinkDisplayLabel setEnabled:YES];
628     }
629     
630 }
631
632 - (IBAction) displayLinkChanged: (id) sender
633 {
634     /* since we have a tickless slider, make sure we are at 0.0 or 1.0 */
635     if ([fDisplayLinkSlider floatValue] < 0.50)
636     {
637         [fDisplayLinkSlider setFloatValue:0.0];
638         /* set slider labels to reflect choice */
639         [fDisplayLinkStorageLabel setEnabled:YES];
640         [fDisplayLinkParLabel setEnabled:NO];
641     }
642     else
643     {
644         [fDisplayLinkSlider setFloatValue:1.0];
645         /* set slider labels to reflect choice */
646         [fDisplayLinkStorageLabel setEnabled:NO];
647         [fDisplayLinkParLabel setEnabled:YES];
648     }
649     
650 }    
651
652 - (IBAction) SettingsChanged: (id) sender
653 {
654     hb_job_t * job = fTitle->job;
655     
656     [fWidthStepper  setIncrement: [[fModulusPopUp titleOfSelectedItem] intValue]];
657     [fHeightStepper setIncrement: [[fModulusPopUp titleOfSelectedItem] intValue]];
658     /* Since custom anamorphic allows for a height setting > fTitle->height
659      * check to make sure it is returned to fTitle->height for all other modes
660      */
661      [fHeightStepper setMaxValue: fTitle->height];
662     
663     autoCrop = ( [fCropMatrix selectedRow] == 0 );
664     [fCropTopStepper    setEnabled: !autoCrop];
665     [fCropBottomStepper setEnabled: !autoCrop];
666     [fCropLeftStepper   setEnabled: !autoCrop];
667     [fCropRightStepper  setEnabled: !autoCrop];
668     
669     if( autoCrop )
670     {
671         memcpy( job->crop, fTitle->crop, 4 * sizeof( int ) );
672     }
673     else
674     {
675         job->crop[0] = [fCropTopStepper    intValue];
676         job->crop[1] = [fCropBottomStepper intValue];
677         job->crop[2] = [fCropLeftStepper   intValue];
678         job->crop[3] = [fCropRightStepper  intValue];
679     }
680     /* Initially we set modulus widgets to 16 and disabled since we
681      * only use it for Custom Anamorphic below
682      */
683     [fModulusPopUp setEnabled:NO];
684     job->anamorphic.modulus = 16;
685     
686     [fRatioCheck setEnabled: YES];
687
688     
689     [fParWidthField setEnabled: NO];
690     [fParHeightField setEnabled: NO];
691     [fDisplayWidthField setEnabled: NO];
692     
693     /* If we are not custom anamorphic, make sure we retain the orginal par */
694     if( [fAnamorphicPopUp indexOfSelectedItem] != 3 )
695         {
696         job->anamorphic.par_width = titleParWidth;
697         job->anamorphic.par_height = titleParHeight;
698         [fRatioLabel setHidden: NO];
699     }
700     
701         if( [fAnamorphicPopUp indexOfSelectedItem] > 0 )
702         {
703         if ([fAnamorphicPopUp indexOfSelectedItem] == 1) // strict
704         {
705             [fWidthStepper      setIntValue: fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3]];
706             [fWidthField        setIntValue: fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3]];
707             
708             /* This will show correct anamorphic height values, but
709              show distorted preview picture ratio */
710             [fHeightStepper      setIntValue: fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1]];
711             [fHeightField        setIntValue: fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1]];
712             job->width       = [fWidthStepper  intValue];
713             job->height      = [fHeightStepper intValue];
714             
715             job->anamorphic.mode = 1;
716             [fWidthStepper setEnabled: NO];
717             [fWidthField setEnabled: NO];
718             [fHeightStepper setEnabled: NO];
719             [fHeightField setEnabled: NO];
720         }
721         else if ([fAnamorphicPopUp indexOfSelectedItem] == 2) // Loose anamorphic
722         {
723             job->anamorphic.mode = 2;
724             [fWidthStepper setEnabled: YES];
725             [fWidthField setEnabled: YES];
726             [fRatioCheck setEnabled: NO];
727             [fHeightStepper setEnabled: NO];
728             [fHeightField setEnabled: NO];
729             /* We set job->width and call hb_set_anamorphic_size in libhb to do a "dry run" to get
730              * the values to be used by libhb for loose anamorphic
731              */
732             /* if the sender is the anamorphic popup, then we know that loose anamorphic has just
733              * been turned on, so snap the width to full width for the source.
734              */
735             if (sender == fAnamorphicPopUp)
736             {
737                 [fWidthStepper      setIntValue: fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3]];
738                 [fWidthField        setIntValue: fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3]];
739             }
740             job->width       = [fWidthStepper  intValue];
741             hb_set_anamorphic_size(job, &output_width, &output_height, &output_par_width, &output_par_height);
742             [fHeightStepper      setIntValue: output_height];
743             [fHeightField        setIntValue: output_height];
744             job->height      = [fHeightStepper intValue];
745             
746         }
747         else if ([fAnamorphicPopUp indexOfSelectedItem] == 3) // custom / power user jamboree
748         {
749
750 #pragma mark - STARTCapuj
751
752             job->anamorphic.mode = 3;
753             
754             /* Set the status of our custom ana only widgets accordingly */
755             /* for mod 3 we can use modulus other than 16 */
756             [fModulusPopUp setEnabled:YES];
757             job->anamorphic.modulus = [[fModulusPopUp titleOfSelectedItem] intValue];
758             
759             [fWidthStepper setEnabled: YES];
760             [fWidthField setEnabled: YES];
761             
762             [fHeightStepper setEnabled: YES];
763             /* for capuj the storage field is immaterial */
764             [fHeightField setEnabled: YES];
765             
766             [fRatioCheck setEnabled: YES];
767             if (sender == fRatioCheck)
768             {
769                 if ([fRatioCheck  state] == NSOnState)
770                 {
771                     [fParWidthField setEnabled: NO];
772                     [fParHeightField setEnabled: NO];   
773                 }
774                 else
775                 {
776                     [fParWidthField setEnabled: YES];
777                     [fParHeightField setEnabled: YES];
778                 }
779             }
780             
781             [fParWidthField setEnabled: YES];
782             [fParHeightField setEnabled: YES];
783             
784             [fDisplayWidthField setEnabled: YES];
785             
786             
787             /* If we are coming into custom ana or if in custom ana and the 
788              * keep ar checkbox is checked, we reset the par to original
789              * which gives us a way back if things are hosed up
790              */
791              
792             if (sender == fAnamorphicPopUp || (sender == fRatioCheck && [fRatioCheck  state] == NSOnState))
793             {
794                 if (sender == fAnamorphicPopUp)
795                 {
796                     [fRatioCheck  setState: NSOnState];
797                 }
798                 
799                 /*
800                  KEEPING ASPECT RATIO
801                  Disable editing: PIXEL WIDTH, PIXEL HEIGHT
802                  */
803                 [fParWidthField setEnabled: NO];
804                 [fParHeightField setEnabled: NO];
805                 
806                 job->width = [fWidthStepper intValue];
807                 job->height = [fHeightStepper intValue];
808
809                 /* make sure our par is set back to original */
810                 job->anamorphic.par_width = titleParWidth;
811                 job->anamorphic.par_height = titleParHeight;
812                 
813                 [fParWidthField   setIntValue: titleParWidth];
814                 [fParHeightField   setIntValue: titleParHeight];
815                 
816                 /* modify our par dims from our storage dims */
817                 hb_set_anamorphic_size(job, &output_width, &output_height, &output_par_width, &output_par_height);
818                 float par_display_width = (float)output_width * (float)output_par_width / (float)output_par_height;
819                 
820                 /* go ahead and mod the display dims */
821                 [fDisplayWidthField   setStringValue: [NSString stringWithFormat:@"%.2f", par_display_width]];
822                 
823                 job->anamorphic.dar_width = [fDisplayWidthField floatValue];
824                 job->anamorphic.dar_height = (float)[fHeightStepper intValue];
825                 
826                 /* Set our dar here assuming we are just coming into capuj mode */
827                 dar = [fDisplayWidthField floatValue] / (float)[fHeightField intValue];
828                 
829             }
830
831             /* For capuj we disable these fields if we are keeping the dispay aspect */
832             if ([fRatioCheck  state] == NSOnState)
833             {
834                 /*
835                  KEEPING ASPECT RATIO
836                  DAR = DISPLAY WIDTH / DISPLAY HEIGHT (cache after every modification) */
837                  /*Disable editing: PIXEL WIDTH, PIXEL HEIGHT */
838                 
839                 [fParWidthField setEnabled: NO];
840                 [fParHeightField setEnabled: NO];
841                 
842                 /* Changing DISPLAY WIDTH: */
843                 if (sender == fDisplayWidthField)
844                 {
845                     job->anamorphic.dar_width = [fDisplayWidthField floatValue];
846                     /* Changes HEIGHT to keep DAR */
847                      /* calculate the height to retain the dar  */
848                     int raw_calulated_height = (int)((int)[fDisplayWidthField floatValue] / dar);
849                     /*  now use the modulus to go lower if there is a remainder  */
850                     /* Note to me, raw_calulated_height % [[fModulusPopUp titleOfSelectedItem] intValue]
851                      * gives me the remainder we are not mod (whatever our modulus is) subtract that from
852                      * the actual calculated value derived from the dar to round down to the nearest mod value.
853                      * This should be desireable over rounding up to the next mod value
854                      */
855                     int modulus_height = raw_calulated_height - (raw_calulated_height % [[fModulusPopUp titleOfSelectedItem] intValue]);
856                     if (modulus_height > fTitle->height)
857                     {
858                         [fHeightStepper setMaxValue: modulus_height];
859                     }
860                     [fHeightStepper setIntValue: modulus_height];
861                     job->anamorphic.dar_height = (float)[fHeightStepper intValue];
862                     job->height = [fHeightStepper intValue];
863                     
864                     /* Changes PIXEL WIDTH to new DISPLAY WIDTH */
865                     [fParWidthField setIntValue: [fDisplayWidthField intValue]];
866                     job->anamorphic.par_width = [fParWidthField intValue];
867                     /* Changes PIXEL HEIGHT to STORAGE WIDTH */
868                     [fParHeightField  setIntValue: [fWidthField intValue]];
869                     job->anamorphic.par_height = [fParHeightField intValue];
870                     
871                 }
872                 /* Changing HEIGHT: */
873                 if (sender == fHeightStepper)
874                 {
875                    job->anamorphic.dar_height = (float)[fHeightStepper intValue];
876                    job->height = [fHeightStepper intValue];
877                    
878                     /* Changes DISPLAY WIDTH to keep DAR*/
879                     [fDisplayWidthField setStringValue: [NSString stringWithFormat: @"%.2f",[fHeightStepper intValue] * dar]];
880                     job->anamorphic.dar_width = [fDisplayWidthField floatValue];
881                     /* Changes PIXEL WIDTH to new DISPLAY WIDTH */
882                     [fParWidthField setIntValue: [fDisplayWidthField intValue]];
883                     job->anamorphic.par_width = [fParWidthField intValue];
884                     /* Changes PIXEL HEIGHT to STORAGE WIDTH */
885                     [fParHeightField  setIntValue: [fWidthField intValue]];
886                     job->anamorphic.par_height = [fParHeightField intValue];
887                 }
888                 /* Changing STORAGE_WIDTH: */
889                 if (sender == fWidthStepper)
890                 {
891                     job->width = [fWidthStepper intValue];
892                     
893                     job->anamorphic.dar_width = [fDisplayWidthField floatValue];
894                     job->anamorphic.dar_height = [fHeightStepper floatValue];
895                      
896                     /* Changes PIXEL WIDTH to DISPLAY WIDTH */
897                     [fParWidthField setIntValue: [fDisplayWidthField intValue]];
898                     job->anamorphic.par_width = [fParWidthField intValue];
899                     /* Changes PIXEL HEIGHT to new STORAGE WIDTH */
900                     [fParHeightField  setIntValue: [fWidthStepper intValue]];
901                     job->anamorphic.par_height = [fParHeightField intValue];
902                 }
903             }
904             else if ([fRatioCheck  state] == NSOffState)
905             {
906                 /* Changing STORAGE_WIDTH: */
907                 if (sender == fWidthStepper)
908                 {
909                     job->width = [fWidthStepper intValue];
910                     /* changes DISPLAY WIDTH to STORAGE WIDTH * PIXEL WIDTH / PIXEL HEIGHT */
911                     [fDisplayWidthField setStringValue: [NSString stringWithFormat: @"%.2f",(float)[fWidthStepper intValue] * [fParWidthField intValue] / [fParHeightField intValue]]];
912                     job->anamorphic.dar_width = [fDisplayWidthField floatValue];
913                 }
914                 /* Changing PIXEL dimensions */
915                 if (sender == fParWidthField || sender == fParHeightField)
916                 {
917                     job->anamorphic.par_width = [fParWidthField intValue];
918                     job->anamorphic.par_height = [fParHeightField intValue];
919                     /* changes DISPLAY WIDTH to STORAGE WIDTH * PIXEL WIDTH / PIXEL HEIGHT */
920                     [fDisplayWidthField setStringValue: [NSString stringWithFormat: @"%.2f",(float)[fWidthStepper intValue] * [fParWidthField intValue] / [fParHeightField intValue]]];
921                     job->anamorphic.dar_width = [fDisplayWidthField floatValue];
922                 }
923                 /* Changing DISPLAY WIDTH: */
924                 if (sender == fDisplayWidthField)
925                 {
926                     job->anamorphic.dar_width = [fDisplayWidthField floatValue];
927                     job->anamorphic.dar_height = (float)[fHeightStepper intValue];
928                     /* changes PIXEL WIDTH to DISPLAY WIDTH and PIXEL HEIGHT to STORAGE WIDTH */
929                     [fParWidthField setIntValue: [fDisplayWidthField intValue]];
930                     job->anamorphic.par_width = [fParWidthField intValue];
931                     
932                     [fParHeightField  setIntValue: [fWidthField intValue]];
933                     job->anamorphic.par_height = [fParHeightField intValue];
934                     hb_set_anamorphic_size(job, &output_width, &output_height, &output_par_width, &output_par_height);
935                 }
936                 /* Changing HEIGHT: */
937                 if (sender == fHeightStepper)
938                 {
939                     /* just....changes the height.*/
940                     job->anamorphic.dar_height = [fHeightStepper intValue];
941                     job->height = [fHeightStepper intValue];
942                 }
943                 
944             }
945             
946 #pragma mark - END Capuj                       
947         }
948         
949         /* if the sender is the Anamorphic checkbox, record the state
950          of KeepAspect Ratio so it can be reset if Anamorphic is unchecked again */
951         if (sender == fAnamorphicPopUp)
952         {
953             keepAspectRatioPreviousState = [fRatioCheck state];
954         }
955         if ([fAnamorphicPopUp indexOfSelectedItem] != 3)
956         {
957             [fRatioCheck setState:NSOffState];
958         }
959         
960     }
961     else
962         {
963         job->width       = [fWidthStepper  intValue];
964         job->height      = [fHeightStepper intValue];
965         job->anamorphic.mode = 0;
966         [fWidthStepper setEnabled: YES];
967         [fWidthField setEnabled: YES];
968         [fHeightStepper setEnabled: YES];
969         [fHeightField setEnabled: YES];
970         [fRatioCheck setEnabled: YES];
971         /* if the sender is the Anamorphic checkbox, we return the
972          keep AR checkbox to its previous state */
973         if (sender == fAnamorphicPopUp)
974         {
975             [fRatioCheck setState:keepAspectRatioPreviousState];
976         }
977         
978         }
979         
980     //job->keep_ratio  = ( [fRatioCheck state] == NSOnState );
981     
982     if ([fAnamorphicPopUp indexOfSelectedItem] != 3)
983     {
984     job->keep_ratio  = ( [fRatioCheck state] == NSOnState );
985             if( job->keep_ratio )
986         {
987             if( sender == fWidthStepper || sender == fRatioCheck ||
988                sender == fCropTopStepper || sender == fCropBottomStepper )
989             {
990                 hb_fix_aspect( job, HB_KEEP_WIDTH );
991                 if( job->height > fTitle->height )
992                 {
993                     job->height = fTitle->height;
994                     hb_fix_aspect( job, HB_KEEP_HEIGHT );
995                 }
996             }
997             else
998             {
999                 hb_fix_aspect( job, HB_KEEP_HEIGHT );
1000                 if( job->width > fTitle->width )
1001                 {
1002                     job->width = fTitle->width;
1003                     hb_fix_aspect( job, HB_KEEP_WIDTH );
1004                 }
1005             }
1006             
1007         }
1008     }
1009     
1010     // hb_get_preview can't handle sizes that are larger than the original title
1011     if ([fAnamorphicPopUp indexOfSelectedItem] != 3)
1012     {
1013         // dimensions
1014         if( job->width > fTitle->width )
1015         {
1016             job->width = fTitle->width;
1017         }
1018         
1019         if( job->height > fTitle->height )
1020         {
1021             job->height = fTitle->height;
1022         }
1023     }
1024     
1025     [fWidthStepper      setIntValue: job->width];
1026     [fWidthField        setIntValue: job->width];
1027     if( [fAnamorphicPopUp indexOfSelectedItem] != 2) // if we are not loose or custom
1028     {
1029         [fHeightStepper     setIntValue: job->height];
1030         [fHeightField       setIntValue: job->height];
1031     }
1032     
1033     [fCropTopStepper    setIntValue: job->crop[0]];
1034     [fCropTopField      setIntValue: job->crop[0]];
1035     [fCropBottomStepper setIntValue: job->crop[1]];
1036     [fCropBottomField   setIntValue: job->crop[1]];
1037     [fCropLeftStepper   setIntValue: job->crop[2]];
1038     [fCropLeftField     setIntValue: job->crop[2]];
1039     [fCropRightStepper  setIntValue: job->crop[3]];
1040     [fCropRightField    setIntValue: job->crop[3]];
1041     
1042     //[fPreviewController SetTitle:fTitle];
1043     
1044     /* Sanity Check Here for < 16 px preview to avoid
1045      crashing hb_get_preview. In fact, just for kicks
1046      lets getting previews at a min limit of 32, since
1047      no human can see any meaningful detail below that */
1048     if (job->width >= 64 && job->height >= 64)
1049     {
1050         [self reloadStillPreview];
1051     }
1052     
1053     /* we get the sizing info to display from fPreviewController */
1054     [fSizeInfoField setStringValue: [fPreviewController pictureSizeInfoString]];
1055     
1056     if (sender != nil)
1057     {
1058         [fHBController pictureSettingsDidChange];
1059     }   
1060     
1061     if ([[self window] isVisible])
1062     { 
1063         [self adjustSizingDisplay:nil];
1064     }
1065     
1066 }
1067
1068 - (NSString*) getPictureSizeInfoString
1069 {
1070     return [fSizeInfoField stringValue];
1071 }
1072
1073 - (void)reloadStillPreview
1074
1075    hb_job_t * job = fTitle->job; 
1076    
1077    [fPreviewController SetTitle:fTitle];
1078     /* Sanity Check Here for < 16 px preview to avoid
1079      crashing hb_get_preview. In fact, just for kicks
1080      lets getting previews at a min limit of 32, since
1081      no human can see any meaningful detail below that */
1082     if (job->width >= 64 && job->height >= 64)
1083     {
1084        
1085          // Purge the existing picture previews so they get recreated the next time
1086         // they are needed.
1087       //  [fPreviewController purgeImageCache];
1088         /* We actually call displayPreview now from pictureSliderChanged which keeps
1089          * our picture preview slider in sync with the previews being shown
1090          */
1091
1092     //[fPreviewController pictureSliderChanged:nil];
1093     }
1094     
1095 }
1096
1097
1098 #pragma mark -
1099
1100 - (BOOL) autoCrop
1101 {
1102     return autoCrop;
1103 }
1104 - (void) setAutoCrop: (BOOL) setting
1105 {
1106     autoCrop = setting;
1107 }
1108
1109 - (BOOL) allowLooseAnamorphic
1110 {
1111     return allowLooseAnamorphic;
1112 }
1113
1114 - (void) setAllowLooseAnamorphic: (BOOL) setting
1115 {
1116     allowLooseAnamorphic = setting;
1117 }
1118
1119 - (IBAction)showPreviewPanel: (id)sender forTitle: (hb_title_t *)title
1120 {
1121     //[self SetTitle:title];
1122     [self showWindow:sender];
1123     //[self adjustSizingDisplay:nil];
1124     //[self adjustFilterDisplay:nil];
1125
1126 }
1127
1128
1129 #pragma mark -
1130 /* we use this to setup the initial picture filters upon first launch, after that their states
1131 are maintained across different sources */
1132 - (void) setInitialPictureFilters
1133 {
1134         /* we use a popup to show the detelecine settings */
1135         [fDetelecinePopUp removeAllItems];
1136     [fDetelecinePopUp addItemWithTitle: @"Off"];
1137     [fDetelecinePopUp addItemWithTitle: @"Default"];
1138     [fDetelecinePopUp addItemWithTitle: @"Custom"];
1139     [fDetelecinePopUp selectItemAtIndex: fPictureFilterSettings.detelecine];
1140     
1141     [self modeDecombDeinterlaceSliderChanged:nil];
1142     /* we use a popup to show the decomb settings */
1143         [fDecombPopUp removeAllItems];
1144     [fDecombPopUp addItemWithTitle: @"Off"];
1145     [fDecombPopUp addItemWithTitle: @"Default"];
1146     [fDecombPopUp addItemWithTitle: @"Custom"];
1147     [fDecombPopUp selectItemAtIndex: fPictureFilterSettings.decomb];
1148     
1149     /* we use a popup to show the deinterlace settings */
1150         [fDeinterlacePopUp removeAllItems];
1151     [fDeinterlacePopUp addItemWithTitle: @"None"];
1152     [fDeinterlacePopUp addItemWithTitle: @"Fast"];
1153     [fDeinterlacePopUp addItemWithTitle: @"Slow"];
1154         [fDeinterlacePopUp addItemWithTitle: @"Slower"];
1155     [fDeinterlacePopUp addItemWithTitle: @"Custom"];
1156     
1157         /* Set deinterlaces level according to the integer in the main window */
1158         [fDeinterlacePopUp selectItemAtIndex: fPictureFilterSettings.deinterlace];
1159
1160         /* we use a popup to show the denoise settings */
1161         [fDenoisePopUp removeAllItems];
1162     [fDenoisePopUp addItemWithTitle: @"None"];
1163     [fDenoisePopUp addItemWithTitle: @"Weak"];
1164         [fDenoisePopUp addItemWithTitle: @"Medium"];
1165     [fDenoisePopUp addItemWithTitle: @"Strong"];
1166     [fDenoisePopUp addItemWithTitle: @"Custom"];
1167         /* Set denoises level according to the integer in the main window */
1168         [fDenoisePopUp selectItemAtIndex: fPictureFilterSettings.denoise];
1169     
1170
1171 }
1172
1173
1174
1175
1176 - (IBAction) modeDecombDeinterlaceSliderChanged: (id) sender
1177 {
1178     
1179     /* since its a tickless slider, we have to  make sure we are on or off */
1180     if ([fDecombDeinterlaceSlider floatValue] < 0.50)
1181     {
1182         [fDecombDeinterlaceSlider setFloatValue:0.0];
1183     }
1184     else
1185     {
1186         [fDecombDeinterlaceSlider setFloatValue:1.0];
1187     }
1188     
1189     
1190     /* Decomb selected*/
1191     if ([fDecombDeinterlaceSlider floatValue] == 0.0)
1192     {
1193         [fDecombBox setHidden:NO];
1194         [fDeinterlaceBox setHidden:YES];
1195         fPictureFilterSettings.decomb = [fDecombPopUp indexOfSelectedItem];
1196         fPictureFilterSettings.usedecomb = 1;
1197         fPictureFilterSettings.deinterlace = 0;
1198         [fDecombPopUp selectItemAtIndex:fPictureFilterSettings.decomb];
1199         [self adjustFilterDisplay:fDecombPopUp];
1200     }
1201     else
1202     {
1203         [fDecombBox setHidden:YES];
1204         [fDeinterlaceBox setHidden:NO];
1205         fPictureFilterSettings.usedecomb = 0;
1206         fPictureFilterSettings.decomb = 0;
1207         [fDeinterlacePopUp selectItemAtIndex: fPictureFilterSettings.deinterlace];
1208         [self adjustFilterDisplay:fDeinterlacePopUp];
1209     }
1210     [self FilterSettingsChanged: fDecombDeinterlaceSlider];
1211 }
1212
1213
1214 - (IBAction) FilterSettingsChanged: (id) sender
1215 {
1216     
1217     fPictureFilterSettings.detelecine  = [fDetelecinePopUp indexOfSelectedItem];
1218     [self adjustFilterDisplay:fDetelecinePopUp];
1219     
1220     fPictureFilterSettings.decomb = [fDecombPopUp indexOfSelectedItem];
1221     [self adjustFilterDisplay:fDecombPopUp];
1222     
1223     fPictureFilterSettings.deinterlace = [fDeinterlacePopUp indexOfSelectedItem];
1224     [self adjustFilterDisplay:fDeinterlacePopUp];
1225     
1226     fPictureFilterSettings.denoise = [fDenoisePopUp indexOfSelectedItem];
1227     [self adjustFilterDisplay:fDenoisePopUp];
1228     
1229     if ([fDeblockField stringValue] == @"Off")
1230     {
1231         fPictureFilterSettings.deblock  = 0;
1232     }
1233     else
1234     {
1235         fPictureFilterSettings.deblock  = [fDeblockField intValue];
1236     }
1237     
1238     fPictureFilterSettings.grayscale = [fGrayscaleCheck state];
1239     
1240     if (sender != nil)
1241     {
1242         [fHBController pictureSettingsDidChange];
1243         
1244     }   
1245
1246 }
1247
1248
1249 #pragma mark -
1250
1251 - (IBAction) deblockSliderChanged: (id) sender
1252 {
1253     if ([fDeblockSlider floatValue] == 4.0)
1254     {
1255     [fDeblockField setStringValue: [NSString stringWithFormat: @"Off"]];
1256     }
1257     else
1258     {
1259     [fDeblockField setStringValue: [NSString stringWithFormat: @"%.0f", [fDeblockSlider floatValue]]];
1260     }
1261         [self FilterSettingsChanged: sender];
1262 }
1263
1264
1265 - (int) detelecine
1266 {
1267     return fPictureFilterSettings.detelecine;
1268 }
1269
1270 - (NSString*) detelecineCustomString
1271 {
1272     return [fDetelecineField stringValue];
1273 }
1274
1275 - (void) setDetelecine: (int) setting
1276 {
1277     fPictureFilterSettings.detelecine = setting;
1278 }
1279
1280 - (void) setDetelecineCustomString: (NSString*) string 
1281 {
1282     [fDetelecineField setStringValue:string];
1283 }
1284
1285 - (int) deinterlace
1286 {
1287     return fPictureFilterSettings.deinterlace;
1288 }
1289 - (NSString*) deinterlaceCustomString
1290 {
1291     return [fDeinterlaceField stringValue];
1292 }
1293
1294 - (void) setDeinterlaceCustomString: (NSString*) string 
1295 {
1296     [fDeinterlaceField setStringValue:string];
1297 }
1298
1299 - (void) setDeinterlace: (int) setting 
1300 {
1301     fPictureFilterSettings.deinterlace = setting;
1302 }
1303 - (int) decomb
1304 {
1305     return fPictureFilterSettings.decomb;
1306 }
1307
1308 - (NSString*) decombCustomString
1309 {
1310     return [fDecombField stringValue];
1311 }
1312
1313 - (int) useDecomb
1314 {
1315     return fPictureFilterSettings.usedecomb;
1316 }
1317
1318 - (void) setUseDecomb: (int) setting
1319 {
1320     fPictureFilterSettings.usedecomb = setting;
1321     if (fPictureFilterSettings.usedecomb == 1)
1322     {
1323         [fDecombDeinterlaceSlider setFloatValue:0.0];
1324     }
1325     else
1326     {
1327         [fDecombDeinterlaceSlider setFloatValue:1.0];
1328     }
1329     [self modeDecombDeinterlaceSliderChanged:nil];
1330 }
1331
1332 - (void) setDecomb: (int) setting {
1333     fPictureFilterSettings.decomb = setting;
1334 }
1335
1336 - (void) setDecombCustomString: (NSString*) string 
1337 {
1338     [fDecombField setStringValue:string];
1339 }
1340
1341 - (int) denoise
1342 {
1343     return fPictureFilterSettings.denoise;
1344 }
1345
1346 - (NSString*) denoiseCustomString
1347 {
1348     return [fDenoiseField stringValue];
1349 }
1350
1351 - (void) setDenoiseCustomString: (NSString*) string 
1352 {
1353     [fDenoiseField setStringValue:string];
1354 }
1355
1356 - (void) setDenoise: (int) setting
1357 {
1358     fPictureFilterSettings.denoise = setting;
1359 }
1360
1361 - (int) deblock
1362 {
1363     return fPictureFilterSettings.deblock;
1364 }
1365
1366 - (void) setDeblock: (int) setting
1367 {
1368     fPictureFilterSettings.deblock = setting;
1369 }
1370
1371 - (int) grayscale
1372 {
1373     return fPictureFilterSettings.grayscale;
1374 }
1375
1376 - (void) setGrayscale: (int) setting
1377 {
1378     fPictureFilterSettings.grayscale = setting;
1379 }
1380
1381
1382
1383 @end
1384