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.m0k.org/>.
5 It may be used under the terms of the GNU General Public License. */
7 #include "PictureController.h"
9 static int GetAlignedSize( int size )
12 while( result < size )
19 @implementation PictureController
21 - (void) SetHandle: (hb_handle_t *) handle
25 fHasQE = CGDisplayUsesOpenGLAcceleration( kCGDirectMainDisplay );
33 [fWidthStepper setValueWraps: NO];
34 [fWidthStepper setIncrement: 16];
35 [fWidthStepper setMinValue: 16];
36 [fHeightStepper setValueWraps: NO];
37 [fHeightStepper setIncrement: 16];
38 [fHeightStepper setMinValue: 16];
40 [fCropTopStepper setIncrement: 2];
41 [fCropTopStepper setMinValue: 0];
42 [fCropBottomStepper setIncrement: 2];
43 [fCropBottomStepper setMinValue: 0];
44 [fCropLeftStepper setIncrement: 2];
45 [fCropLeftStepper setMinValue: 0];
46 [fCropRightStepper setIncrement: 2];
47 [fCropRightStepper setMinValue: 0];
50 - (void) SetTitle: (hb_title_t *) title
52 hb_job_t * job = title->job;
56 /* Make sure we have big enough buffers */
58 newSize = ( title->width + 2 ) * (title->height + 2 ) * 4;
59 if( fBufferSize < newSize )
61 fBufferSize = newSize;
62 fBuffer = (uint8_t *) realloc( fBuffer, fBufferSize );
66 newSize = ( GetAlignedSize( title->width + 2 ) *
67 GetAlignedSize( title->height + 2 ) * 4 );
69 if( fTexBufSize < newSize )
71 fTexBufSize = newSize;
72 fTexBuf[0] = (uint8_t *) realloc( fTexBuf[0], fTexBufSize );
73 fTexBuf[1] = (uint8_t *) realloc( fTexBuf[1], fTexBufSize );
76 [fWidthStepper setMaxValue: title->width];
77 [fWidthStepper setIntValue: job->width];
78 [fWidthField setIntValue: job->width];
79 [fHeightStepper setMaxValue: title->height];
80 [fHeightStepper setIntValue: job->height];
81 [fHeightField setIntValue: job->height];
82 [fRatioCheck setState: job->keep_ratio ? NSOnState : NSOffState];
83 [fCropTopStepper setMaxValue: title->height/2-2];
84 [fCropBottomStepper setMaxValue: title->height/2-2];
85 [fCropLeftStepper setMaxValue: title->width/2-2];
86 [fCropRightStepper setMaxValue: title->width/2-2];
87 [fDeinterlaceCheck setState: job->deinterlace ? NSOnState : NSOffState];
90 [self SettingsChanged: nil];
93 - (void) Display: (int) anim
95 hb_get_preview( fHandle, fTitle, fPicture, fBuffer );
97 /* Backup previous picture (for effects) */
98 memcpy( fTexBuf[1], fTexBuf[0], fTexBufSize );
103 memcpy( fTexBuf[0], fBuffer, fTexBufSize );
107 /* Copy line by line */
108 uint8_t * in = fBuffer;
109 uint8_t * out = fTexBuf[0];
110 for( int i = fTitle->height + 2; i--; )
112 memcpy( out, in, 4 * ( fTitle->width + 2 ) );
113 in += 4 * ( fTitle->width + 2 );
114 out += 4 * GetAlignedSize( fTitle->width + 2 );
118 if( [fEffectsCheck state] == NSOffState )
120 anim = HB_ANIMATE_NONE;
122 else if( [[NSApp currentEvent] modifierFlags] & NSShiftKeyMask )
124 anim |= HB_ANIMATE_SLOW;
127 [fPictureGLView Display: anim buffer1: fTexBuf[0]
128 buffer2: fTexBuf[1] width: ( fTitle->width + 2 )
129 height: ( fTitle->height + 2 )];
131 [fInfoField setStringValue: [NSString stringWithFormat:
132 @"Source %dx%d, output %dx%d", fTitle->width, fTitle->height,
133 fTitle->job->width, fTitle->job->height]];
135 [fPrevButton setEnabled: ( fPicture > 0 )];
136 [fNextButton setEnabled: ( fPicture < 9 )];
139 - (IBAction) SettingsChanged: (id) sender
141 hb_job_t * job = fTitle->job;
143 job->width = [fWidthStepper intValue];
144 job->height = [fHeightStepper intValue];
145 job->keep_ratio = ( [fRatioCheck state] == NSOnState );
146 job->deinterlace = ( [fDeinterlaceCheck state] == NSOnState );
148 bool autocrop = ( [fCropMatrix selectedRow] == 0 );
149 [fCropTopStepper setEnabled: !autocrop];
150 [fCropBottomStepper setEnabled: !autocrop];
151 [fCropLeftStepper setEnabled: !autocrop];
152 [fCropRightStepper setEnabled: !autocrop];
155 memcpy( job->crop, fTitle->crop, 4 * sizeof( int ) );
159 job->crop[0] = [fCropTopStepper intValue];
160 job->crop[1] = [fCropBottomStepper intValue];
161 job->crop[2] = [fCropLeftStepper intValue];
162 job->crop[3] = [fCropRightStepper intValue];
165 if( job->keep_ratio )
167 if( sender == fWidthStepper || sender == fRatioCheck ||
168 sender == fCropTopStepper || sender == fCropBottomStepper )
170 hb_fix_aspect( job, HB_KEEP_WIDTH );
171 if( job->height > fTitle->height )
173 job->height = fTitle->height;
174 hb_fix_aspect( job, HB_KEEP_HEIGHT );
179 hb_fix_aspect( job, HB_KEEP_HEIGHT );
180 if( job->width > fTitle->width )
182 job->width = fTitle->width;
183 hb_fix_aspect( job, HB_KEEP_WIDTH );
188 [fWidthStepper setIntValue: job->width];
189 [fWidthField setIntValue: job->width];
190 [fHeightStepper setIntValue: job->height];
191 [fHeightField setIntValue: job->height];
192 [fCropTopStepper setIntValue: job->crop[0]];
193 [fCropTopField setIntValue: job->crop[0]];
194 [fCropBottomStepper setIntValue: job->crop[1]];
195 [fCropBottomField setIntValue: job->crop[1]];
196 [fCropLeftStepper setIntValue: job->crop[2]];
197 [fCropLeftField setIntValue: job->crop[2]];
198 [fCropRightStepper setIntValue: job->crop[3]];
199 [fCropRightField setIntValue: job->crop[3]];
200 [self Display: HB_ANIMATE_NONE];
203 - (IBAction) PreviousPicture: (id) sender
210 [self Display: HB_ANIMATE_BACKWARD];
213 - (IBAction) NextPicture: (id) sender
220 [self Display: HB_ANIMATE_FORWARD];
223 - (IBAction) ClosePanel: (id) sender