OSDN Git Service

MacGui: Use nil instead of NULL. Patch by blindjimmy. http://handbrake.djgraphite...
[handbrake-jp/handbrake-jp-git.git] / macosx / PictureController.mm
index fc356c7..2f2f51c 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id: PictureController.mm,v 1.11 2005/08/01 15:10:44 titer Exp $
 
    This file is part of the HandBrake source code.
-   Homepage: <http://handbrake.m0k.org/>.
+   Homepage: <http://handbrake.fr/>.
    It may be used under the terms of the GNU General Public License. */
 
 #include "PictureController.h"
 
 - (id)initWithDelegate:(id)del
 {
-       if (self = [super init])
+       if (self = [super initWithWindowNibName:@"PictureSettings"])
        {
+        // NSWindowController likes to lazily load its window. However since
+        // this controller tries to set all sorts of outlets before the window
+        // is displayed, we need it to load immediately. The correct way to do
+        // this, according to the documentation, is simply to invoke the window
+        // getter once.
+        //
+        // If/when we switch a lot of this stuff to bindings, this can probably
+        // go away.
+        [self window];
+
                delegate = del;
-        [self loadMyNibFile];
         fPicturePreviews = [[NSMutableDictionary dictionaryWithCapacity: HB_NUM_HBLIB_PICTURES] retain];
        }
        return self;
@@ -126,7 +135,6 @@ are maintained across different sources */
     [fDeinterlacePopUp addItemWithTitle: @"Fast"];
     [fDeinterlacePopUp addItemWithTitle: @"Slow"];
        [fDeinterlacePopUp addItemWithTitle: @"Slower"];
-       [fDeinterlacePopUp addItemWithTitle: @"Slowest"];
     
        /* Set deinterlaces level according to the integer in the main window */
        [fDeinterlacePopUp selectItemAtIndex: fPictureFilterSettings.deinterlace];
@@ -139,6 +147,14 @@ are maintained across different sources */
     [fDenoisePopUp addItemWithTitle: @"Strong"];
        /* Set denoises level according to the integer in the main window */
        [fDenoisePopUp selectItemAtIndex: fPictureFilterSettings.denoise];
+    
+    /* we use a popup to show the decomb settings */
+       [fDecombPopUp removeAllItems];
+    [fDecombPopUp addItemWithTitle: @"None"];
+    [fDecombPopUp addItemWithTitle: @"Default"];
+    [fDecombPopUp addItemWithTitle: @"Custom"];
+       /* Set denoises level according to the integer in the main window */
+       [fDecombPopUp selectItemAtIndex: fPictureFilterSettings.decomb];
 
 }
 
@@ -305,8 +321,9 @@ are maintained across different sources */
     }
     fPictureFilterSettings.detelecine  = [fDetelecineCheck state];
     fPictureFilterSettings.deblock  = [fDeblockCheck state];
-       //job->pixel_ratio = ( [fPARCheck state] == NSOnState );
     
+    fPictureFilterSettings.decomb = [fDecombPopUp indexOfSelectedItem];
+       
     autoCrop = ( [fCropMatrix selectedRow] == 0 );
     [fCropTopStepper    setEnabled: !autoCrop];
     [fCropBottomStepper setEnabled: !autoCrop];
@@ -400,9 +417,9 @@ are maintained across different sources */
 {
     if ([delegate respondsToSelector:@selector(pictureSettingsDidChange)])
         [delegate pictureSettingsDidChange];
-        
-    [NSApp endSheet: fPicturePanel];
-    [fPicturePanel orderOut: self];
+
+    [NSApp endSheet:[self window]];
+    [[self window] orderOut:self];
 }
 
 - (BOOL) autoCrop
@@ -452,7 +469,14 @@ are maintained across different sources */
 - (void) setDeinterlace: (int) setting {
     fPictureFilterSettings.deinterlace = setting;
 }
+- (int) decomb
+{
+    return fPictureFilterSettings.decomb;
+}
 
