OSDN Git Service

Remove MediaForkCLI from .dmg
[handbrake-jp/handbrake-jp-git.git] / macosx / PictureController.mm
1 /* $Id: PictureController.mm,v 1.11 2005/08/01 15:10:44 titer Exp $
2
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. */
6
7 #include "PictureController.h"
8
9 static int GetAlignedSize( int size )
10 {
11     int result = 1;
12     while( result < size )
13     {
14         result *= 2;
15     }
16     return result;
17 }
18
19 @implementation PictureController
20
21 - (void) SetHandle: (hb_handle_t *) handle
22 {
23     fHandle = handle;
24
25     fHasQE = CGDisplayUsesOpenGLAcceleration( kCGDirectMainDisplay );
26
27     fBuffer     = NULL;
28     fBufferSize = 0;
29     fTexBuf[0]  = NULL;
30     fTexBuf[1]  = NULL;
31     fTexBufSize = 0;
32
33     [fWidthStepper  setValueWraps: NO];
34     [fWidthStepper  setIncrement: 16];
35     [fWidthStepper  setMinValue: 16];
36     [fHeightStepper setValueWraps: NO];
37     [fHeightStepper setIncrement: 16];
38     [fHeightStepper setMinValue: 16];
39
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];
48 }
49
50 - (void) SetTitle: (hb_title_t *) title
51 {
52     hb_job_t * job = title->job;
53
54     fTitle = title;
55
56     /* Make sure we have big enough buffers */
57     int newSize;
58     newSize = ( title->width + 2 ) * (title->height + 2 ) * 4;
59     if( fBufferSize < newSize )
60     {
61         fBufferSize = newSize;
62         fBuffer     = (uint8_t *) realloc( fBuffer, fBufferSize );
63     }
64     if( !fHasQE )
65     {
66         newSize = ( GetAlignedSize( title->width + 2 ) *
67             GetAlignedSize( title->height + 2 ) * 4 );
68     }
69     if( fTexBufSize < newSize )
70     {
71         fTexBufSize = newSize;
72         fTexBuf[0]  = (uint8_t *) realloc( fTexBuf[0], fTexBufSize );
73         fTexBuf[1]  = (uint8_t *) realloc( fTexBuf[1], fTexBufSize );
74     }
75
76
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];
90
91     MaxOutputWidth = title->width;
92         MaxOutputHeight = title->height;
93     fPicture = 0;
94     [self SettingsChanged: nil];
95 }
96
97 - (void) Display: (int) anim
98 {
99     hb_get_preview( fHandle, fTitle, fPicture, fBuffer );
100
101     /* Backup previous picture (for effects) */
102     memcpy( fTexBuf[1], fTexBuf[0], fTexBufSize );
103
104     if( fHasQE )
105     {
106         /* Simply copy */
107         memcpy( fTexBuf[0], fBuffer, fTexBufSize );
108     }
109     else
110     {
111         /* Copy line by line */
112         uint8_t * in  = fBuffer;
113         uint8_t * out = fTexBuf[0];
114         for( int i = fTitle->height + 2; i--; )
115         {
116             memcpy( out, in, 4 * ( fTitle->width + 2 ) );
117             in  += 4 * ( fTitle->width + 2 );
118             out += 4 * GetAlignedSize( fTitle->width + 2 );
119         }
120     }
121
122     if( [fEffectsCheck state] == NSOffState )
123     {
124         anim = HB_ANIMATE_NONE;
125     }
126     else if( [[NSApp currentEvent] modifierFlags] & NSShiftKeyMask )
127     {
128         anim |= HB_ANIMATE_SLOW;
129     }
130
131     [fPictureGLView Display: anim buffer1: fTexBuf[0]
132         buffer2: fTexBuf[1] width: ( fTitle->width + 2 )
133         height: ( fTitle->height + 2 )];
134         
135         /* Set the Output Display below the Preview Picture*/
136         if (fTitle->job->pixel_ratio == 1)
137         {
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         [fInfoField setStringValue: [NSString stringWithFormat:
144         @"Source: %dx%d, Output: %dx%d, Anamorphic: %dx%d", fTitle->width, fTitle->height,
145         titlewidth, fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1], displayparwidth,
146         fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1]]];
147         
148         
149         }
150         else
151         {
152         [fInfoField setStringValue: [NSString stringWithFormat:
153         @"Source: %dx%d, Output: %dx%d", fTitle->width, fTitle->height,
154         fTitle->job->width, fTitle->job->height]];      
155         }
156
157     [fPrevButton setEnabled: ( fPicture > 0 )];
158     [fNextButton setEnabled: ( fPicture < 9 )];
159 }
160
161 - (IBAction) SettingsChanged: (id) sender
162 {
163     hb_job_t * job = fTitle->job;
164     
165         if ([fPARCheck state] == 1 )
166         {
167         [fWidthStepper      setIntValue: MaxOutputWidth];
168         [fWidthField        setIntValue: MaxOutputWidth];
169         
170         [fHeightStepper      setIntValue: fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1]];
171         [fHeightField        setIntValue: fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1]];
172         [fRatioCheck        setState: 0];
173
174         [fWidthStepper setEnabled: NO];
175         [fWidthField setEnabled: NO];
176         [fHeightStepper setEnabled: NO];
177         [fHeightField setEnabled: NO];
178         [fRatioCheck setEnabled: NO];
179         
180         
181         }
182         else
183         {
184         [fWidthStepper setEnabled: YES];
185         [fWidthField setEnabled: YES];
186         [fHeightStepper setEnabled: YES];
187         [fHeightField setEnabled: YES];
188         [fRatioCheck setEnabled: YES];
189         }
190         
191         
192         
193     job->width       = [fWidthStepper  intValue];
194     job->height      = [fHeightStepper intValue];
195     job->keep_ratio  = ( [fRatioCheck state] == NSOnState );
196     job->deinterlace = ( [fDeinterlaceCheck state] == NSOnState );
197         job->pixel_ratio = ( [fPARCheck state] == NSOnState );
198
199
200
201     bool autocrop = ( [fCropMatrix selectedRow] == 0 );
202     [fCropTopStepper    setEnabled: !autocrop];
203     [fCropBottomStepper setEnabled: !autocrop];
204     [fCropLeftStepper   setEnabled: !autocrop];
205     [fCropRightStepper  setEnabled: !autocrop];
206     if( autocrop )
207     {
208         memcpy( job->crop, fTitle->crop, 4 * sizeof( int ) );
209     }
210     else
211     {
212         job->crop[0] = [fCropTopStepper    intValue];
213         job->crop[1] = [fCropBottomStepper intValue];
214         job->crop[2] = [fCropLeftStepper   intValue];
215         job->crop[3] = [fCropRightStepper  intValue];
216     }
217
218     if( job->keep_ratio )
219     {
220         if( sender == fWidthStepper || sender == fRatioCheck ||
221             sender == fCropTopStepper || sender == fCropBottomStepper )
222         {
223             hb_fix_aspect( job, HB_KEEP_WIDTH );
224             if( job->height > fTitle->height )
225             {
226                 job->height = fTitle->height;
227                 hb_fix_aspect( job, HB_KEEP_HEIGHT );
228             }
229         }
230         else
231         {
232             hb_fix_aspect( job, HB_KEEP_HEIGHT );
233             if( job->width > fTitle->width )
234             {
235                 job->width = fTitle->width;
236                 hb_fix_aspect( job, HB_KEEP_WIDTH );
237             }
238         }
239     }
240     
241     [fWidthStepper      setIntValue: job->width];
242     [fWidthField        setIntValue: job->width];
243     [fHeightStepper     setIntValue: job->height];
244     [fHeightField       setIntValue: job->height];
245     [fCropTopStepper    setIntValue: job->crop[0]];
246     [fCropTopField      setIntValue: job->crop[0]];
247     [fCropBottomStepper setIntValue: job->crop[1]];
248     [fCropBottomField   setIntValue: job->crop[1]];
249     [fCropLeftStepper   setIntValue: job->crop[2]];
250     [fCropLeftField     setIntValue: job->crop[2]];
251     [fCropRightStepper  setIntValue: job->crop[3]];
252     [fCropRightField    setIntValue: job->crop[3]];
253     [self Display: HB_ANIMATE_NONE];
254 }
255
256 - (IBAction) PreviousPicture: (id) sender
257 {   
258     if( fPicture <= 0 )
259     {
260         return;
261     }
262     fPicture--;
263     [self Display: HB_ANIMATE_BACKWARD];
264 }
265
266 - (IBAction) NextPicture: (id) sender
267 {
268     if( fPicture >= 9 )
269     {
270         return;
271     }
272     fPicture++;
273     [self Display: HB_ANIMATE_FORWARD];
274 }
275
276 - (IBAction) ClosePanel: (id) sender
277 {
278
279         [NSApp stopModal];
280 }
281
282 @end