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 [fModulusLabel setHidden: NO];
154 [fModulusPopUp setHidden: NO];
155 /* adjust/move keep ar checkbox */
156 [fRatioLabel setHidden: YES];
157 [fRatioLabel2 setHidden: NO];
159 /* Optionally swith the Storage and Display width positions*/
161 NSPoint fWidthLabelOrigin = [fWidthLabel frame].origin;
162 NSPoint fWidthFieldOrigin = [fWidthField frame].origin;
163 NSPoint fWidthStepperOrigin = [fWidthStepper frame].origin;
164 fWidthFieldOrigin.x = [fRatioLabel2 frame].origin.x + [fRatioLabel2 frame].size.width + 4;
165 [fWidthField setFrameOrigin:fWidthFieldOrigin];
167 fWidthStepperOrigin.x = [fWidthField frame].origin.x + [fWidthField frame].size.width + 4;
168 [fWidthStepper setFrameOrigin:fWidthStepperOrigin];
170 fWidthLabelOrigin.x = [fWidthField frame].origin.x - [fWidthLabel frame].size.width - 4;
171 [fWidthLabel setFrameOrigin:fWidthLabelOrigin];
172 [fWidthLabel setStringValue:@"Storage Width:"];
175 /* set the origin for fRatioCheck so origin.y == fRatioLabel2
176 * and origin.x == fDisplayWidthField
178 NSPoint fRatioCheckOrigin = [fRatioCheck frame].origin;
179 fRatioCheckOrigin.y = [fRatioLabel2 frame].origin.y - 2;
180 fRatioCheckOrigin.x = [fRatioLabel2 frame].origin.x + [fRatioLabel2 frame].size.width + 4;
181 [fRatioCheck setFrameOrigin:fRatioCheckOrigin];
186 pictureSizingBoxSize.width = 200;
188 /* Set visibility of capuj widgets */
189 [fParWidthField setHidden: YES];
190 [fParHeightField setHidden: YES];
191 [fParWidthLabel setHidden: YES];
192 [fParHeightLabel setHidden: YES];
193 [fDisplayWidthField setHidden: YES];
194 [fDisplayWidthLabel setHidden: YES];
195 [fModulusLabel setHidden: YES];
196 [fModulusPopUp setHidden: YES];
197 /* adjust/move keep ar checkbox */
198 [fRatioLabel setHidden: NO];
199 [fRatioLabel2 setHidden: YES];
201 /* Optionally swith the Storage and Display width positions*/
204 NSPoint fWidthLabelOrigin = [fWidthLabel frame].origin;
205 NSPoint fWidthFieldOrigin = [fWidthField frame].origin;
206 NSPoint fWidthStepperOrigin = [fWidthStepper frame].origin;
208 fWidthFieldOrigin.x = [fHeightField frame].origin.x;
209 [fWidthField setFrameOrigin:fWidthFieldOrigin];
211 fWidthStepperOrigin.x = [fHeightStepper frame].origin.x;
212 [fWidthStepper setFrameOrigin:fWidthStepperOrigin];
214 fWidthLabelOrigin.x = [fWidthField frame].origin.x - [fWidthLabel frame].size.width -4;
215 [fWidthLabel setFrameOrigin:fWidthLabelOrigin];
216 [fWidthLabel setStringValue:@"Width:"];
220 /* set the origin for fRatioCheck so origin.y == fRatioLabel
221 * and origin.x == fWidthStepper
223 NSPoint fRatioCheckOrigin = [fRatioCheck frame].origin;
224 fRatioCheckOrigin.y = [fRatioLabel frame].origin.y - 2;
225 fRatioCheckOrigin.x = [fWidthStepper frame].origin.x - 2;
226 [fRatioCheck setFrameOrigin:fRatioCheckOrigin];
230 /* Check to see if we have changed the size from current */
231 if (pictureSizingBoxSize.height != [fPictureSizeBox frame].size.height || pictureSizingBoxSize.width != [fPictureSizeBox frame].size.width)
233 /* Get our delta for the change in picture size box height */
234 CGFloat deltaYSizeBoxShift = pictureSizingBoxSize.height - [fPictureSizeBox frame].size.height;
235 fPictureSizeBoxOrigin.y -= deltaYSizeBoxShift;
236 /* Get our delta for the change in picture size box width */
237 CGFloat deltaXSizeBoxShift = pictureSizingBoxSize.width - [fPictureSizeBox frame].size.width;
238 //fPictureSizeBoxOrigin.x += deltaXSizeBoxShift;
239 /* set our new Picture size box size */
240 [fPictureSizeBox setFrameSize:pictureSizingBoxSize];
241 [fPictureSizeBox setFrameOrigin:fPictureSizeBoxOrigin];
243 pictureCropBoxSize.height += deltaYSizeBoxShift;
244 fPictureCropBoxOrigin.y -= deltaYSizeBoxShift;
245 fPictureCropBoxOrigin.x += deltaXSizeBoxShift;
247 [fPictureCropBox setFrameSize:pictureCropBoxSize];
248 [[fPictureCropBox animator] setFrameOrigin:fPictureCropBoxOrigin];
252 /* now we call to resize the entire inspector window */
253 [self resizeInspectorForTab:nil];
256 - (IBAction) adjustFilterDisplay: (id) sender
259 NSBox * filterBox = nil;
260 NSTextField * filterField;
261 if (sender == fDetelecinePopUp)
263 filterBox = fDetelecineBox;
264 filterField = fDetelecineField;
267 if (sender == fDecombDeinterlaceSlider)
269 if ([fDecombDeinterlaceSlider floatValue] == 0.0)
271 filterBox = fDecombBox;
272 filterField = fDecombField;
276 filterBox = fDeinterlaceBox;
277 filterField = fDeinterlaceField;
281 if (sender == fDecombPopUp)
283 filterBox = fDecombBox;
284 filterField = fDecombField;
286 if (sender == fDeinterlacePopUp)
288 filterBox = fDeinterlaceBox;
289 filterField = fDeinterlaceField;
292 if (sender == fDenoisePopUp)
294 filterBox = fDenoiseBox;
295 filterField = fDenoiseField;
298 NSSize currentSize = [filterBox frame].size;
299 NSRect boxFrame = [filterBox frame];
301 if ([sender titleOfSelectedItem] == @"Custom")
304 currentSize.height = 60;
309 currentSize.height = 30;
312 /* Check to see if we have changed the size from current */
313 if (currentSize.height != [filterBox frame].size.height)
315 /* We are changing the size of the box, so recalc the origin */
316 NSPoint boxOrigin = [filterBox frame].origin;
317 /* We get the deltaY here for how much we are expanding/contracting the box vertically */
318 CGFloat deltaYBoxShift = currentSize.height - [filterBox frame].size.height;
319 boxOrigin.y -= deltaYBoxShift;
321 boxFrame.size.height = currentSize.height;
322 boxFrame.origin.y = boxOrigin.y;
323 [filterBox setFrame:boxFrame];
325 /* go ahead and resize the box */
326 //[[filterBox animator] setFrameSize:currentSize];
327 //[[filterBox animator] setFrameOrigin:origin];
330 if (filterBox == fDecombBox || filterBox == fDeinterlaceBox)
332 /* fDecombDeinterlaceBox*/
333 NSSize decombDeinterlaceBoxSize = [fDecombDeinterlaceBox frame].size;
334 NSPoint decombDeinterlaceBoxOrigin = [fDecombDeinterlaceBox frame].origin;
336 //decombDeinterlaceBoxSize.height = [filterBox frame].size.height + 50;
337 if (sender == fDecombDeinterlaceSlider)
339 [fHBController writeToActivityLog: "Sender is deinterlace decomb slider"];
342 if ([fDeinterlaceBox isHidden] == YES)
344 decombDeinterlaceBoxSize.height = [fDecombBox frame].size.height + 50;
345 [fHBController writeToActivityLog: "Resize by Decomb box"];
349 decombDeinterlaceBoxSize.height = [fDeinterlaceBox frame].size.height + 50;
350 [fHBController writeToActivityLog: "Resize by Deinterlace box"];
352 /* get delta's for the change in window size */
354 CGFloat deltaYdecombDeinterlace = decombDeinterlaceBoxSize.height - [fDecombDeinterlaceBox frame].size.height;
356 deltaYBoxShift = deltaYdecombDeinterlace;
358 decombDeinterlaceBoxOrigin.y -= deltaYdecombDeinterlace;
360 [fDecombDeinterlaceBox setFrameSize:decombDeinterlaceBoxSize];
361 [fDecombDeinterlaceBox setFrameOrigin:decombDeinterlaceBoxOrigin];
364 /* now we must reset the origin of each box below the adjusted box*/
365 NSPoint decombDeintOrigin = [fDecombDeinterlaceBox frame].origin;
366 NSPoint denoiseOrigin = [fDenoiseBox frame].origin;
367 NSPoint deblockOrigin = [fDeblockBox frame].origin;
368 if (sender == fDetelecinePopUp)
370 decombDeintOrigin.y -= deltaYBoxShift;
371 [fDecombDeinterlaceBox setFrameOrigin:decombDeintOrigin];
373 denoiseOrigin.y -= deltaYBoxShift;
374 [fDenoiseBox setFrameOrigin:denoiseOrigin];
376 deblockOrigin.y -= deltaYBoxShift;
377 [fDeblockBox setFrameOrigin:deblockOrigin];
379 if (sender == fDecombPopUp || sender == fDeinterlacePopUp)
381 denoiseOrigin.y -= deltaYBoxShift;
382 [fDenoiseBox setFrameOrigin:denoiseOrigin];
384 deblockOrigin.y -= deltaYBoxShift;
385 [fDeblockBox setFrameOrigin:deblockOrigin];
388 if (sender == fDenoisePopUp)
390 deblockOrigin.y -= deltaYBoxShift;
391 [fDeblockBox setFrameOrigin:deblockOrigin];
394 /* now we call to resize the entire inspector window */
395 [self resizeInspectorForTab:nil];
403 - (IBAction) previewGoWindowed: (id)sender
405 [fPreviewController goWindowedScreen:self];
408 - (IBAction) showPreviewWindow: (id)sender
410 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"PreviewWindowIsOpen"];
411 [fPreviewController showWindow:sender];
417 - (void) setToFullScreenMode
419 int32_t shieldLevel = CGShieldingWindowLevel();
421 [fPictureWindow setLevel:shieldLevel + 1];
423 [fPictureWindow makeKeyAndOrderFront:self];
426 - (void) setToWindowedMode
428 /* Set the window back to Floating Window mode
429 * This will put the window always on top, but
430 * since we have Hide on Deactivate set in our
431 * xib, if other apps are put in focus we will
432 * hide properly to stay out of the way
434 [[self window] setLevel:NSFloatingWindowLevel];
437 - (void)setHBController: (HBController *)controller
439 fHBController = controller;
440 [fPreviewController setHBController: controller];
446 [fPictureWindow setDelegate:self];
447 if( ![[self window] setFrameUsingName:@"PictureSizing"] )
448 [[self window] center];
449 [self setWindowFrameAutosaveName:@"PictureSizing"];
450 [[self window] setExcludedFromWindowsMenu:YES];
452 [self setInitialPictureFilters];
454 /* Setup our layers for core animation */
455 [fSizeFilterView setWantsLayer:YES];
456 [fPictureSizeBox setWantsLayer:YES];
457 [fPictureCropBox setWantsLayer:YES];
462 - (void)windowWillClose:(NSNotification *)aNotification
464 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"PictureSizeWindowIsOpen"];
467 - (BOOL)windowShouldClose:(id)fPictureWindow
474 [fPreviewController release];
478 - (void) SetHandle: (hb_handle_t *) handle
482 [fPreviewController SetHandle: fHandle];
485 - (void) SetTitle: (hb_title_t *) title
487 hb_job_t * job = title->job;
491 [fWidthStepper setValueWraps: NO];
492 [fWidthStepper setIncrement: 16];
493 [fWidthStepper setMinValue: 64];
494 [fHeightStepper setValueWraps: NO];
495 [fHeightStepper setIncrement: 16];
496 [fHeightStepper setMinValue: 64];
498 [fCropTopStepper setIncrement: 2];
499 [fCropTopStepper setMinValue: 0];
500 [fCropBottomStepper setIncrement: 2];
501 [fCropBottomStepper setMinValue: 0];
502 [fCropLeftStepper setIncrement: 2];
503 [fCropLeftStepper setMinValue: 0];
504 [fCropRightStepper setIncrement: 2];
505 [fCropRightStepper setMinValue: 0];
507 [fWidthStepper setMaxValue: title->width];
508 [fWidthStepper setIntValue: job->width];
509 [fWidthField setIntValue: job->width];
510 [fHeightStepper setMaxValue: title->height];
511 [fHeightStepper setIntValue: job->height];
512 [fHeightField setIntValue: job->height];
513 [fRatioCheck setState: job->keep_ratio ? NSOnState : NSOffState];
514 [fCropTopStepper setMaxValue: title->height/2-2];
515 [fCropBottomStepper setMaxValue: title->height/2-2];
516 [fCropLeftStepper setMaxValue: title->width/2-2];
517 [fCropRightStepper setMaxValue: title->width/2-2];
519 /* Populate the Anamorphic NSPopUp button here */
520 [fAnamorphicPopUp removeAllItems];
521 [fAnamorphicPopUp addItemWithTitle: @"None"];
522 [fAnamorphicPopUp addItemWithTitle: @"Strict"];
523 if (allowLooseAnamorphic)
525 [fAnamorphicPopUp addItemWithTitle: @"Loose"];
527 [fAnamorphicPopUp addItemWithTitle: @"Custom"];
528 [fAnamorphicPopUp selectItemAtIndex: job->anamorphic.mode];
530 //[self adjustSizingDisplay:nil];
532 /* populate the modulus popup here */
533 [fModulusPopUp removeAllItems];
534 [fModulusPopUp addItemWithTitle: @"16"];
535 [fModulusPopUp addItemWithTitle: @"8"];
536 [fModulusPopUp addItemWithTitle: @"4"];
537 [fModulusPopUp addItemWithTitle: @"2"];
538 if (job->anamorphic.mode == 3)
540 [fModulusPopUp selectItemWithTitle: [NSString stringWithFormat:@"%d",job->anamorphic.modulus]];
544 [fModulusPopUp selectItemWithTitle: @"16"];
547 /* We initially set the previous state of keep ar to on */
548 keepAspectRatioPreviousState = 1;
551 [fCropMatrix selectCellAtRow: 1 column:0];
552 /* If auto, lets set the crop steppers according to current job->crop values */
553 [fCropTopStepper setIntValue: job->crop[0]];
554 [fCropTopField setIntValue: job->crop[0]];
555 [fCropBottomStepper setIntValue: job->crop[1]];
556 [fCropBottomField setIntValue: job->crop[1]];
557 [fCropLeftStepper setIntValue: job->crop[2]];
558 [fCropLeftField setIntValue: job->crop[2]];
559 [fCropRightStepper setIntValue: job->crop[3]];
560 [fCropRightField setIntValue: job->crop[3]];
564 [fCropMatrix selectCellAtRow: 0 column:0];
567 /* Set filters widgets according to the filters struct */
568 [fDetelecinePopUp selectItemAtIndex:fPictureFilterSettings.detelecine];
569 [fDecombPopUp selectItemAtIndex:fPictureFilterSettings.decomb];
570 [fDeinterlacePopUp selectItemAtIndex: fPictureFilterSettings.deinterlace];
571 [fDenoisePopUp selectItemAtIndex: fPictureFilterSettings.denoise];
572 [fDeblockSlider setFloatValue:fPictureFilterSettings.deblock];
573 [fGrayscaleCheck setState:fPictureFilterSettings.grayscale];
575 [self deblockSliderChanged: nil];
578 MaxOutputWidth = title->width - job->crop[2] - job->crop[3];
579 MaxOutputHeight = title->height - job->crop[0] - job->crop[1];
581 titleDarWidth = job->anamorphic.dar_width;
582 titleDarHeight = job->anamorphic.dar_height;
584 titleParWidth = job->anamorphic.par_width;
585 titleParHeight = job->anamorphic.par_height;
587 [self SettingsChanged: nil];
590 - (IBAction) storageLinkChanged: (id) sender
592 /* since we have a tickless slider, make sure we are at 0.0 or 1.0 */
593 if ([fStorageLinkSlider floatValue] < 0.50)
595 [fStorageLinkSlider setFloatValue:0.0];
596 /* set slider labels to reflect choice */
597 [fStorageLinkParLabel setEnabled:YES];
598 [fStorageLinkDisplayLabel setEnabled:NO];
603 [fStorageLinkSlider setFloatValue:1.0];
604 /* set slider labels to reflect choice */
605 [fStorageLinkParLabel setEnabled:NO];
606 [fStorageLinkDisplayLabel setEnabled:YES];
611 - (IBAction) parLinkChanged: (id) sender
613 /* since we have a tickless slider, make sure we are at 0.0 or 1.0 */
614 if ([fParLinkSlider floatValue] < 0.50)
616 [fParLinkSlider setFloatValue:0.0];
617 /* set slider labels to reflect choice */
618 [fParLinkStorageLabel setEnabled:YES];
619 [fParLinkDisplayLabel setEnabled:NO];
623 [fParLinkSlider setFloatValue:1.0];
624 /* set slider labels to reflect choice */
625 [fParLinkStorageLabel setEnabled:NO];
626 [fParLinkDisplayLabel setEnabled:YES];
631 - (IBAction) displayLinkChanged: (id) sender
633 /* since we have a tickless slider, make sure we are at 0.0 or 1.0 */
634 if ([fDisplayLinkSlider floatValue] < 0.50)
636 [fDisplayLinkSlider setFloatValue:0.0];
637 /* set slider labels to reflect choice */
638 [fDisplayLinkStorageLabel setEnabled:YES];
639 [fDisplayLinkParLabel setEnabled:NO];
643 [fDisplayLinkSlider setFloatValue:1.0];
644 /* set slider labels to reflect choice */
645 [fDisplayLinkStorageLabel setEnabled:NO];
646 [fDisplayLinkParLabel setEnabled:YES];
651 - (IBAction) SettingsChanged: (id) sender
653 hb_job_t * job = fTitle->job;
654 [fModulusPopUp setEnabled:NO];
655 job->anamorphic.modulus = 16;
657 /* Since custom anamorphic allows for a height setting > fTitle->height
658 * check to make sure it is returned to fTitle->height for all other modes
660 [fHeightStepper setMaxValue: fTitle->height];
662 autoCrop = ( [fCropMatrix selectedRow] == 0 );
663 [fCropTopStepper setEnabled: !autoCrop];
664 [fCropBottomStepper setEnabled: !autoCrop];
665 [fCropLeftStepper setEnabled: !autoCrop];
666 [fCropRightStepper setEnabled: !autoCrop];
670 memcpy( job->crop, fTitle->crop, 4 * sizeof( int ) );
674 job->crop[0] = [fCropTopStepper intValue];
675 job->crop[1] = [fCropBottomStepper intValue];
676 job->crop[2] = [fCropLeftStepper intValue];
677 job->crop[3] = [fCropRightStepper intValue];
680 [fRatioCheck setEnabled: YES];
683 [fParWidthField setEnabled: NO];
684 [fParHeightField setEnabled: NO];
685 [fDisplayWidthField setEnabled: NO];
687 /* If we are not custom anamorphic, make sure we retain the orginal par */
688 if( [fAnamorphicPopUp indexOfSelectedItem] != 3 )
690 job->anamorphic.par_width = titleParWidth;
691 job->anamorphic.par_height = titleParHeight;
692 [fRatioLabel setHidden: NO];
694 [fWidthStepper setIncrement: 16];
695 [fHeightStepper setIncrement: 16];
699 [fWidthStepper setIncrement: [[fModulusPopUp titleOfSelectedItem] intValue]];
700 [fHeightStepper setIncrement: [[fModulusPopUp titleOfSelectedItem] intValue]];
703 if( [fAnamorphicPopUp indexOfSelectedItem] > 0 )
705 if ([fAnamorphicPopUp indexOfSelectedItem] == 1) // strict
707 [fWidthStepper setIntValue: fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3]];
708 [fWidthField setIntValue: fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3]];
710 /* This will show correct anamorphic height values, but
711 show distorted preview picture ratio */
712 [fHeightStepper setIntValue: fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1]];
713 [fHeightField setIntValue: fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1]];
714 job->width = [fWidthStepper intValue];
715 job->height = [fHeightStepper intValue];
717 job->anamorphic.mode = 1;
718 [fWidthStepper setEnabled: NO];
719 [fWidthField setEnabled: NO];
720 [fHeightStepper setEnabled: NO];
721 [fHeightField setEnabled: NO];
723 else if ([fAnamorphicPopUp indexOfSelectedItem] == 2) // Loose anamorphic
725 job->anamorphic.mode = 2;
726 [fWidthStepper setEnabled: YES];
727 [fWidthField setEnabled: YES];
728 [fRatioCheck setEnabled: NO];
729 [fHeightStepper setEnabled: NO];
730 [fHeightField setEnabled: NO];
731 /* We set job->width and call hb_set_anamorphic_size in libhb to do a "dry run" to get
732 * the values to be used by libhb for loose anamorphic
734 /* if the sender is the anamorphic popup, then we know that loose anamorphic has just
735 * been turned on, so snap the width to full width for the source.
737 if (sender == fAnamorphicPopUp)
739 [fWidthStepper setIntValue: fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3]];
740 [fWidthField setIntValue: fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3]];
742 job->width = [fWidthStepper intValue];
743 hb_set_anamorphic_size(job, &output_width, &output_height, &output_par_width, &output_par_height);
744 [fHeightStepper setIntValue: output_height];
745 [fHeightField setIntValue: output_height];
746 job->height = [fHeightStepper intValue];
749 else if ([fAnamorphicPopUp indexOfSelectedItem] == 3) // custom / power user jamboree
752 #pragma mark - STARTCapuj
754 job->anamorphic.mode = 3;
756 /* Set the status of our custom ana only widgets accordingly */
757 /* for mod 3 we can use modulus other than 16 */
758 [fModulusPopUp setEnabled:YES];
759 job->anamorphic.modulus = [[fModulusPopUp titleOfSelectedItem] intValue];
761 [fWidthStepper setEnabled: YES];
762 [fWidthField setEnabled: YES];
764 [fHeightStepper setEnabled: YES];
765 /* for capuj the storage field is immaterial */
766 [fHeightField setEnabled: YES];
768 [fRatioCheck setEnabled: YES];
769 if (sender == fRatioCheck)
771 if ([fRatioCheck state] == NSOnState)
773 [fParWidthField setEnabled: NO];
774 [fParHeightField setEnabled: NO];
778 [fParWidthField setEnabled: YES];
779 [fParHeightField setEnabled: YES];
783 [fParWidthField setEnabled: YES];
784 [fParHeightField setEnabled: YES];
786 [fDisplayWidthField setEnabled: YES];
789 /* If we are coming into custom ana or if in custom ana and the
790 * keep ar checkbox is checked, we reset the par to original
791 * which gives us a way back if things are hosed up
794 if (sender == fAnamorphicPopUp || (sender == fRatioCheck && [fRatioCheck state] == NSOnState))
796 if (sender == fAnamorphicPopUp)
798 [fRatioCheck setState: NSOnState];
803 Disable editing: PIXEL WIDTH, PIXEL HEIGHT
805 [fParWidthField setEnabled: NO];
806 [fParHeightField setEnabled: NO];
808 job->width = [fWidthStepper intValue];
809 job->height = [fHeightStepper intValue];
811 /* make sure our par is set back to original */
812 job->anamorphic.par_width = titleParWidth;
813 job->anamorphic.par_height = titleParHeight;
815 [fParWidthField setIntValue: titleParWidth];
816 [fParHeightField setIntValue: titleParHeight];
818 /* modify our par dims from our storage dims */
819 hb_set_anamorphic_size(job, &output_width, &output_height, &output_par_width, &output_par_height);
820 float par_display_width = (float)output_width * (float)output_par_width / (float)output_par_height;
822 /* go ahead and mod the display dims */
823 [fDisplayWidthField setStringValue: [NSString stringWithFormat:@"%.2f", par_display_width]];
825 job->anamorphic.dar_width = [fDisplayWidthField floatValue];
826 job->anamorphic.dar_height = (float)[fHeightStepper intValue];
828 /* Set our dar here assuming we are just coming into capuj mode */
829 dar = [fDisplayWidthField floatValue] / (float)[fHeightField intValue];
833 /* For capuj we disable these fields if we are keeping the dispay aspect */
834 if ([fRatioCheck state] == NSOnState)
838 DAR = DISPLAY WIDTH / DISPLAY HEIGHT (cache after every modification) */
839 /*Disable editing: PIXEL WIDTH, PIXEL HEIGHT */
841 [fParWidthField setEnabled: NO];
842 [fParHeightField setEnabled: NO];
844 /* Changing DISPLAY WIDTH: */
845 if (sender == fDisplayWidthField)
847 job->anamorphic.dar_width = [fDisplayWidthField floatValue];
848 /* Changes HEIGHT to keep DAR */
849 /* calculate the height to retain the dar */
850 int raw_calulated_height = (int)((int)[fDisplayWidthField floatValue] / dar);
851 /* now use the modulus to go lower if there is a remainder */
852 /* Note to me, raw_calulated_height % [[fModulusPopUp titleOfSelectedItem] intValue]
853 * gives me the remainder we are not mod (whatever our modulus is) subtract that from
854 * the actual calculated value derived from the dar to round down to the nearest mod value.
855 * This should be desireable over rounding up to the next mod value
857 int modulus_height = raw_calulated_height - (raw_calulated_height % [[fModulusPopUp titleOfSelectedItem] intValue]);
858 if (modulus_height > fTitle->height)
860 [fHeightStepper setMaxValue: modulus_height];
862 [fHeightStepper setIntValue: modulus_height];
863 job->anamorphic.dar_height = (float)[fHeightStepper intValue];
864 job->height = [fHeightStepper intValue];
866 /* Changes PIXEL WIDTH to new DISPLAY WIDTH */
867 [fParWidthField setIntValue: [fDisplayWidthField intValue]];
868 job->anamorphic.par_width = [fParWidthField intValue];
869 /* Changes PIXEL HEIGHT to STORAGE WIDTH */
870 [fParHeightField setIntValue: [fWidthField intValue]];
871 job->anamorphic.par_height = [fParHeightField intValue];
874 /* Changing HEIGHT: */
875 if (sender == fHeightStepper)
877 job->anamorphic.dar_height = (float)[fHeightStepper intValue];
878 job->height = [fHeightStepper intValue];
880 /* Changes DISPLAY WIDTH to keep DAR*/
881 [fDisplayWidthField setStringValue: [NSString stringWithFormat: @"%.2f",[fHeightStepper intValue] * dar]];
882 job->anamorphic.dar_width = [fDisplayWidthField floatValue];
883 /* Changes PIXEL WIDTH to new DISPLAY WIDTH */
884 [fParWidthField setIntValue: [fDisplayWidthField intValue]];
885 job->anamorphic.par_width = [fParWidthField intValue];
886 /* Changes PIXEL HEIGHT to STORAGE WIDTH */
887 [fParHeightField setIntValue: [fWidthField intValue]];
888 job->anamorphic.par_height = [fParHeightField intValue];
890 /* Changing STORAGE_WIDTH: */
891 if (sender == fWidthStepper)
893 job->width = [fWidthStepper intValue];
895 job->anamorphic.dar_width = [fDisplayWidthField floatValue];
896 job->anamorphic.dar_height = [fHeightStepper floatValue];
898 /* Changes PIXEL WIDTH to DISPLAY WIDTH */
899 [fParWidthField setIntValue: [fDisplayWidthField intValue]];
900 job->anamorphic.par_width = [fParWidthField intValue];
901 /* Changes PIXEL HEIGHT to new STORAGE WIDTH */
902 [fParHeightField setIntValue: [fWidthStepper intValue]];
903 job->anamorphic.par_height = [fParHeightField intValue];
906 else if ([fRatioCheck state] == NSOffState)
908 /* Changing STORAGE_WIDTH: */
909 if (sender == fWidthStepper)
911 job->width = [fWidthStepper intValue];
912 /* changes DISPLAY WIDTH to STORAGE WIDTH * PIXEL WIDTH / PIXEL HEIGHT */
913 [fDisplayWidthField setStringValue: [NSString stringWithFormat: @"%.2f",(float)[fWidthStepper intValue] * [fParWidthField intValue] / [fParHeightField intValue]]];
914 job->anamorphic.dar_width = [fDisplayWidthField floatValue];
916 /* Changing PIXEL dimensions */
917 if (sender == fParWidthField || sender == fParHeightField)
919 job->anamorphic.par_width = [fParWidthField intValue];
920 job->anamorphic.par_height = [fParHeightField intValue];
921 /* changes DISPLAY WIDTH to STORAGE WIDTH * PIXEL WIDTH / PIXEL HEIGHT */
922 [fDisplayWidthField setStringValue: [NSString stringWithFormat: @"%.2f",(float)[fWidthStepper intValue] * [fParWidthField intValue] / [fParHeightField intValue]]];
923 job->anamorphic.dar_width = [fDisplayWidthField floatValue];
925 /* Changing DISPLAY WIDTH: */
926 if (sender == fDisplayWidthField)
928 job->anamorphic.dar_width = [fDisplayWidthField floatValue];
929 job->anamorphic.dar_height = (float)[fHeightStepper intValue];
930 /* changes PIXEL WIDTH to DISPLAY WIDTH and PIXEL HEIGHT to STORAGE WIDTH */
931 [fParWidthField setIntValue: [fDisplayWidthField intValue]];
932 job->anamorphic.par_width = [fParWidthField intValue];
934 [fParHeightField setIntValue: [fWidthField intValue]];
935 job->anamorphic.par_height = [fParHeightField intValue];
936 hb_set_anamorphic_size(job, &output_width, &output_height, &output_par_width, &output_par_height);
938 /* Changing HEIGHT: */
939 if (sender == fHeightStepper)
941 /* just....changes the height.*/
942 job->anamorphic.dar_height = [fHeightStepper intValue];
943 job->height = [fHeightStepper intValue];
948 #pragma mark - END Capuj
951 /* if the sender is the Anamorphic checkbox, record the state
952 of KeepAspect Ratio so it can be reset if Anamorphic is unchecked again */
953 if (sender == fAnamorphicPopUp)
955 keepAspectRatioPreviousState = [fRatioCheck state];
957 if ([fAnamorphicPopUp indexOfSelectedItem] != 3)
959 [fRatioCheck setState:NSOffState];
965 job->width = [fWidthStepper intValue];
966 job->height = [fHeightStepper intValue];
967 job->anamorphic.mode = 0;
968 [fWidthStepper setEnabled: YES];
969 [fWidthField setEnabled: YES];
970 [fHeightStepper setEnabled: YES];
971 [fHeightField setEnabled: YES];
972 [fRatioCheck setEnabled: YES];
973 /* if the sender is the Anamorphic checkbox, we return the
974 keep AR checkbox to its previous state */
975 if (sender == fAnamorphicPopUp)
977 [fRatioCheck setState:keepAspectRatioPreviousState];
982 //job->keep_ratio = ( [fRatioCheck state] == NSOnState );
984 if ([fAnamorphicPopUp indexOfSelectedItem] != 3)
986 job->keep_ratio = ( [fRatioCheck state] == NSOnState );
987 if( job->keep_ratio )
989 if( sender == fWidthStepper || sender == fRatioCheck ||
990 sender == fCropTopStepper || sender == fCropBottomStepper )
992 hb_fix_aspect( job, HB_KEEP_WIDTH );
993 if( job->height > fTitle->height )
995 job->height = fTitle->height;
996 hb_fix_aspect( job, HB_KEEP_HEIGHT );
1001 hb_fix_aspect( job, HB_KEEP_HEIGHT );
1002 if( job->width > fTitle->width )
1004 job->width = fTitle->width;
1005 hb_fix_aspect( job, HB_KEEP_WIDTH );
1012 // hb_get_preview can't handle sizes that are larger than the original title
1013 if ([fAnamorphicPopUp indexOfSelectedItem] != 3)
1016 if( job->width > fTitle->width )
1018 job->width = fTitle->width;
1021 if( job->height > fTitle->height )
1023 job->height = fTitle->height;
1027 [fWidthStepper setIntValue: job->width];
1028 [fWidthField setIntValue: job->width];
1029 if( [fAnamorphicPopUp indexOfSelectedItem] != 2) // if we are not loose or custom
1031 [fHeightStepper setIntValue: job->height];
1032 [fHeightField setIntValue: job->height];
1035 [fCropTopStepper setIntValue: job->crop[0]];
1036 [fCropTopField setIntValue: job->crop[0]];
1037 [fCropBottomStepper setIntValue: job->crop[1]];
1038 [fCropBottomField setIntValue: job->crop[1]];
1039 [fCropLeftStepper setIntValue: job->crop[2]];
1040 [fCropLeftField setIntValue: job->crop[2]];
1041 [fCropRightStepper setIntValue: job->crop[3]];
1042 [fCropRightField setIntValue: job->crop[3]];
1044 //[fPreviewController SetTitle:fTitle];
1046 /* Sanity Check Here for < 16 px preview to avoid
1047 crashing hb_get_preview. In fact, just for kicks
1048 lets getting previews at a min limit of 32, since
1049 no human can see any meaningful detail below that */
1050 if (job->width >= 64 && job->height >= 64)
1052 [self reloadStillPreview];
1055 /* we get the sizing info to display from fPreviewController */
1056 [fSizeInfoField setStringValue: [fPreviewController pictureSizeInfoString]];
1060 [fHBController pictureSettingsDidChange];
1063 if ([[self window] isVisible])
1065 [self adjustSizingDisplay:nil];
1070 - (NSString*) getPictureSizeInfoString
1072 return [fSizeInfoField stringValue];
1075 - (void)reloadStillPreview
1077 hb_job_t * job = fTitle->job;
1079 [fPreviewController SetTitle:fTitle];
1080 /* Sanity Check Here for < 16 px preview to avoid
1081 crashing hb_get_preview. In fact, just for kicks
1082 lets getting previews at a min limit of 32, since
1083 no human can see any meaningful detail below that */
1084 if (job->width >= 64 && job->height >= 64)
1087 // Purge the existing picture previews so they get recreated the next time
1089 // [fPreviewController purgeImageCache];
1090 /* We actually call displayPreview now from pictureSliderChanged which keeps
1091 * our picture preview slider in sync with the previews being shown
1094 //[fPreviewController pictureSliderChanged:nil];
1106 - (void) setAutoCrop: (BOOL) setting
1111 - (BOOL) allowLooseAnamorphic
1113 return allowLooseAnamorphic;
1116 - (void) setAllowLooseAnamorphic: (BOOL) setting
1118 allowLooseAnamorphic = setting;
1121 - (IBAction)showPreviewPanel: (id)sender forTitle: (hb_title_t *)title
1123 //[self SetTitle:title];
1124 [self showWindow:sender];
1125 //[self adjustSizingDisplay:nil];
1126 //[self adjustFilterDisplay:nil];
1132 /* we use this to setup the initial picture filters upon first launch, after that their states
1133 are maintained across different sources */
1134 - (void) setInitialPictureFilters
1136 /* we use a popup to show the detelecine settings */
1137 [fDetelecinePopUp removeAllItems];
1138 [fDetelecinePopUp addItemWithTitle: @"Off"];
1139 [fDetelecinePopUp addItemWithTitle: @"Default"];
1140 [fDetelecinePopUp addItemWithTitle: @"Custom"];
1141 [fDetelecinePopUp selectItemAtIndex: fPictureFilterSettings.detelecine];
1143 [self modeDecombDeinterlaceSliderChanged:nil];
1144 /* we use a popup to show the decomb settings */
1145 [fDecombPopUp removeAllItems];
1146 [fDecombPopUp addItemWithTitle: @"Off"];
1147 [fDecombPopUp addItemWithTitle: @"Default"];
1148 [fDecombPopUp addItemWithTitle: @"Custom"];
1149 [fDecombPopUp selectItemAtIndex: fPictureFilterSettings.decomb];
1151 /* we use a popup to show the deinterlace settings */
1152 [fDeinterlacePopUp removeAllItems];
1153 [fDeinterlacePopUp addItemWithTitle: @"None"];
1154 [fDeinterlacePopUp addItemWithTitle: @"Fast"];
1155 [fDeinterlacePopUp addItemWithTitle: @"Slow"];
1156 [fDeinterlacePopUp addItemWithTitle: @"Slower"];
1157 [fDeinterlacePopUp addItemWithTitle: @"Custom"];
1159 /* Set deinterlaces level according to the integer in the main window */
1160 [fDeinterlacePopUp selectItemAtIndex: fPictureFilterSettings.deinterlace];
1162 /* we use a popup to show the denoise settings */
1163 [fDenoisePopUp removeAllItems];
1164 [fDenoisePopUp addItemWithTitle: @"None"];
1165 [fDenoisePopUp addItemWithTitle: @"Weak"];
1166 [fDenoisePopUp addItemWithTitle: @"Medium"];
1167 [fDenoisePopUp addItemWithTitle: @"Strong"];
1168 [fDenoisePopUp addItemWithTitle: @"Custom"];
1169 /* Set denoises level according to the integer in the main window */
1170 [fDenoisePopUp selectItemAtIndex: fPictureFilterSettings.denoise];
1178 - (IBAction) modeDecombDeinterlaceSliderChanged: (id) sender
1181 /* since its a tickless slider, we have to make sure we are on or off */
1182 if ([fDecombDeinterlaceSlider floatValue] < 0.50)
1184 [fDecombDeinterlaceSlider setFloatValue:0.0];
1188 [fDecombDeinterlaceSlider setFloatValue:1.0];
1192 /* Decomb selected*/
1193 if ([fDecombDeinterlaceSlider floatValue] == 0.0)
1195 [fDecombBox setHidden:NO];
1196 [fDeinterlaceBox setHidden:YES];
1197 fPictureFilterSettings.decomb = [fDecombPopUp indexOfSelectedItem];
1198 fPictureFilterSettings.usedecomb = 1;
1199 fPictureFilterSettings.deinterlace = 0;
1200 [fDecombPopUp selectItemAtIndex:fPictureFilterSettings.decomb];
1201 [self adjustFilterDisplay:fDecombPopUp];
1205 [fDecombBox setHidden:YES];
1206 [fDeinterlaceBox setHidden:NO];
1207 fPictureFilterSettings.usedecomb = 0;
1208 fPictureFilterSettings.decomb = 0;
1209 [fDeinterlacePopUp selectItemAtIndex: fPictureFilterSettings.deinterlace];
1210 [self adjustFilterDisplay:fDeinterlacePopUp];
1212 [self FilterSettingsChanged: fDecombDeinterlaceSlider];
1216 - (IBAction) FilterSettingsChanged: (id) sender
1219 fPictureFilterSettings.detelecine = [fDetelecinePopUp indexOfSelectedItem];
1220 [self adjustFilterDisplay:fDetelecinePopUp];
1222 fPictureFilterSettings.decomb = [fDecombPopUp indexOfSelectedItem];
1223 [self adjustFilterDisplay:fDecombPopUp];
1225 fPictureFilterSettings.deinterlace = [fDeinterlacePopUp indexOfSelectedItem];
1226 [self adjustFilterDisplay:fDeinterlacePopUp];
1228 fPictureFilterSettings.denoise = [fDenoisePopUp indexOfSelectedItem];
1229 [self adjustFilterDisplay:fDenoisePopUp];
1231 if ([fDeblockField stringValue] == @"Off")
1233 fPictureFilterSettings.deblock = 0;
1237 fPictureFilterSettings.deblock = [fDeblockField intValue];
1240 fPictureFilterSettings.grayscale = [fGrayscaleCheck state];
1244 [fHBController pictureSettingsDidChange];
1253 - (IBAction) deblockSliderChanged: (id) sender
1255 if ([fDeblockSlider floatValue] == 4.0)
1257 [fDeblockField setStringValue: [NSString stringWithFormat: @"Off"]];
1261 [fDeblockField setStringValue: [NSString stringWithFormat: @"%.0f", [fDeblockSlider floatValue]]];
1263 [self FilterSettingsChanged: sender];
1269 return fPictureFilterSettings.detelecine;
1272 - (NSString*) detelecineCustomString
1274 return [fDetelecineField stringValue];
1277 - (void) setDetelecine: (int) setting
1279 fPictureFilterSettings.detelecine = setting;
1282 - (void) setDetelecineCustomString: (NSString*) string
1284 [fDetelecineField setStringValue:string];
1289 return fPictureFilterSettings.deinterlace;
1291 - (NSString*) deinterlaceCustomString
1293 return [fDeinterlaceField stringValue];
1296 - (void) setDeinterlaceCustomString: (NSString*) string
1298 [fDeinterlaceField setStringValue:string];
1301 - (void) setDeinterlace: (int) setting
1303 fPictureFilterSettings.deinterlace = setting;
1307 return fPictureFilterSettings.decomb;
1310 - (NSString*) decombCustomString
1312 return [fDecombField stringValue];
1317 return fPictureFilterSettings.usedecomb;
1320 - (void) setUseDecomb: (int) setting
1322 fPictureFilterSettings.usedecomb = setting;
1323 if (fPictureFilterSettings.usedecomb == 1)
1325 [fDecombDeinterlaceSlider setFloatValue:0.0];
1329 [fDecombDeinterlaceSlider setFloatValue:1.0];
1331 [self modeDecombDeinterlaceSliderChanged:nil];
1334 - (void) setDecomb: (int) setting {
1335 fPictureFilterSettings.decomb = setting;
1338 - (void) setDecombCustomString: (NSString*) string
1340 [fDecombField setStringValue:string];
1345 return fPictureFilterSettings.denoise;
1348 - (NSString*) denoiseCustomString
1350 return [fDenoiseField stringValue];
1353 - (void) setDenoiseCustomString: (NSString*) string
1355 [fDenoiseField setStringValue:string];
1358 - (void) setDenoise: (int) setting
1360 fPictureFilterSettings.denoise = setting;
1365 return fPictureFilterSettings.deblock;
1368 - (void) setDeblock: (int) setting
1370 fPictureFilterSettings.deblock = setting;
1375 return fPictureFilterSettings.grayscale;
1378 - (void) setGrayscale: (int) setting
1380 fPictureFilterSettings.grayscale = setting;