1 /* $Id: PictureController.mm,v 1.11 2005/08/01 15:10:44 titer Exp $
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. */
7 #import "PictureController.h"
9 #import "HBPreviewController.h"
13 @implementation PictureController
17 if (self = [super initWithWindowNibName:@"PictureSettings"])
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
25 // If/when we switch a lot of this stuff to bindings, this can probably
29 fPreviewController = [[PreviewController alloc] init];
34 //------------------------------------------------------------------------------------
35 // Displays and brings the picture window to the front
36 //------------------------------------------------------------------------------------
37 - (IBAction) showPictureWindow: (id)sender
39 if ([fPreviewController fullScreen] == YES)
41 [self showWindow:sender];
42 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"PictureSizeWindowIsOpen"];
43 [self setToFullScreenMode];
47 if ([[self window] isVisible])
49 [[self window] close];
53 [self showWindow:sender];
54 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"PictureSizeWindowIsOpen"];
55 [self setToWindowedMode];
58 [self adjustFilterDisplay:nil];
59 [self adjustSizingDisplay:nil];
62 - (BOOL) previewFullScreenMode
64 return [fPreviewController fullScreen];
67 /* this method is used to detect clicking on a tab in fSizeFilterView */
68 - (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
71 [self resizeInspectorForTab:nil];
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.
81 - (IBAction) resizeInspectorForTab: (id)sender
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;
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)
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
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];
100 else // we are Tab index 0 which is size
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];
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;
111 /* Check to see if we have changed the height from current */
112 //if (frame.size.height != [[self window] frame].size.height)
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;
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
125 if ((frame.origin.x + frame.size.width) > (screenOrigin.x + screenSize.width))
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;
131 [[self window] setFrame:frame display:YES animate:YES];
134 - (IBAction) adjustSizingDisplay: (id) sender
136 NSSize pictureSizingBoxSize = [fPictureSizeBox frame].size;
138 NSPoint fPictureSizeBoxOrigin = [fPictureSizeBox frame].origin;
139 NSSize pictureCropBoxSize = [fPictureCropBox frame].size;
140 NSPoint fPictureCropBoxOrigin = [fPictureCropBox frame].origin;
142 if ([fAnamorphicPopUp indexOfSelectedItem] == 3) // custom / power user jamboree
144 pictureSizingBoxSize.width = 530;
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];
157 /* Optionally swith the Storage and Display width positions*/
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];
165 fWidthStepperOrigin.x = [fWidthField frame].origin.x + [fWidthField frame].size.width + 4;
166 [fWidthStepper setFrameOrigin:fWidthStepperOrigin];
168 fWidthLabelOrigin.x = [fWidthField frame].origin.x - [fWidthLabel frame].size.width - 4;
169 [fWidthLabel setFrameOrigin:fWidthLabelOrigin];
170 [fWidthLabel setStringValue:@"Storage Width:"];
173 /* set the origin for fRatioCheck so origin.y == fRatioLabel2
174 * and origin.x == fDisplayWidthField
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];
184 pictureSizingBoxSize.width = 200;
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];
197 /* Optionally swith the Storage and Display width positions*/
200 NSPoint fWidthLabelOrigin = [fWidthLabel frame].origin;
201 NSPoint fWidthFieldOrigin = [fWidthField frame].origin;
202 NSPoint fWidthStepperOrigin = [fWidthStepper frame].origin;
204 fWidthFieldOrigin.x = [fHeightField frame].origin.x;
205 [fWidthField setFrameOrigin:fWidthFieldOrigin];
207 fWidthStepperOrigin.x = [fHeightStepper frame].origin.x;
208 [fWidthStepper setFrameOrigin:fWidthStepperOrigin];
210 fWidthLabelOrigin.x = [fWidthField frame].origin.x - [fWidthLabel frame].size.width -4;
211 [fWidthLabel setFrameOrigin:fWidthLabelOrigin];
212 [fWidthLabel setStringValue:@"Width:"];
216 /* set the origin for fRatioCheck so origin.y == fRatioLabel
217 * and origin.x == fWidthStepper
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];
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)
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];
239 pictureCropBoxSize.height += deltaYSizeBoxShift;
240 fPictureCropBoxOrigin.y -= deltaYSizeBoxShift;
241 fPictureCropBoxOrigin.x += deltaXSizeBoxShift;
243 [fPictureCropBox setFrameSize:pictureCropBoxSize];
244 [[fPictureCropBox animator] setFrameOrigin:fPictureCropBoxOrigin];
248 /* now we call to resize the entire inspector window */
249 [self resizeInspectorForTab:nil];
252 - (IBAction) adjustFilterDisplay: (id) sender
255 NSBox * filterBox = nil;
256 NSTextField * filterField;
257 if (sender == fDetelecinePopUp)
259 filterBox = fDetelecineBox;
260 filterField = fDetelecineField;
263 if (sender == fDecombDeinterlaceSlider)
265 if ([fDecombDeinterlaceSlider floatValue] == 0.0)
267 filterBox = fDecombBox;
268 filterField = fDecombField;
272 filterBox = fDeinterlaceBox;
273 filterField = fDeinterlaceField;
277 if (sender == fDecombPopUp)
279 filterBox = fDecombBox;
280 filterField = fDecombField;
282 if (sender == fDeinterlacePopUp)
284 filterBox = fDeinterlaceBox;
285 filterField = fDeinterlaceField;
288 if (sender == fDenoisePopUp)
290 filterBox = fDenoiseBox;
291 filterField = fDenoiseField;
294 NSSize currentSize = [filterBox frame].size;
295 NSRect boxFrame = [filterBox frame];
297 if ([sender titleOfSelectedItem] == @"Custom")
300 currentSize.height = 60;
305 currentSize.height = 30;
308 /* Check to see if we have changed the size from current */
309 if (currentSize.height != [filterBox frame].size.height)
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;
317 boxFrame.size.height = currentSize.height;
318 boxFrame.origin.y = boxOrigin.y;
319 [filterBox setFrame:boxFrame];
321 /* go ahead and resize the box */
322 //[[filterBox animator] setFrameSize:currentSize];
323 //[[filterBox animator] setFrameOrigin:origin];
326 if (filterBox == fDecombBox || filterBox == fDeinterlaceBox)
328 /* fDecombDeinterlaceBox*/
329 NSSize decombDeinterlaceBoxSize = [fDecombDeinterlaceBox frame].size;
330 NSPoint decombDeinterlaceBoxOrigin = [fDecombDeinterlaceBox frame].origin;
332 //decombDeinterlaceBoxSize.height = [filterBox frame].size.height + 50;
333 if (sender == fDecombDeinterlaceSlider)
335 [fHBController writeToActivityLog: "Sender is deinterlace decomb slider"];
338 if ([fDeinterlaceBox isHidden] == YES)
340 decombDeinterlaceBoxSize.height = [fDecombBox frame].size.height + 50;
341 [fHBController writeToActivityLog: "Resize by Decomb box"];
345 decombDeinterlaceBoxSize.height = [fDeinterlaceBox frame].size.height + 50;
346 [fHBController writeToActivityLog: "Resize by Deinterlace box"];
348 /* get delta's for the change in window size */
350 CGFloat deltaYdecombDeinterlace = decombDeinterlaceBoxSize.height - [fDecombDeinterlaceBox frame].size.height;
352 deltaYBoxShift = deltaYdecombDeinterlace;
354 decombDeinterlaceBoxOrigin.y -= deltaYdecombDeinterlace;
356 [fDecombDeinterlaceBox setFrameSize:decombDeinterlaceBoxSize];
357 [fDecombDeinterlaceBox setFrameOrigin:decombDeinterlaceBoxOrigin];
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)
366 decombDeintOrigin.y -= deltaYBoxShift;
367 [fDecombDeinterlaceBox setFrameOrigin:decombDeintOrigin];
369 denoiseOrigin.y -= deltaYBoxShift;
370 [fDenoiseBox setFrameOrigin:denoiseOrigin];
372 deblockOrigin.y -= deltaYBoxShift;
373 [fDeblockBox setFrameOrigin:deblockOrigin];
375 if (sender == fDecombPopUp || sender == fDeinterlacePopUp)
377 denoiseOrigin.y -= deltaYBoxShift;
378 [fDenoiseBox setFrameOrigin:denoiseOrigin];
380 deblockOrigin.y -= deltaYBoxShift;
381 [fDeblockBox setFrameOrigin:deblockOrigin];
384 if (sender == fDenoisePopUp)
386 deblockOrigin.y -= deltaYBoxShift;
387 [fDeblockBox setFrameOrigin:deblockOrigin];
390 /* now we call to resize the entire inspector window */
391 [self resizeInspectorForTab:nil];
399 - (IBAction) previewGoWindowed: (id)sender
401 [fPreviewController goWindowedScreen:self];
404 - (IBAction) showPreviewWindow: (id)sender
406 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"PreviewWindowIsOpen"];
407 [fPreviewController showWindow:sender];
413 - (void) setToFullScreenMode
415 int32_t shieldLevel = CGShieldingWindowLevel();
417 [fPictureWindow setLevel:shieldLevel + 1];
419 [fPictureWindow makeKeyAndOrderFront:self];
422 - (void) setToWindowedMode
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
430 [[self window] setLevel:NSFloatingWindowLevel];
433 - (void)setHBController: (HBController *)controller
435 fHBController = controller;
436 [fPreviewController setHBController: controller];
442 [fPictureWindow setDelegate:self];
443 if( ![[self window] setFrameUsingName:@"PictureSizing"] )
444 [[self window] center];
445 [self setWindowFrameAutosaveName:@"PictureSizing"];
446 [[self window] setExcludedFromWindowsMenu:YES];
448 [self setInitialPictureFilters];
450 /* Setup our layers for core animation */
451 [fSizeFilterView setWantsLayer:YES];
452 [fPictureSizeBox setWantsLayer:YES];
453 [fPictureCropBox setWantsLayer:YES];
458 - (void)windowWillClose:(NSNotification *)aNotification
460 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"PictureSizeWindowIsOpen"];
463 - (BOOL)windowShouldClose:(id)fPictureWindow
470 [fPreviewController release];
474 - (void) SetHandle: (hb_handle_t *) handle
478 [fPreviewController SetHandle: fHandle];
481 - (void) SetTitle: (hb_title_t *) title
483 hb_job_t * job = title->job;
487 [fWidthStepper setValueWraps: NO];
488 [fWidthStepper setIncrement: 16];
489 [fWidthStepper setMinValue: 64];
490 [fHeightStepper setValueWraps: NO];
491 [fHeightStepper setIncrement: 16];
492 [fHeightStepper setMinValue: 64];
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];
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];
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];
523 //[self adjustSizingDisplay:nil];
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"];
533 [fModulusPopUp selectItemWithTitle: [NSString stringWithFormat:@"%d",job->modulus]];
537 [fModulusPopUp selectItemAtIndex: 0];
541 /* We initially set the previous state of keep ar to on */
542 keepAspectRatioPreviousState = 1;
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]];
558 [fCropMatrix selectCellAtRow: 0 column:0];
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];
569 [self deblockSliderChanged: nil];
572 MaxOutputWidth = title->width - job->crop[2] - job->crop[3];
573 MaxOutputHeight = title->height - job->crop[0] - job->crop[1];
575 titleDarWidth = job->anamorphic.dar_width;
576 titleDarHeight = job->anamorphic.dar_height;
578 titleParWidth = job->anamorphic.par_width;
579 titleParHeight = job->anamorphic.par_height;
581 [self SettingsChanged:nil];
584 - (IBAction) storageLinkChanged: (id) sender
586 /* since we have a tickless slider, make sure we are at 0.0 or 1.0 */
587 if ([fStorageLinkSlider floatValue] < 0.50)
589 [fStorageLinkSlider setFloatValue:0.0];
590 /* set slider labels to reflect choice */
591 [fStorageLinkParLabel setEnabled:YES];
592 [fStorageLinkDisplayLabel setEnabled:NO];
597 [fStorageLinkSlider setFloatValue:1.0];
598 /* set slider labels to reflect choice */
599 [fStorageLinkParLabel setEnabled:NO];
600 [fStorageLinkDisplayLabel setEnabled:YES];
605 - (IBAction) parLinkChanged: (id) sender
607 /* since we have a tickless slider, make sure we are at 0.0 or 1.0 */
608 if ([fParLinkSlider floatValue] < 0.50)
610 [fParLinkSlider setFloatValue:0.0];
611 /* set slider labels to reflect choice */
612 [fParLinkStorageLabel setEnabled:YES];
613 [fParLinkDisplayLabel setEnabled:NO];
617 [fParLinkSlider setFloatValue:1.0];
618 /* set slider labels to reflect choice */
619 [fParLinkStorageLabel setEnabled:NO];
620 [fParLinkDisplayLabel setEnabled:YES];
625 - (IBAction) displayLinkChanged: (id) sender
627 /* since we have a tickless slider, make sure we are at 0.0 or 1.0 */
628 if ([fDisplayLinkSlider floatValue] < 0.50)
630 [fDisplayLinkSlider setFloatValue:0.0];
631 /* set slider labels to reflect choice */
632 [fDisplayLinkStorageLabel setEnabled:YES];
633 [fDisplayLinkParLabel setEnabled:NO];
637 [fDisplayLinkSlider setFloatValue:1.0];
638 /* set slider labels to reflect choice */
639 [fDisplayLinkStorageLabel setEnabled:NO];
640 [fDisplayLinkParLabel setEnabled:YES];
645 - (IBAction) SettingsChanged: (id) sender
647 hb_job_t * job = fTitle->job;
649 /* if we are anything but strict anamorphic */
650 if ([fAnamorphicPopUp indexOfSelectedItem] != 1)
652 [fModulusLabel setHidden:NO];
653 [fModulusPopUp setHidden:NO];
654 if (sender == fModulusPopUp)
656 /* do a dry run with hb_fix aspect to get new modulus */
657 job->modulus = [[fModulusPopUp titleOfSelectedItem] intValue];
659 hb_fix_aspect( job, HB_KEEP_WIDTH );
660 if( job->height > fTitle->height )
662 job->height = fTitle->height;
663 hb_fix_aspect( job, HB_KEEP_HEIGHT );
665 [fWidthStepper setIntValue: job->width];
666 [fWidthField setIntValue: job->width];
667 if( [fAnamorphicPopUp indexOfSelectedItem] != 2) // if we are not loose or custom
669 [fHeightStepper setIntValue: job->height];
670 [fHeightField setIntValue: job->height];
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];
681 job->modulus = [[fModulusPopUp titleOfSelectedItem] intValue];
683 [fWidthStepper setIncrement: job->modulus];
684 [fHeightStepper setIncrement: job->modulus];
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
689 [fHeightStepper setMaxValue: fTitle->height];
691 autoCrop = ( [fCropMatrix selectedRow] == 0 );
692 [fCropTopStepper setEnabled: !autoCrop];
693 [fCropBottomStepper setEnabled: !autoCrop];
694 [fCropLeftStepper setEnabled: !autoCrop];
695 [fCropRightStepper setEnabled: !autoCrop];
699 memcpy( job->crop, fTitle->crop, 4 * sizeof( int ) );
703 job->crop[0] = [fCropTopStepper intValue];
704 job->crop[1] = [fCropBottomStepper intValue];
705 job->crop[2] = [fCropLeftStepper intValue];
706 job->crop[3] = [fCropRightStepper intValue];
709 [fRatioCheck setEnabled: YES];
712 [fParWidthField setEnabled: NO];
713 [fParHeightField setEnabled: NO];
714 [fDisplayWidthField setEnabled: NO];
716 /* If we are not custom anamorphic, make sure we retain the orginal par */
717 if( [fAnamorphicPopUp indexOfSelectedItem] != 3 )
719 job->anamorphic.par_width = titleParWidth;
720 job->anamorphic.par_height = titleParHeight;
721 [fRatioLabel setHidden: NO];
724 if( [fAnamorphicPopUp indexOfSelectedItem] > 0 )
726 if ([fAnamorphicPopUp indexOfSelectedItem] == 1) // strict
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]];
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];
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];
745 else if ([fAnamorphicPopUp indexOfSelectedItem] == 2) // Loose anamorphic
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
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.
759 if (sender == fAnamorphicPopUp)
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]];
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];
771 else if ([fAnamorphicPopUp indexOfSelectedItem] == 3) // custom / power user jamboree
774 #pragma mark - STARTCapuj
776 job->anamorphic.mode = 3;
778 /* Set the status of our custom ana only widgets accordingly */
779 [fModulusPopUp setEnabled:YES];
781 [fWidthStepper setEnabled: YES];
782 [fWidthField setEnabled: YES];
784 [fHeightStepper setEnabled: YES];
785 /* for capuj the storage field is immaterial */
786 [fHeightField setEnabled: YES];
788 [fRatioCheck setEnabled: YES];
789 if (sender == fRatioCheck)
791 if ([fRatioCheck state] == NSOnState)
793 [fParWidthField setEnabled: NO];
794 [fParHeightField setEnabled: NO];
798 [fParWidthField setEnabled: YES];
799 [fParHeightField setEnabled: YES];
803 [fParWidthField setEnabled: YES];
804 [fParHeightField setEnabled: YES];
806 [fDisplayWidthField setEnabled: YES];
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.
813 if (sender == fAnamorphicPopUp)
815 /* When entering custom anamorphic, we start with keep ar on */
816 [fRatioCheck setState: NSOnState];
819 Disable editing: PIXEL WIDTH, PIXEL HEIGHT
821 [fParWidthField setEnabled: NO];
822 [fParHeightField setEnabled: NO];
824 job->width = [fWidthStepper intValue];
825 job->height = [fHeightStepper intValue];
827 /* make sure our par is set back to original */
828 job->anamorphic.par_width = titleParWidth;
829 job->anamorphic.par_height = titleParHeight;
831 [fParWidthField setIntValue: titleParWidth];
832 [fParHeightField setIntValue: titleParHeight];
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;
838 /* go ahead and mod the display dims */
839 [fDisplayWidthField setStringValue: [NSString stringWithFormat:@"%.2f", par_display_width]];
841 job->anamorphic.dar_width = [fDisplayWidthField floatValue];
842 job->anamorphic.dar_height = (float)[fHeightStepper intValue];
844 /* Set our dar here assuming we are just coming into capuj mode */
845 dar = [fDisplayWidthField floatValue] / (float)[fHeightField intValue];
849 /* For capuj we disable these fields if we are keeping the dispay aspect */
850 if ([fRatioCheck state] == NSOnState)
854 DAR = DISPLAY WIDTH / DISPLAY HEIGHT (cache after every modification) */
855 /*Disable editing: PIXEL WIDTH, PIXEL HEIGHT */
857 [fParWidthField setEnabled: NO];
858 [fParHeightField setEnabled: NO];
860 /* Changing DISPLAY WIDTH: */
861 if (sender == fDisplayWidthField)
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
873 int modulus_height = raw_calulated_height - (raw_calulated_height % [[fModulusPopUp titleOfSelectedItem] intValue]);
874 if (modulus_height > fTitle->height)
876 [fHeightStepper setMaxValue: modulus_height];
878 [fHeightStepper setIntValue: modulus_height];
879 job->anamorphic.dar_height = (float)[fHeightStepper intValue];
880 job->height = [fHeightStepper intValue];
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];
890 /* Changing HEIGHT: */
891 if (sender == fHeightStepper)
893 job->anamorphic.dar_height = (float)[fHeightStepper intValue];
894 job->height = [fHeightStepper intValue];
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];
906 /* Changing STORAGE_WIDTH: */
907 if (sender == fWidthStepper)
909 job->width = [fWidthStepper intValue];
911 job->anamorphic.dar_width = [fDisplayWidthField floatValue];
912 job->anamorphic.dar_height = [fHeightStepper floatValue];
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];
922 else if ([fRatioCheck state] == NSOffState)
924 /* Changing STORAGE_WIDTH: */
925 if (sender == fWidthStepper)
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];
932 /* Changing PIXEL dimensions */
933 if (sender == fParWidthField || sender == fParHeightField)
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];
941 /* Changing DISPLAY WIDTH: */
942 if (sender == fDisplayWidthField)
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];
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);
954 /* Changing HEIGHT: */
955 if (sender == fHeightStepper)
957 /* just....changes the height.*/
958 job->anamorphic.dar_height = [fHeightStepper intValue];
959 job->height = [fHeightStepper intValue];
964 #pragma mark - END Capuj
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)
971 keepAspectRatioPreviousState = [fRatioCheck state];
973 if ([fAnamorphicPopUp indexOfSelectedItem] != 3)
975 [fRatioCheck setState:NSOffState];
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)
993 [fRatioCheck setState:keepAspectRatioPreviousState];
998 if ([fAnamorphicPopUp indexOfSelectedItem] != 3)
1000 job->keep_ratio = ( [fRatioCheck state] == NSOnState );
1001 if( job->keep_ratio )
1003 if( sender == fWidthStepper || sender == fRatioCheck ||
1004 sender == fCropTopStepper || sender == fCropBottomStepper||
1005 sender == fCropMatrix || sender == nil )
1007 hb_fix_aspect( job, HB_KEEP_WIDTH );
1008 if( job->height > fTitle->height )
1010 job->height = fTitle->height;
1011 hb_fix_aspect( job, HB_KEEP_HEIGHT );
1016 hb_fix_aspect( job, HB_KEEP_HEIGHT );
1017 if( job->width > fTitle->width )
1019 job->width = fTitle->width;
1020 hb_fix_aspect( job, HB_KEEP_WIDTH );
1027 // hb_get_preview can't handle sizes that are larger than the original title
1028 if ([fAnamorphicPopUp indexOfSelectedItem] != 3)
1031 if( job->width > fTitle->width )
1033 job->width = fTitle->width;
1036 if( job->height > fTitle->height )
1038 job->height = fTitle->height;
1042 [fWidthStepper setIntValue: job->width];
1043 [fWidthField setIntValue: job->width];
1044 if( [fAnamorphicPopUp indexOfSelectedItem] != 2) // if we are not loose or custom
1046 [fHeightStepper setIntValue: job->height];
1047 [fHeightField setIntValue: job->height];
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]];
1059 //[fPreviewController SetTitle:fTitle];
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)
1067 [self reloadStillPreview];
1070 /* we get the sizing info to display from fPreviewController */
1071 [fSizeInfoField setStringValue: [fPreviewController pictureSizeInfoString]];
1075 [fHBController pictureSettingsDidChange];
1078 if ([[self window] isVisible])
1080 [self adjustSizingDisplay:nil];
1085 - (NSString*) getPictureSizeInfoString
1087 return [fSizeInfoField stringValue];
1090 - (void)reloadStillPreview
1092 hb_job_t * job = fTitle->job;
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)
1102 // Purge the existing picture previews so they get recreated the next time
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
1109 //[fPreviewController pictureSliderChanged:nil];
1121 - (void) setAutoCrop: (BOOL) setting
1126 - (IBAction)showPreviewPanel: (id)sender forTitle: (hb_title_t *)title
1128 //[self SetTitle:title];
1129 [self showWindow:sender];
1130 //[self adjustSizingDisplay:nil];
1131 //[self adjustFilterDisplay:nil];
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
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];
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"];
1155 [fDecombPopUp selectItemAtIndex: fPictureFilterSettings.decomb];
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"];
1165 /* Set deinterlaces level according to the integer in the main window */
1166 [fDeinterlacePopUp selectItemAtIndex: fPictureFilterSettings.deinterlace];
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];
1184 - (IBAction) modeDecombDeinterlaceSliderChanged: (id) sender
1187 /* since its a tickless slider, we have to make sure we are on or off */
1188 if ([fDecombDeinterlaceSlider floatValue] < 0.50)
1190 [fDecombDeinterlaceSlider setFloatValue:0.0];
1194 [fDecombDeinterlaceSlider setFloatValue:1.0];
1198 /* Decomb selected*/
1199 if ([fDecombDeinterlaceSlider floatValue] == 0.0)
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];
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];
1218 [self FilterSettingsChanged: fDecombDeinterlaceSlider];
1222 - (IBAction) FilterSettingsChanged: (id) sender
1225 fPictureFilterSettings.detelecine = [fDetelecinePopUp indexOfSelectedItem];
1226 [self adjustFilterDisplay:fDetelecinePopUp];
1228 fPictureFilterSettings.decomb = [fDecombPopUp indexOfSelectedItem];
1229 [self adjustFilterDisplay:fDecombPopUp];
1231 fPictureFilterSettings.deinterlace = [fDeinterlacePopUp indexOfSelectedItem];
1232 [self adjustFilterDisplay:fDeinterlacePopUp];
1234 fPictureFilterSettings.denoise = [fDenoisePopUp indexOfSelectedItem];
1235 [self adjustFilterDisplay:fDenoisePopUp];
1237 if ([fDeblockField stringValue] == @"Off")
1239 fPictureFilterSettings.deblock = 0;
1243 fPictureFilterSettings.deblock = [fDeblockField intValue];
1246 fPictureFilterSettings.grayscale = [fGrayscaleCheck state];
1250 [fHBController pictureSettingsDidChange];
1259 - (IBAction) deblockSliderChanged: (id) sender
1261 if ([fDeblockSlider floatValue] == 4.0)
1263 [fDeblockField setStringValue: [NSString stringWithFormat: @"Off"]];
1267 [fDeblockField setStringValue: [NSString stringWithFormat: @"%.0f", [fDeblockSlider floatValue]]];
1269 [self FilterSettingsChanged: sender];
1275 return fPictureFilterSettings.detelecine;
1278 - (NSString*) detelecineCustomString
1280 return [fDetelecineField stringValue];
1283 - (void) setDetelecine: (int) setting
1285 fPictureFilterSettings.detelecine = setting;
1288 - (void) setDetelecineCustomString: (NSString*) string
1290 [fDetelecineField setStringValue:string];
1295 return fPictureFilterSettings.deinterlace;
1297 - (NSString*) deinterlaceCustomString
1299 return [fDeinterlaceField stringValue];
1302 - (void) setDeinterlaceCustomString: (NSString*) string
1304 [fDeinterlaceField setStringValue:string];
1307 - (void) setDeinterlace: (int) setting
1309 fPictureFilterSettings.deinterlace = setting;
1313 return fPictureFilterSettings.decomb;
1316 - (NSString*) decombCustomString
1318 return [fDecombField stringValue];
1323 return fPictureFilterSettings.usedecomb;
1326 - (void) setUseDecomb: (int) setting
1328 fPictureFilterSettings.usedecomb = setting;
1329 if (fPictureFilterSettings.usedecomb == 1)
1331 [fDecombDeinterlaceSlider setFloatValue:0.0];
1335 [fDecombDeinterlaceSlider setFloatValue:1.0];
1337 [self modeDecombDeinterlaceSliderChanged:nil];
1340 - (void) setDecomb: (int) setting {
1341 fPictureFilterSettings.decomb = setting;
1344 - (void) setDecombCustomString: (NSString*) string
1346 [fDecombField setStringValue:string];
1351 return fPictureFilterSettings.denoise;
1354 - (NSString*) denoiseCustomString
1356 return [fDenoiseField stringValue];
1359 - (void) setDenoiseCustomString: (NSString*) string
1361 [fDenoiseField setStringValue:string];
1364 - (void) setDenoise: (int) setting
1366 fPictureFilterSettings.denoise = setting;
1371 return fPictureFilterSettings.deblock;
1374 - (void) setDeblock: (int) setting
1376 fPictureFilterSettings.deblock = setting;
1381 return fPictureFilterSettings.grayscale;
1384 - (void) setGrayscale: (int) setting
1386 fPictureFilterSettings.grayscale = setting;