OSDN Git Service

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