+- (void) setDecomb: (int) setting {
+    fPictureFilterSettings.decomb = setting;
+}
 - (int) denoise
 {
     return fPictureFilterSettings.denoise;
@@ -476,8 +500,8 @@ are maintained across different sources */
 - (void)showPanelInWindow: (NSWindow *)fWindow forTitle: (hb_title_t *)title
 {
     [self SetTitle:title];
-    
-    [NSApp beginSheet:fPicturePanel
+
+    [NSApp beginSheet:[self window]
        modalForWindow:fWindow
         modalDelegate:nil
        didEndSelector:nil
@@ -565,7 +589,11 @@ are maintained across different sources */
         for (int r = 0; r < dstHeight; r++)
         {
             for (int c = 0; c < dstWidth; c++)
+#if TARGET_RT_LITTLE_ENDIAN
                 *dst++ = Endian32_Swap(*src++);
+#else
+                *dst++ = *src++;
+#endif
             src += (srcWidth - dstWidth);   // skip to next row in src
         }
 
@@ -613,7 +641,11 @@ are maintained across different sources */
         UInt32 * src = (UInt32 *)buffer;
         UInt32 * dst = (UInt32 *)[imgrep bitmapData];
         for (int i = 0; i < numPixels; i++)
+#if TARGET_RT_LITTLE_ENDIAN
             *dst++ = Endian32_Swap(*src++);
+#else
+            *dst++ = *src++;
+#endif
 
         NSImage * img = [[[NSImage alloc] initWithSize: NSMakeSize(width, height)] autorelease];
         [img addRepresentation:imgrep];
@@ -647,17 +679,6 @@ are maintained across different sources */
     [fPicturePreviews removeAllObjects];
 }
 
-- (BOOL) loadMyNibFile
-{
-    if(![NSBundle loadNibNamed:@"PictureSettings" owner:self])
-    {
-        NSLog(@"Warning! Could not load myNib file.\n");
-        return NO;
-    }
-    
-    return YES;
-}
-
 @end
 
 @implementation PictureController (Private)
@@ -666,17 +687,17 @@ are maintained across different sources */
 // -[PictureController(Private) optimalViewSizeForImageSize:]
 //
 // Given the size of the preview image to be shown, returns the best possible
-// size for the OpenGL view.
+// size for the view.
 //
 - (NSSize)optimalViewSizeForImageSize: (NSSize)imageSize
 {
     // The min size is 320x240
     float minWidth = 320.0;
     float minHeight = 240.0;
-    
+
     // The max size of the view is when the sheet is taking up 85% of the screen.
     NSSize screenSize = [[NSScreen mainScreen] frame].size;
-    NSSize sheetSize = [fPicturePanel frame].size;
+    NSSize sheetSize = [[self window] frame].size;
     NSSize viewAreaSize = [fPictureViewArea frame].size;
     float paddingX = sheetSize.width - viewAreaSize.width;
     float paddingY = sheetSize.height - viewAreaSize.height;
@@ -714,7 +735,7 @@ are maintained across different sources */
 //
 // -[PictureController(Private) resizePanelForViewSize:animate:]
 //
-// Resizes the entire sheet to accomodate an OpenGL view of a particular size.
+// Resizes the entire sheet to accomodate a view of a particular size.
 //
 - (void)resizeSheetForViewSize: (NSSize)viewSize
 {
@@ -722,11 +743,11 @@ are maintained across different sources */
     NSSize currentSize = [fPictureViewArea frame].size;
     float deltaX = viewSize.width - currentSize.width;
     float deltaY = viewSize.height - currentSize.height;
-    
+
     // Now resize the whole panel by those same deltas, but don't exceed the min
-    NSRect frame = [fPicturePanel frame];
-    NSSize maxSize = [fPicturePanel maxSize];
-    NSSize minSize = [fPicturePanel minSize];
+    NSRect frame = [[self window] frame];
+    NSSize maxSize = [[self window] maxSize];
+    NSSize minSize = [[self window] minSize];
     frame.size.width += deltaX;
     frame.size.height += deltaY;
     if( frame.size.width < minSize.width )
@@ -740,16 +761,19 @@ are maintained across different sources */
 
     // But now the sheet is off-center, so also shift the origin to center it and
     // keep the top aligned.
-    frame.origin.x -= (deltaX / 2.0);
-    frame.origin.y -= deltaY;
+    if( frame.size.width != [[self window] frame].size.width )
+        frame.origin.x -= (deltaX / 2.0);
+
+    if( frame.size.height != [[self window] frame].size.height )
+        frame.origin.y -= deltaY;
 
-    [fPicturePanel setFrame:frame display:YES animate:YES];
+    [[self window] setFrame:frame display:YES animate:YES];
 }
 
 //
 // -[PictureController(Private) setViewSize:]
 //
-// Changes the OpenGL view's size and centers it vertially inside of its area.
+// Changes the view's size and centers it vertically inside of its area.
 // Assumes resizeSheetForViewSize: has already been called.
 //
 - (void)setViewSize: (NSSize)viewSize