OSDN Git Service

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