1 /* $Id: HBPreviewController.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 "HBPreviewController.h"
10 @implementation QTMovieView ( HBQTkitExt )
11 - (void) mouseMoved:(NSEvent *)theEvent
13 [super mouseMoved:theEvent];
19 @interface PreviewController (Private)
21 - (NSSize)optimalViewSizeForImageSize: (NSSize)imageSize;
22 - (void)resizeSheetForViewSize: (NSSize)viewSize;
23 - (void)setViewSize: (NSSize)viewSize;
24 - (BOOL)viewNeedsToResizeToSize: (NSSize)newSize;
28 @implementation PreviewController
32 if (self = [super initWithWindowNibName:@"PicturePreview"])
34 // NSWindowController likes to lazily load its window. However since
35 // this controller tries to set all sorts of outlets before the window
36 // is displayed, we need it to load immediately. The correct way to do
37 // this, according to the documentation, is simply to invoke the window
40 // If/when we switch a lot of this stuff to bindings, this can probably
44 fPicturePreviews = [[NSMutableDictionary dictionaryWithCapacity: HB_NUM_HBLIB_PICTURES] retain];
45 /* Init libhb with check for updates libhb style set to "0" so its ignored and lets sparkle take care of it */
46 int loggingLevel = [[[NSUserDefaults standardUserDefaults] objectForKey:@"LoggingLevel"] intValue];
47 fPreviewLibhb = hb_init(loggingLevel, 0);
56 //------------------------------------------------------------------------------------
57 // Displays and brings the picture window to the front
58 //------------------------------------------------------------------------------------
59 - (IBAction) showPreviewWindow: (id)sender
61 [self showWindow:sender];
62 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"PreviewWindowIsOpen"];
64 /* lets set the preview window to accept mouse moved events */
65 [fPreviewWindow setAcceptsMouseMovedEvents:YES];
67 [self pictureSliderChanged:nil];
68 [self startReceivingLibhbNotifications];
71 - (void)setHBController: (HBController *)controller
73 fHBController = controller;
78 [fPreviewWindow setDelegate:self];
79 if( ![[self window] setFrameUsingName:@"Preview"] )
80 [[self window] center];
81 [self setWindowFrameAutosaveName:@"Preview"];
82 [[self window] setExcludedFromWindowsMenu:YES];
84 /* lets set the preview window to accept mouse moved events */
85 [fPreviewWindow setAcceptsMouseMovedEvents:YES];
86 //[self pictureSliderChanged:nil];
87 [self startReceivingLibhbNotifications];
90 /* we set the progress indicator to not use threaded animation
91 * as it causes a conflict with the qtmovieview's controllerbar
93 [fMovieCreationProgressIndicator setUsesThreadedAnimation:NO];
95 /* Setup our layers for core animation */
96 [fPictureViewArea setWantsLayer:YES];
97 [fPictureView setWantsLayer:YES];
99 [fCancelPreviewMovieButton setWantsLayer:YES];
100 [fMovieCreationProgressIndicator setWantsLayer:YES];
102 [fPictureControlBox setWantsLayer:YES];
103 [fEncodingControlBox setWantsLayer:YES];
104 [fMovieView setWantsLayer:YES];
105 [fMovieView setHidden:YES];
106 [fMovieView setDelegate:self];
108 /* Since the xib has everything off center for easy acess
109 * we align our views and windows here we an align to anything
110 * since it will actually change later upon source load, but
111 * for convenience we will use the fPictureViewArea
114 /* Align the still preview image view to the picture box */
115 [fPictureView setFrameSize:[fPictureViewArea frame].size];
116 [fMovieView setFrameSize:[fPictureViewArea frame].size];
117 //[fPreviewWindow setFrameSize:[fPictureViewArea frame].size];
121 - (BOOL)acceptsMouseMovedEvents
126 - (void)windowWillClose:(NSNotification *)aNotification
128 /* Upon Closing the picture window, we make sure we clean up any
129 * preview movie that might be playing
131 hb_stop( fPreviewLibhb );
133 // Show the picture view
134 [fPictureView setHidden:NO];
135 [fMovieView pause:nil];
136 [fMovieTimer invalidate];
137 [fMovieTimer release];
138 [fMovieView setHidden:YES];
139 [fMovieView setMovie:nil];
140 [self pictureSliderChanged:nil];
143 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"PreviewWindowIsOpen"];
146 - (BOOL)windowShouldClose:(id)fPictureWindow
153 hb_stop(fPreviewLibhb);
154 if (fPreviewMoviePath)
156 [[NSFileManager defaultManager] removeItemAtPath:fPreviewMoviePath error:nil];
157 [fPreviewMoviePath release];
160 [fLibhbTimer invalidate];
161 [fLibhbTimer release];
163 [fHudTimer invalidate];
166 [fMovieTimer invalidate];
167 [fMovieTimer release];
169 [fPicturePreviews release];
170 [fFullScreenWindow release];
172 hb_close(&fPreviewLibhb);
174 [self removeMovieCallbacks];
179 - (void) SetHandle: (hb_handle_t *) handle
185 /* we set the preview length popup in seconds */
186 [fPreviewMovieLengthPopUp removeAllItems];
187 [fPreviewMovieLengthPopUp addItemWithTitle: @"5"];
188 [fPreviewMovieLengthPopUp addItemWithTitle: @"10"];
189 [fPreviewMovieLengthPopUp addItemWithTitle: @"15"];
190 [fPreviewMovieLengthPopUp addItemWithTitle: @"20"];
191 [fPreviewMovieLengthPopUp addItemWithTitle: @"25"];
192 [fPreviewMovieLengthPopUp addItemWithTitle: @"30"];
193 [fPreviewMovieLengthPopUp addItemWithTitle: @"35"];
194 [fPreviewMovieLengthPopUp addItemWithTitle: @"40"];
195 [fPreviewMovieLengthPopUp addItemWithTitle: @"45"];
196 [fPreviewMovieLengthPopUp addItemWithTitle: @"50"];
197 [fPreviewMovieLengthPopUp addItemWithTitle: @"55"];
198 [fPreviewMovieLengthPopUp addItemWithTitle: @"60"];
200 /* adjust the preview slider length */
201 /* We use our advance pref to determine how many previews we scanned */
202 int hb_num_previews = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
203 [fPictureSlider setMaxValue: hb_num_previews - 1.0];
204 [fPictureSlider setNumberOfTickMarks: hb_num_previews];
206 if ([[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewLength"])
208 [fPreviewMovieLengthPopUp selectItemWithTitle:[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewLength"]];
212 /* currently hard set default to 10 seconds */
213 [fPreviewMovieLengthPopUp selectItemAtIndex: 1];
217 - (void) SetTitle: (hb_title_t *) title
219 hb_job_t * job = title->job;
223 MaxOutputWidth = title->width - job->crop[2] - job->crop[3];
224 MaxOutputHeight = title->height - job->crop[0] - job->crop[1];
226 [self SettingsChanged: nil];
232 // Adjusts the window to draw the current picture (fPicture) adjusting its size as
233 // necessary to display as much of the picture as possible.
234 - (void) displayPreview
236 hb_job_t * job = fTitle->job;
237 /* lets make sure that the still picture view is not hidden and that
238 * the movie preview is
241 [fMovieView pause:nil];
242 [fMovieView setHidden:YES];
243 [fMovieView setMovie:nil];
244 [fMovieCreationProgressIndicator stopAnimation: nil];
245 [fMovieCreationProgressIndicator setHidden: YES];
246 [fMoviePlaybackControlBox setHidden: YES];
249 [self stopMovieTimer];
251 [fPictureControlBox setHidden: NO];
253 [fPictureView setHidden:NO];
255 NSImage *fPreviewImage = [self imageForPicture: fPicture];
256 NSSize imageScaledSize = [fPreviewImage size];
257 [fPictureView setImage: fPreviewImage];
259 NSSize displaySize = NSMakeSize( ( CGFloat )fTitle->width, ( CGFloat )fTitle->height );
260 NSString *sizeInfoString;
261 /* Set the picture size display fields below the Preview Picture*/
262 if( fTitle->job->anamorphic.mode == 1 ) // Original PAR Implementation
264 output_width = fTitle->width-fTitle->job->crop[2]-fTitle->job->crop[3];
265 output_height = fTitle->height-fTitle->job->crop[0]-fTitle->job->crop[1];
266 display_width = output_width * fTitle->job->anamorphic.par_width / fTitle->job->anamorphic.par_height;
267 sizeInfoString = [NSString stringWithFormat:
268 @"Source: %dx%d, Output: %dx%d, Anamorphic: %dx%d Strict",
269 fTitle->width, fTitle->height, output_width, output_height, display_width, output_height];
271 displaySize.width = display_width;
272 displaySize.height = fTitle->height;
273 imageScaledSize.width = display_width;
274 imageScaledSize.height = output_height;
276 else if (fTitle->job->anamorphic.mode == 2) // Loose Anamorphic
278 hb_set_anamorphic_size(job, &output_width, &output_height, &output_par_width, &output_par_height);
279 display_width = output_width * output_par_width / output_par_height;
280 sizeInfoString = [NSString stringWithFormat:
281 @"Source: %dx%d, Output: %dx%d, Anamorphic: %dx%d Loose",
282 fTitle->width, fTitle->height, output_width, output_height, display_width, output_height];
284 displaySize.width = display_width;
285 displaySize.height = fTitle->height;
286 imageScaledSize.width = display_width;
287 imageScaledSize.height = output_height;
289 else if (fTitle->job->anamorphic.mode == 3) // Custom Anamorphic
291 hb_set_anamorphic_size(job, &output_width, &output_height, &output_par_width, &output_par_height);
292 display_width = output_width * output_par_width / output_par_height;
293 sizeInfoString = [NSString stringWithFormat:
294 @"Source: %dx%d, Output: %dx%d, Anamorphic: %dx%d Custom",
295 fTitle->width, fTitle->height, output_width, output_height, fTitle->job->anamorphic.dar_width, fTitle->job->anamorphic.dar_height];
297 displaySize.width = fTitle->job->anamorphic.dar_width + fTitle->job->crop[2] + fTitle->job->crop[3] ;
298 displaySize.height = fTitle->job->anamorphic.dar_height + fTitle->job->crop[0] + fTitle->job->crop[1];
299 imageScaledSize.width = (int)fTitle->job->anamorphic.dar_width;
300 imageScaledSize.height = (int)fTitle->job->height;
302 else // No Anamorphic
304 sizeInfoString = [NSString stringWithFormat:
305 @"Source: %dx%d, Output: %dx%d", fTitle->width, fTitle->height,
306 fTitle->job->width, fTitle->job->height];
308 displaySize.width = fTitle->width;
309 displaySize.height = fTitle->height;
310 imageScaledSize.width = fTitle->job->width;
311 imageScaledSize.height = fTitle->job->height;
316 NSSize viewSize = [self optimalViewSizeForImageSize:displaySize];
317 [self resizeSheetForViewSize:viewSize];
319 NSSize windowSize = [[self window] frame].size;
321 if (scaleToScreen == YES)
323 /* Note: this should probably become a utility function */
324 /* We are in Scale To Screen mode so, we have to get the ratio for height and width against the window
325 *size so we can scale from there.
327 CGFloat deltaWidth = imageScaledSize.width / displaySize.width;
328 CGFloat deltaHeight = imageScaledSize.height /displaySize.height;
329 NSSize windowSize = [[self window] frame].size;
330 CGFloat pictureAspectRatio = imageScaledSize.width / imageScaledSize.height;
332 /* Set our min size to the storage size */
334 minSize.width = fTitle->width;
335 minSize.height = fTitle->height;
337 /* Set delta's based on minimum size */
338 if (imageScaledSize.width < minSize.width)
340 deltaWidth = imageScaledSize.width / minSize.width;
347 if (imageScaledSize.height < minSize.height)
349 deltaHeight = imageScaledSize.height / minSize.height;
356 /* Now apply our deltas to the full screen view */
357 if (pictureAspectRatio > 1.0) // we are wider than taller, so expand the width to fill the area and scale the height
359 viewSize.width = windowSize.width * deltaWidth;
360 viewSize.height = viewSize.width / pictureAspectRatio;
365 viewSize.height = windowSize.height * deltaHeight;
366 viewSize.width = viewSize.height * pictureAspectRatio;
372 viewSize.width = viewSize.width - (viewSize.width - imageScaledSize.width);
373 viewSize.height = viewSize.height - (viewSize.height - imageScaledSize.height);
375 if (fTitle->width > windowSize.width || fTitle->height > windowSize.height)
377 CGFloat viewSizeAspect = viewSize.width / viewSize.height;
378 if (viewSizeAspect > 1.0) // we are wider than taller, so expand the width to fill the area and scale the height
380 viewSize.width = viewSize.width * (windowSize.width / fTitle->width) ;
381 viewSize.height = viewSize.width / viewSizeAspect;
385 viewSize.height = viewSize.height * (windowSize.height / fTitle->height);
386 viewSize.width = viewSize.height * viewSizeAspect;
392 [self setViewSize:viewSize];
394 /* relocate our hud origins as per setViewSize */
395 NSPoint hudControlBoxOrigin = [fPictureControlBox frame].origin;
396 hudControlBoxOrigin.y = ([[self window] frame].size.height / 2) - (viewSize.height / 2);
397 hudControlBoxOrigin.x = ([[self window] frame].size.width / 2) - ([fPictureControlBox frame].size.width / 2);
398 [fPictureControlBox setFrameOrigin:hudControlBoxOrigin];
399 [fEncodingControlBox setFrameOrigin:hudControlBoxOrigin];
400 [fMoviePlaybackControlBox setFrameOrigin:hudControlBoxOrigin];
403 NSString *scaleString;
404 CGFloat scale = ( ( CGFloat )[fPictureView frame].size.width) / ( ( CGFloat )imageScaledSize.width);
405 if (scale * 100.0 != 100)
407 scaleString = [NSString stringWithFormat:
408 NSLocalizedString( @" (%.0f%% actual size)",
409 @"String shown when a preview is scaled" ), scale * 100.0];
413 scaleString = @"(Actual size)";
416 if (scaleToScreen == YES)
418 scaleString = [scaleString stringByAppendingString:@" Scaled To Screen"];
420 /* Set the info fields in the hud controller */
421 [fInfoField setStringValue: [NSString stringWithFormat:
422 @"%@", sizeInfoString]];
424 [fscaleInfoField setStringValue: [NSString stringWithFormat:
425 @"%@", scaleString]];
426 /* Set the info field in the window title bar */
427 [[self window] setTitle:[NSString stringWithFormat: @"Preview - %@ %@",sizeInfoString, scaleString]];
430 - (IBAction) previewDurationPopUpChanged: (id) sender
433 [[NSUserDefaults standardUserDefaults] setObject:[fPreviewMovieLengthPopUp titleOfSelectedItem] forKey:@"PreviewLength"];
437 - (IBAction) SettingsChanged: (id) sender
439 // Purge the existing picture previews so they get recreated the next time
441 [self purgeImageCache];
442 [self pictureSliderChanged:nil];
445 - (IBAction) pictureSliderChanged: (id) sender
447 // Show the picture view
448 [fPictureView setHidden:NO];
449 [fMovieView pause:nil];
450 [fMovieView setHidden:YES];
451 [fMovieView setMovie:nil];
452 [fEncodingControlBox setHidden: YES];
454 int newPicture = [fPictureSlider intValue];
455 if (newPicture != fPicture)
457 fPicture = newPicture;
459 [self displayPreview];
463 - (IBAction)showPreviewPanel: (id)sender forTitle: (hb_title_t *)title
465 if ([fPreviewWindow isVisible])
467 [fPreviewWindow close];
471 [self showWindow:sender];
472 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"PreviewWindowIsOpen"];
473 [fPreviewWindow setAcceptsMouseMovedEvents:YES];
475 [self pictureSliderChanged:nil];
480 - (NSString*) pictureSizeInfoString
482 return [fInfoField stringValue];
485 - (IBAction)showPictureSettings:(id)sender
487 [fHBController showPicturePanel:self];
490 #pragma mark Hud Control Overlay
491 - (void) mouseMoved:(NSEvent *)theEvent
493 [super mouseMoved:theEvent];
494 NSPoint mouseLoc = [theEvent locationInWindow];
496 /* Test for mouse location to show/hide hud controls */
497 if( isEncoding == NO )
499 /* Since we are not encoding, verify which control hud to show
500 * or hide based on aMovie ( aMovie indicates we need movie controls )
502 NSBox * hudBoxToShow;
503 if ( aMovie == nil ) // No movie loaded up
505 hudBoxToShow = fPictureControlBox;
507 else // We have a movie
509 hudBoxToShow = fMoviePlaybackControlBox;
512 if( NSPointInRect( mouseLoc, [fPictureControlBox frame] ) )
514 [[hudBoxToShow animator] setHidden: NO];
517 else if( NSPointInRect( mouseLoc, [fPictureViewArea frame] ) )
519 [[hudBoxToShow animator] setHidden: NO];
520 [self startHudTimer];
524 [[hudBoxToShow animator] setHidden: YES];
529 - (void) startHudTimer
532 [fHudTimer invalidate];
535 fHudTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(hudTimerFired:) userInfo:nil repeats:YES];
539 - (void) stopHudTimer
543 [fHudTimer invalidate];
550 - (void) hudTimerFired: (NSTimer*)theTimer
553 if( hudTimerSeconds >= 10 )
555 /* Regardless which control box is active, after the timer
556 * period we want either one to fade to hidden.
558 [[fPictureControlBox animator] setHidden: YES];
559 [[fMoviePlaybackControlBox animator] setHidden: YES];
566 - (IBAction)toggleScaleToScreen:(id)sender
568 if (scaleToScreen == YES)
571 /* make sure we are set to a still preview */
572 [self pictureSliderChanged:nil];
573 [fScaleToScreenToggleButton setTitle:@"Scale To Screen"];
578 /* make sure we are set to a still preview */
579 [self pictureSliderChanged:nil];
580 [fScaleToScreenToggleButton setTitle:@"Actual Scale"];
587 // Title-less windows normally don't receive key presses, override this
588 - (BOOL)canBecomeKeyWindow
593 // Title-less windows normally can't become main which means that another
594 // non-fullscreen window will have the "active" titlebar in expose. Bad, fix it.
595 - (BOOL)canBecomeMainWindow
601 - (IBAction)goWindowedScreen:(id)sender
604 /* Get the screen info to release the display but don't actually do
605 * it until the windowed screen is setup.
608 [self pictureSliderChanged:nil];
609 [fScaleToScreenToggleButton setTitle:@"<->"];
611 NSScreen* mainScreen = [NSScreen mainScreen];
612 NSDictionary* screenInfo = [mainScreen deviceDescription];
613 NSNumber* screenID = [screenInfo objectForKey:@"NSScreenNumber"];
614 CGDirectDisplayID displayID = (CGDirectDisplayID)[screenID longValue];
616 [fFullScreenWindow dealloc];
617 [fFullScreenWindow release];
620 [fPreviewWindow setContentView:fPictureViewArea];
621 [fPictureViewArea setNeedsDisplay:YES];
622 [self setWindow:fPreviewWindow];
625 [fPreviewWindow makeKeyAndOrderFront:self];
627 /* Set the window back to regular level */
628 [fPreviewWindow setLevel:NSNormalWindowLevel];
630 /* Set the isFullScreen flag back to NO */
633 /* make sure we are set to a still preview */
634 [self pictureSliderChanged:nil];
635 [self showPreviewWindow:nil];
637 /* Change the name of fFullScreenToggleButton appropriately */
638 //[fFullScreenToggleButton setTitle: @"Full Screen"];
639 // [fScaleToScreenToggleButton setHidden:YES];
640 /* set the picture settings pallete back to normal level */
641 [fHBController picturePanelWindowed];
643 /* Release the display now that the we are back in windowed mode */
644 CGDisplayRelease(displayID);
646 [fPreviewWindow setAcceptsMouseMovedEvents:YES];
647 //[fFullScreenWindow setAcceptsMouseMovedEvents:NO];
650 [self startHudTimer];
655 #pragma mark Still Preview Image Processing
658 // This function converts an image created by libhb (specified via pictureIndex) into
659 // an NSImage suitable for the GUI code to use. If removeBorders is YES,
660 // makeImageForPicture crops the image generated by libhb stripping off the gray
661 // border around the content. This is the low-level method that generates the image.
662 // -imageForPicture calls this function whenever it can't find an image in its cache.
663 + (NSImage *) makeImageForPicture: (int)pictureIndex
664 libhb:(hb_handle_t*)handle
665 title:(hb_title_t*)title
667 static uint8_t * buffer;
668 static int bufferSize;
670 // Make sure we have a big enough buffer to receive the image from libhb. libhb
671 int dstWidth = title->job->width;
672 int dstHeight = title->job->height;
675 newSize = dstWidth * dstHeight * 4;
676 if( bufferSize < newSize )
678 bufferSize = newSize;
679 buffer = (uint8_t *) realloc( buffer, bufferSize );
682 hb_get_preview( handle, title, pictureIndex, buffer );
684 // Create an NSBitmapImageRep and copy the libhb image into it, converting it from
685 // libhb's format to one suitable for NSImage. Along the way, we'll strip off the
686 // border around libhb's image.
688 // The image data returned by hb_get_preview is 4 bytes per pixel, BGRA format.
691 NSBitmapFormat bitmapFormat = (NSBitmapFormat)NSAlphaFirstBitmapFormat;
692 NSBitmapImageRep * imgrep = [[[NSBitmapImageRep alloc]
693 initWithBitmapDataPlanes:nil
697 samplesPerPixel:3 // ignore alpha
700 colorSpaceName:NSCalibratedRGBColorSpace
701 bitmapFormat:bitmapFormat
702 bytesPerRow:dstWidth * 4
703 bitsPerPixel:32] autorelease];
705 UInt32 * src = (UInt32 *)buffer;
706 UInt32 * dst = (UInt32 *)[imgrep bitmapData];
708 for (r = 0; r < dstHeight; r++)
710 for (c = 0; c < dstWidth; c++)
711 #if TARGET_RT_LITTLE_ENDIAN
712 *dst++ = Endian32_Swap(*src++);
718 NSImage * img = [[[NSImage alloc] initWithSize: NSMakeSize(dstWidth, dstHeight)] autorelease];
719 [img addRepresentation:imgrep];
724 // Returns the preview image for the specified index, retrieving it from its internal
725 // cache or by calling makeImageForPicture if it is not cached. Generally, you should
726 // use imageForPicture so that images are cached. Calling makeImageForPicture will
727 // always generate a new copy of the image.
728 - (NSImage *) imageForPicture: (int) pictureIndex
730 // The preview for the specified index may not currently exist, so this method
731 // generates it if necessary.
732 NSString * key = [NSString stringWithFormat:@"%d", pictureIndex];
733 NSImage * theImage = [fPicturePreviews objectForKey:key];
736 theImage = [PreviewController makeImageForPicture:pictureIndex libhb:fHandle title:fTitle];
737 [fPicturePreviews setObject:theImage forKey:key];
742 // Purges all images from the cache. The next call to imageForPicture will cause a new
743 // image to be generated.
744 - (void) purgeImageCache
746 [fPicturePreviews removeAllObjects];
751 #pragma mark Movie Preview
753 - (IBAction) cancelCreateMoviePreview: (id) sender
757 hb_get_state2( fPreviewLibhb, &s );
759 if(isEncoding && (s.state == HB_STATE_WORKING || s.state == HB_STATE_PAUSED))
761 hb_stop( fPreviewLibhb );
762 [fPictureView setHidden:NO];
763 [fMovieView pause:nil];
764 [fMovieView setHidden:YES];
765 [fMovieView setMovie:nil];
766 [fPictureSlider setHidden:NO];
769 [self pictureSliderChanged:nil];
776 - (IBAction) createMoviePreview: (id) sender
780 /* Lets make sure the still picture previews are showing in case
781 * there is currently a movie showing */
782 [self pictureSliderChanged:nil];
784 /* Rip or Cancel ? */
786 hb_get_state2( fPreviewLibhb, &s );
788 if(sender == fCancelPreviewMovieButton && (s.state == HB_STATE_WORKING || s.state == HB_STATE_PAUSED))
790 hb_stop( fPreviewLibhb );
791 [fPictureView setHidden:NO];
792 [fMovieView pause:nil];
793 [fMovieView setHidden:YES];
794 [fMovieView setMovie:nil];
795 [fPictureSlider setHidden:NO];
802 /* we use controller.mm's prepareJobForPreview to go ahead and set all of our settings
803 * however, we want to use a temporary destination field of course
804 * so that we do not put our temp preview in the users chosen
807 hb_job_t * job = fTitle->job;
809 /* We run our current setting through prepeareJob in Controller.mm
810 * just as if it were a regular encode */
812 [fHBController prepareJobForPreview];
814 /* Destination file. We set this to our preview directory
815 * changing the extension appropriately.*/
816 if (fTitle->job->mux == HB_MUX_MP4) // MP4 file
818 /* we use .m4v for our mp4 files so that ac3 and chapters in mp4 will play properly */
819 fPreviewMoviePath = @"~/Library/Application Support/HandBrake/Previews/preview_temp.m4v";
821 else if (fTitle->job->mux == HB_MUX_MKV) // MKV file
823 fPreviewMoviePath = @"~/Library/Application Support/HandBrake/Previews/preview_temp.mkv";
825 else if (fTitle->job->mux == HB_MUX_AVI) // AVI file
827 fPreviewMoviePath = @"~/Library/Application Support/HandBrake/Previews/preview_temp.avi";
829 else if (fTitle->job->mux == HB_MUX_OGM) // OGM file
831 fPreviewMoviePath = @"~/Library/Application Support/HandBrake/Previews/preview_temp.ogm";
834 fPreviewMoviePath = [[fPreviewMoviePath stringByExpandingTildeInPath]retain];
836 /* See if there is an existing preview file, if so, delete it */
837 if( ![[NSFileManager defaultManager] fileExistsAtPath:fPreviewMoviePath] )
839 [[NSFileManager defaultManager] removeItemAtPath:fPreviewMoviePath error:nil];
842 /* We now direct our preview encode to fPreviewMoviePath */
843 fTitle->job->file = [fPreviewMoviePath UTF8String];
845 /* We use our advance pref to determine how many previews to scan */
846 int hb_num_previews = [[[NSUserDefaults standardUserDefaults] objectForKey:@"PreviewsNumber"] intValue];
847 job->start_at_preview = fPicture + 1;
848 job->seek_points = hb_num_previews;
850 /* we use the preview duration popup to get the specified
851 * number of seconds for the preview encode.
854 job->pts_to_stop = [[fPreviewMovieLengthPopUp titleOfSelectedItem] intValue] * 90000LL;
856 /* lets go ahead and send it off to libhb
857 * Note: unlike a full encode, we only send 1 pass regardless if the final encode calls for 2 passes.
858 * this should suffice for a fairly accurate short preview and cuts our preview generation time in half.
859 * However we also need to take into account the indepth scan for subtitles.
862 * If scanning we need to do some extra setup of the job.
864 if( job->indepth_scan == 1 )
869 * When subtitle scan is enabled do a fast pre-scan job
870 * which will determine which subtitles to enable, if any.
873 x264opts_tmp = job->x264opts;
875 job->x264opts = NULL;
876 job->indepth_scan = 1;
878 * Add the pre-scan job
880 hb_add( fPreviewLibhb, job );
881 job->x264opts = x264opts_tmp;
883 /* Go ahead and perform the actual encoding preview scan */
884 job->indepth_scan = 0;
886 hb_add( fPreviewLibhb, job );
888 [fEncodingControlBox setHidden: NO];
889 [fPictureControlBox setHidden: YES];
891 [fMovieCreationProgressIndicator setHidden: NO];
892 [fPreviewMovieStatusField setHidden: NO];
896 /* Let fPreviewLibhb do the job */
897 hb_start( fPreviewLibhb );
901 - (void) startReceivingLibhbNotifications
905 fLibhbTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(libhbTimerFired:) userInfo:nil repeats:YES];
906 [fLibhbTimer retain];
910 - (void) stopReceivingLibhbNotifications
914 [fLibhbTimer invalidate];
915 [fLibhbTimer release];
919 - (void) libhbTimerFired: (NSTimer*)theTimer
922 hb_get_state( fPreviewLibhb, &s );
923 [self libhbStateChanged: s];
927 - (void) libhbStateChanged: (hb_state_t)state
929 switch( state.state )
932 case HB_STATE_SCANNING:
933 case HB_STATE_SCANDONE:
936 case HB_STATE_WORKING:
938 #define p state.param.working
940 NSMutableString * string;
941 /* Update text field */
942 string = [NSMutableString stringWithFormat: NSLocalizedString( @"Encoding preview: %.2f %%", @"" ), 100.0 * p.progress];
946 [string appendFormat:
947 NSLocalizedString( @" (%.2f fps, avg %.2f fps, ETA %02dh%02dm%02ds)", @"" ),
948 p.rate_cur, p.rate_avg, p.hours, p.minutes, p.seconds];
950 [fPreviewMovieStatusField setStringValue: string];
952 [fMovieCreationProgressIndicator setIndeterminate: NO];
954 [fMovieCreationProgressIndicator setDoubleValue: 100.0 * p.progress];
956 [fCreatePreviewMovieButton setTitle: @"Cancel Preview"];
963 #define p state.param.muxing
964 case HB_STATE_MUXING:
966 // Update fMovieCreationProgressIndicator
967 [fMovieCreationProgressIndicator setIndeterminate: YES];
968 [fMovieCreationProgressIndicator startAnimation: nil];
969 [fPreviewMovieStatusField setStringValue: [NSString stringWithFormat:
970 NSLocalizedString( @"Muxing Preview ...", @"" )]];
974 case HB_STATE_PAUSED:
975 [fMovieCreationProgressIndicator stopAnimation: nil];
978 case HB_STATE_WORKDONE:
980 // Delete all remaining jobs since libhb doesn't do this on its own.
982 while( ( job = hb_job(fPreviewLibhb, 0) ) )
983 hb_rem( fHandle, job );
985 [fPreviewMovieStatusField setStringValue: @""];
986 [fPreviewMovieStatusField setHidden: YES];
988 [fMovieCreationProgressIndicator stopAnimation: nil];
989 [fMovieCreationProgressIndicator setHidden: YES];
990 [fEncodingControlBox setHidden: YES];
991 [fPictureControlBox setHidden: YES];
994 // Show the movie view
995 [self showMoviePreview:fPreviewMoviePath];
996 [fCreatePreviewMovieButton setTitle: @"Live Preview"];
1003 - (IBAction) toggleMoviePreviewPlayPause: (id) sender
1005 /* make sure a movie is even loaded up */
1008 /* For some stupid reason there is no "isPlaying" method for a QTMovie
1009 * object, given that, we detect the rate to determine whether the movie
1010 * is playing or not.
1012 if ([aMovie rate] != 0) // we are playing
1014 [fMovieView pause:aMovie];
1015 [fPlayPauseButton setTitle: @">"];
1017 else // we are paused or stopped
1019 [fMovieView play:aMovie];
1020 [fPlayPauseButton setTitle: @"||"];
1026 - (IBAction) moviePlaybackGoToBeginning: (id) sender
1028 /* make sure a movie is even loaded up */
1031 [fMovieView gotoBeginning:aMovie];
1036 - (IBAction) moviePlaybackGoToEnd: (id) sender
1038 /* make sure a movie is even loaded up */
1041 [fMovieView gotoEnd:aMovie];
1046 - (IBAction) moviePlaybackGoBackwardOneFrame: (id) sender
1048 /* make sure a movie is even loaded up */
1051 [fMovieView pause:aMovie]; // Pause the movie
1052 [fMovieView stepBackward:aMovie];
1057 - (IBAction) moviePlaybackGoForwardOneFrame: (id) sender
1059 /* make sure a movie is even loaded up */
1062 [fMovieView pause:aMovie]; // Pause the movie
1063 [fMovieView stepForward:aMovie];
1069 - (void) startMovieTimer
1072 [fMovieTimer invalidate];
1073 [fMovieTimer release];
1075 fMovieTimer = [NSTimer scheduledTimerWithTimeInterval:0.10 target:self selector:@selector(movieTimerFired:) userInfo:nil repeats:YES];
1076 [fMovieTimer retain];
1079 - (void) stopMovieTimer
1083 [fMovieTimer invalidate];
1084 [fMovieTimer release];
1089 - (void) movieTimerFired: (NSTimer*)theTimer
1093 [self adjustPreviewScrubberForCurrentMovieTime];
1094 [fMovieInfoField setStringValue: [NSString stringWithFormat:NSLocalizedString( @"%@", @"" ),[self calculatePlaybackSMTPETimecodeForDisplay]]];
1100 - (IBAction) showMoviePreview: (NSString *) path
1102 /* Since the gray background for the still images is part of
1103 * fPictureView, lets leave the picture view visible and postion
1104 * the fMovieView over the image portion of fPictureView so
1105 * we retain the gray cropping border we have already established
1106 * with the still previews
1109 /* Load the new movie into fMovieView */
1114 NSURL *movieUrl = [NSURL fileURLWithPath:path];
1115 NSDictionary *movieAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
1116 movieUrl, QTMovieURLAttribute,
1117 [NSNumber numberWithBool:NO], QTMovieAskUnresolvedDataRefsAttribute,
1118 [NSNumber numberWithBool:YES], @"QTMovieOpenForPlaybackAttribute",
1119 [NSNumber numberWithBool:NO], @"QTMovieOpenAsyncRequiredAttribute",
1120 [NSNumber numberWithBool:NO], @"QTMovieOpenAsyncOKAttribute",
1121 [NSNumber numberWithBool:YES], @"QTMovieIsSteppableAttribute",
1122 QTMovieApertureModeClean, QTMovieApertureModeAttribute,
1125 aMovie = [[[QTMovie alloc] initWithAttributes:movieAttributes error:&outError] autorelease];
1130 NSLog(@"Unable to open movie");
1135 /* we get some size information from the preview movie */
1136 NSSize movieSize= [[aMovie attributeForKey:QTMovieNaturalSizeAttribute] sizeValue];
1137 movieBounds = [fMovieView movieBounds];
1138 movieBounds.size.height = movieSize.height;
1139 /* We also get our view size to use for scaling fMovieView's size */
1140 NSSize scaledMovieViewSize = [fPictureView frame].size;
1141 [fMovieView setControllerVisible:FALSE];
1142 if ([fMovieView isControllerVisible])
1144 CGFloat controllerBarHeight = [fMovieView controllerBarHeight];
1145 if ( controllerBarHeight != 0 ) //Check if QTKit return a real value or not.
1147 movieBounds.size.height += controllerBarHeight;
1148 scaledMovieViewSize.height += controllerBarHeight;
1152 movieBounds.size.height += 15;
1153 scaledMovieViewSize.height += 15;
1157 movieBounds.size.width = movieSize.width;
1159 /* we need to account for an issue where the scaledMovieViewSize > the window size */
1160 if (scaledMovieViewSize.height > [[self window] frame].size.height)
1162 [fHBController writeToActivityLog: "showMoviePreview: Our window is not tall enough to show the controller bar ..."];
1167 /* Scale the fMovieView to scaledMovieViewSize */
1168 [fMovieView setFrameSize:scaledMovieViewSize];
1170 /*set our origin try using fPictureViewArea or fPictureView */
1171 NSPoint origin = [fPictureView frame].origin;
1172 origin.x += trunc( ( [fPictureView frame].size.width -
1173 [fMovieView frame].size.width ) / 2.0 );
1174 origin.y += trunc( ( ( [fPictureView frame].size.height -
1175 [fMovieView frame].size.height ) / 2.0 ) - 7.5 );
1177 [fMovieView setFrameOrigin:origin];
1178 [fMovieView setMovie:aMovie];
1179 [fMovieView setHidden:NO];
1180 [fMoviePlaybackControlBox setHidden: NO];
1181 [fPictureControlBox setHidden: YES];
1183 // to actually play the movie
1185 [self initPreviewScrubberForMovie];
1186 [self startMovieTimer];
1187 /* Install amovie notifications */
1188 [aMovie setDelegate:self];
1189 [self installMovieCallbacks];
1190 [fMovieView play:aMovie];
1196 #pragma mark *** Movie Playback Scrubber and time code methods ***
1198 /* Since MacOSX Leopard QTKit has taken over some responsibility for assessing movie playback
1199 * information from the old QuickTime carbon api ( time code information as well as fps, etc.).
1200 * However, the QTKit devs at apple were not really big on documentation and further ...
1201 * QuickTimes ability to playback HB's largely variable framerate output makes perfectly frame
1202 * accurate information at best convoluted. Still, for the purpose of a custom hud based custom
1203 * playback scrubber slider this has so far proven to be as accurate as I have found. To say it
1204 * could use some better accuracy is not understating it enough probably.
1205 * Most of this was gleaned from this obscure Apple Mail list thread:
1206 * http://www.mailinglistarchive.com/quicktime-api@lists.apple.com/msg05642.html
1207 * Now as we currently do not show a QTKit control bar with scrubber for display sizes > container
1208 * size, this seems to facilitate playback control from the HB custom HUD controller fairly close
1209 * to the built in controller bar.
1210 * Further work needs to be done to try to get accurate frame by frame playback display if we want it.
1211 * Note that the keyboard commands for frame by frame step through etc. work as always.
1214 // Returns a human readable string from the currentTime of movie playback
1215 - (NSString*) calculatePlaybackSMTPETimecodeForDisplay
1217 QTTime time = [aMovie currentTime];
1219 NSString *smtpeTimeCodeString;
1220 int days, hour, minute, second, frame;
1223 result = time.timeValue / time.timeScale; // second
1224 frame = (time.timeValue % time.timeScale) / 100;
1226 second = result % 60;
1228 result = result / 60; // minute
1229 minute = result % 60;
1231 result = result / 60; // hour
1235 smtpeTimeCodeString = [NSString stringWithFormat:@"Time: %02d:%02d:%02d", hour, minute, second]; // hh:mm:ss
1236 return smtpeTimeCodeString;
1241 // Initialize the preview scrubber min/max to appropriate values for the current movie
1242 -(void) initPreviewScrubberForMovie
1247 QTTime duration = [aMovie duration];
1248 float result = duration.timeValue / duration.timeScale;
1250 [fMovieScrubberSlider setMinValue:0.0];
1251 [fMovieScrubberSlider setMaxValue: (float)result];
1252 [fMovieScrubberSlider setFloatValue: 0.0];
1257 -(void) adjustPreviewScrubberForCurrentMovieTime
1261 QTTime time = [aMovie currentTime];
1263 float result = (float)time.timeValue / (float)time.timeScale;;
1264 [fMovieScrubberSlider setFloatValue:result];
1268 - (IBAction) previewScrubberChanged: (id) sender
1272 [fMovieView pause:aMovie]; // Pause the movie
1273 QTTime time = [aMovie currentTime];
1274 [self setTime: time.timeScale * [fMovieScrubberSlider floatValue]];
1275 [self calculatePlaybackSMTPETimecodeForDisplay];
1278 #pragma mark *** Movie Notifications ***
1280 - (void) installMovieCallbacks
1284 /*Notification for any time the movie rate changes */
1285 [[NSNotificationCenter defaultCenter] addObserver:self
1286 selector:@selector(movieRateDidChange:)
1287 name:@"QTMovieRateDidChangeNotification"
1289 /*Notification for when the movie ends */
1290 [[NSNotificationCenter defaultCenter] addObserver:self
1291 selector:@selector(movieDidEnd:)
1292 name:@"QTMovieDidEndNotification"
1296 - (void)removeMovieCallbacks
1300 /*Notification for any time the movie rate changes */
1301 [[NSNotificationCenter defaultCenter] removeObserver:self
1302 name:@"QTMovieRateDidChangeNotification"
1304 /*Notification for when the movie ends */
1305 [[NSNotificationCenter defaultCenter] removeObserver:self
1306 name:@"QTMovieDidEndNotification"
1311 - (void)movieRateDidChange:(NSNotification *)notification
1315 /* For some stupid reason there is no "isPlaying" method for a QTMovie
1316 * object, given that, we detect the rate to determine whether the movie
1317 * is playing or not.
1319 //[self adjustPreviewScrubberForCurrentMovieTime];
1320 if ([aMovie rate] != 0) // we are playing
1322 [fPlayPauseButton setTitle: @"||"];
1324 else // we are paused or stopped
1326 [fPlayPauseButton setTitle: @">"];
1330 /* This notification is not currently used. However we should keep it "just in case" as
1331 * live preview playback is enhanced.
1333 - (void)movieDidEnd:(NSNotification *)notification
1336 //[fHBController writeToActivityLog: "Movie DidEnd Notification Received"];
1340 #pragma mark *** QTTime Utilities ***
1342 // convert a time value (long) to a QTTime structure
1343 -(void)timeToQTTime:(long)timeValue resultTime:(QTTime *)aQTTime
1345 NSNumber *timeScaleObj;
1346 long timeScaleValue;
1348 timeScaleObj = [aMovie attributeForKey:QTMovieTimeScaleAttribute];
1349 timeScaleValue = [timeScaleObj longValue];
1351 *aQTTime = QTMakeTime(timeValue, timeScaleValue);
1354 // set the movie's current time
1355 -(void)setTime:(int)timeValue
1358 NSValue *valueForQTTime;
1360 [self timeToQTTime:timeValue resultTime:&movieQTTime];
1362 valueForQTTime = [NSValue valueWithQTTime:movieQTTime];
1364 [aMovie setAttribute:valueForQTTime forKey:QTMovieCurrentTimeAttribute];
1370 @implementation PreviewController (Private)
1373 // -[PictureController(Private) optimalViewSizeForImageSize:]
1375 // Given the size of the preview image to be shown, returns the best possible
1376 // size for the view.
1378 - (NSSize)optimalViewSizeForImageSize: (NSSize)imageSize
1380 // The min size is 480x360
1381 CGFloat minWidth = 480.0;
1382 CGFloat minHeight = 360.0;
1384 NSSize screenSize = [[[self window] screen] visibleFrame].size;
1385 NSSize sheetSize = [[self window] frame].size;
1386 NSSize viewAreaSize = [fPictureViewArea frame].size;
1387 CGFloat paddingX = 0.00;
1388 CGFloat paddingY = 0.00;
1390 if (fTitle->width > screenSize.width || fTitle->height > screenSize.height)
1392 if (scaleToScreen == YES)
1394 paddingX = screenSize.width - imageSize.width;
1395 paddingY = screenSize.height - imageSize.height;
1400 paddingX = sheetSize.width - viewAreaSize.width;
1401 paddingY = sheetSize.height - viewAreaSize.height;
1408 maxWidth = screenSize.width - paddingX;
1409 maxHeight = screenSize.height - paddingY;
1411 NSSize resultSize = imageSize;
1412 CGFloat resultPar = resultSize.width / resultSize.height;
1414 //note, a mbp 15" at 1440 x 900 is a 1.6 ar
1415 CGFloat screenAspect = screenSize.width / screenSize.height;
1416 // Note, a standard dvd will use 720 x 480 which is a 1.5
1417 CGFloat viewAreaAspect = viewAreaSize.width / viewAreaSize.height;
1419 if (scaleToScreen == YES)
1422 if (screenAspect < viewAreaAspect)
1424 resultSize.width = screenSize.width;
1425 resultSize.height = (screenSize.width / viewAreaAspect);
1429 resultSize.height = screenSize.height;
1430 resultSize.width = resultSize.height * viewAreaAspect;
1434 else if ( resultSize.width > maxWidth || resultSize.height > maxHeight )
1436 // Source is larger than screen in one or more dimensions
1437 if ( resultPar > screenAspect )
1439 // Source aspect wider than screen aspect, snap to max width and vary height
1440 resultSize.width = maxWidth;
1441 resultSize.height = (maxWidth / resultPar);
1445 // Source aspect narrower than screen aspect, snap to max height vary width
1446 resultSize.height = maxHeight;
1447 resultSize.width = (maxHeight * resultPar);
1451 // If necessary, grow to minimum dimensions to ensure controls overlay is not obstructed
1452 if ( resultSize.width < minWidth )
1454 resultSize.width = minWidth;
1456 if ( resultSize.height < minHeight )
1458 resultSize.height = minHeight;
1467 // -[PictureController(Private) resizePanelForViewSize:animate:]
1469 // Resizes the entire window to accomodate a view of a particular size.
1471 - (void)resizeSheetForViewSize: (NSSize)viewSize
1473 // Figure out the deltas for the new frame area
1474 NSSize currentSize = [fPictureViewArea frame].size;
1475 CGFloat deltaX = viewSize.width - currentSize.width;
1476 CGFloat deltaY = viewSize.height - currentSize.height;
1478 // Now resize the whole panel by those same deltas, but don't exceed the min
1479 NSRect frame = [[self window] frame];
1480 NSSize maxSize = [[[self window] screen] visibleFrame].size;
1481 /* if we are not Scale To Screen, put an 85% of visible screen on the window */
1482 if (scaleToScreen == NO )
1484 maxSize.width = maxSize.width * 0.85;
1485 maxSize.height = maxSize.height * 0.85;
1488 /* Set our min size to the storage size */
1490 minSize.width = fTitle->width;
1491 minSize.height = fTitle->height;
1493 frame.size.width += deltaX;
1494 frame.size.height += deltaY;
1495 if( frame.size.width < minSize.width )
1497 frame.size.width = minSize.width;
1500 if( frame.size.height < minSize.height )
1502 frame.size.height = minSize.height;
1504 /* compare frame to max size of screen */
1506 if( frame.size.width > maxSize.width )
1508 frame.size.width = maxSize.width;
1511 if( frame.size.height > maxSize.height )
1513 frame.size.height = maxSize.height;
1520 // But now the sheet is off-center, so also shift the origin to center it and
1521 // keep the top aligned.
1522 if( frame.size.width != [[self window] frame].size.width )
1523 frame.origin.x -= (deltaX / 2.0);
1526 /* Since upon launch we can open up the preview window if it was open
1527 * the last time we quit (and at the size it was) we want to make
1528 * sure that upon resize we do not have the window off the screen
1529 * So check the origin against the screen origin and adjust if
1532 NSSize screenSize = [[[self window] screen] visibleFrame].size;
1533 NSPoint screenOrigin = [[[self window] screen] frame].origin;
1534 if (screenSize.height < frame.size.height)
1536 frame.size.height = screenSize.height;
1538 if (screenSize.width < frame.size.width)
1540 frame.size.width = screenSize.width;
1544 /* our origin is off the screen to the left*/
1545 if (frame.origin.x < screenOrigin.x)
1547 /* so shift our origin to the right */
1548 frame.origin.x = screenOrigin.x;
1550 else if ((frame.origin.x + frame.size.width) > (screenOrigin.x + screenSize.width))
1552 /* the right side of the preview is off the screen, so shift to the left */
1553 frame.origin.x = (screenOrigin.x + screenSize.width) - frame.size.width;
1556 [[self window] setFrame:frame display:YES animate:YES];
1562 // -[PictureController(Private) setViewSize:]
1564 // Changes the view's size and centers it vertically inside of its area.
1565 // Assumes resizeSheetForViewSize: has already been called.
1567 - (void)setViewSize: (NSSize)viewSize
1570 /* special case for scaleToScreen */
1571 NSSize screenSize = [[[self window] screen] visibleFrame].size;
1572 NSSize areaSize = [fPictureViewArea frame].size;
1573 NSSize pictureSize = [fPictureView frame].size;
1574 CGFloat viewSizeAspect = viewSize.width / viewSize.height;
1576 if (viewSize.width > areaSize.width || viewSize.height > areaSize.height)
1579 if (viewSizeAspect > 1.0) // we are wider than taller, so expand the width to fill the area and scale the height
1581 viewSize.width = areaSize.width;
1582 viewSize.height = viewSize.width / viewSizeAspect;
1586 viewSize.height = areaSize.height;
1587 viewSize.width = viewSize.height * viewSizeAspect;
1592 [fPictureView setFrameSize:viewSize];
1593 NSSize newAreaSize = [fPictureViewArea frame].size;
1596 // center it vertically and horizontally
1597 NSPoint origin = [fPictureViewArea frame].origin;
1598 origin.y += ([fPictureViewArea frame].size.height -
1599 [fPictureView frame].size.height) / 2.0;
1601 origin.x += ([fPictureViewArea frame].size.width -
1602 [fPictureView frame].size.width) / 2.0;
1604 origin.x = floor( origin.x );
1605 origin.y = floor( origin.y );
1607 [fPictureView setFrameOrigin:origin];
1612 - (BOOL)viewNeedsToResizeToSize: (NSSize)newSize
1614 NSSize viewSize = [fPictureViewArea frame].size;
1615 return (newSize.width != viewSize.width || newSize.height != viewSize.height);