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 );
77 [fWidthStepper setMaxValue: title->width];
78 [fWidthStepper setIntValue: job->width];
79 [fWidthField setIntValue: job->width];
80 [fHeightStepper setMaxValue: title->height];
81 [fHeightStepper setIntValue: job->height];
82 [fHeightField setIntValue: job->height];
83 [fRatioCheck setState: job->keep_ratio ? NSOnState : NSOffState];
84 [fCropTopStepper setMaxValue: title->height/2-2];
85 [fCropBottomStepper setMaxValue: title->height/2-2];
86 [fCropLeftStepper setMaxValue: title->width/2-2];
87 [fCropRightStepper setMaxValue: title->width/2-2];
88 [fDeinterlaceCheck setState: job->deinterlace ? NSOnState : NSOffState];
89 [fPARCheck setState: job->pixel_ratio ? NSOnState : NSOffState];
91 MaxOutputWidth = job->width;
92 MaxOutputHeight = job->height;
94 [self SettingsChanged: nil];
97 - (void) Display: (int) anim
99 hb_get_preview( fHandle, fTitle, fPicture, fBuffer );
101 /* Backup previous picture (for effects) */
102 memcpy( fTexBuf[1], fTexBuf[0], fTexBufSize );
107 memcpy( fTexBuf[0], fBuffer, fTexBufSize );
111 /* Copy line by line */
112 uint8_t * in = fBuffer;
113 uint8_t * out = fTexBuf[0];
115 for( int i = fTitle->height + 2; i--; )
117 memcpy( out, in, 4 * ( fTitle->width + 2 ) );
118 in += 4 * ( fTitle->width + 2 );
119 out += 4 * GetAlignedSize( fTitle->width + 2 );
124 if( [fEffectsCheck state] == NSOffState )
126 anim = HB_ANIMATE_NONE;
128 else if( [[NSApp currentEvent] modifierFlags] & NSShiftKeyMask )
130 anim |= HB_ANIMATE_SLOW;
133 [fPictureGLView Display: anim buffer1: fTexBuf[0]
134 buffer2: fTexBuf[1] width: ( fTitle->width + 2 )
135 height: ( fTitle->height + 2 )];
137 /* Set the Output Display below the Preview Picture*/
138 int titlewidth = fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3];
139 int arpwidth = fTitle->job->pixel_aspect_width;
140 int arpheight = fTitle->job->pixel_aspect_height;
141 int displayparwidth = titlewidth * arpwidth / arpheight;
142 int displayparheight = fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1];
143 if (fTitle->job->pixel_ratio == 1)
146 [fInfoField setStringValue: [NSString stringWithFormat:
147 @"Source: %dx%d, Output: %dx%d, Anamorphic: %dx%d", fTitle->width, fTitle->height,
148 MaxOutputWidth, displayparheight, displayparwidth,
155 [fInfoField setStringValue: [NSString stringWithFormat:
156 @"Source: %dx%d, Output: %dx%d", fTitle->width, fTitle->height,
157 fTitle->job->width, fTitle->job->height]];
161 [fPrevButton setEnabled: ( fPicture > 0 )];
162 [fNextButton setEnabled: ( fPicture < 9 )];
165 - (IBAction) SettingsChanged: (id) sender
167 hb_job_t * job = fTitle->job;
169 if ([fPARCheck state] == 1 )
171 [fWidthStepper setIntValue: MaxOutputWidth];
172 [fWidthField setIntValue: MaxOutputWidth];
174 /* This will show correct anamorphic height values, but
175 show distorted preview picture ratio */
176 [fHeightStepper setIntValue: fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1]];
177 [fHeightField setIntValue: fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1]];
179 /* This will show wrong anamorphic height values, but
180 show proper preview picture ratio */
181 //[fHeightStepper setIntValue: MaxOutputHeight];
182 //[fHeightField setIntValue: MaxOutputHeight];
183 [fRatioCheck setState: 0];
185 [fWidthStepper setEnabled: NO];
186 [fWidthField setEnabled: NO];
187 [fHeightStepper setEnabled: NO];
188 [fHeightField setEnabled: NO];
189 [fRatioCheck setEnabled: NO];
195 [fWidthStepper setEnabled: YES];
196 [fWidthField setEnabled: YES];
197 [fHeightStepper setEnabled: YES];
198 [fHeightField setEnabled: YES];
199 [fRatioCheck setEnabled: YES];
204 job->width = [fWidthStepper intValue];
205 job->height = [fHeightStepper intValue];
206 job->keep_ratio = ( [fRatioCheck state] == NSOnState );
207 job->deinterlace = ( [fDeinterlaceCheck state] == NSOnState );
208 job->pixel_ratio = ( [fPARCheck state] == NSOnState );
212 bool autocrop = ( [fCropMatrix selectedRow] == 0 );
213 [fCropTopStepper setEnabled: !autocrop];
214 [fCropBottomStepper setEnabled: !autocrop];
215 [fCropLeftStepper setEnabled: !autocrop];
216 [fCropRightStepper setEnabled: !autocrop];
219 memcpy( job->crop, fTitle->crop, 4 * sizeof( int ) );
223 job->crop[0] = [fCropTopStepper intValue];
224 job->crop[1] = [fCropBottomStepper intValue];
225 job->crop[2] = [fCropLeftStepper intValue];
226 job->crop[3] = [fCropRightStepper intValue];
229 if( job->keep_ratio )
231 if( sender == fWidthStepper || sender == fRatioCheck ||
232 sender == fCropTopStepper || sender == fCropBottomStepper )
234 hb_fix_aspect( job, HB_KEEP_WIDTH );
235 if( job->height > fTitle->height )
237 job->height = fTitle->height;
238 hb_fix_aspect( job, HB_KEEP_HEIGHT );
243 hb_fix_aspect( job, HB_KEEP_HEIGHT );
244 if( job->width > fTitle->width )
246 job->width = fTitle->width;
247 hb_fix_aspect( job, HB_KEEP_WIDTH );
252 [fWidthStepper setIntValue: job->width];
253 [fWidthField setIntValue: job->width];
254 [fHeightStepper setIntValue: job->height];
255 [fHeightField setIntValue: job->height];
256 [fCropTopStepper setIntValue: job->crop[0]];
257 [fCropTopField setIntValue: job->crop[0]];
258 [fCropBottomStepper setIntValue: job->crop[1]];
259 [fCropBottomField setIntValue: job->crop[1]];
260 [fCropLeftStepper setIntValue: job->crop[2]];
261 [fCropLeftField setIntValue: job->crop[2]];
262 [fCropRightStepper setIntValue: job->crop[3]];
263 [fCropRightField setIntValue: job->crop[3]];
264 [self Display: HB_ANIMATE_NONE];
267 - (IBAction) PreviousPicture: (id) sender
274 [self Display: HB_ANIMATE_BACKWARD];
277 - (IBAction) NextPicture: (id) sender
284 [self Display: HB_ANIMATE_FORWARD];
287 - (IBAction) ClosePanel: (id) sender