diff options
author | ritsuka <[email protected]> | 2015-01-26 08:30:23 +0000 |
---|---|---|
committer | ritsuka <[email protected]> | 2015-01-26 08:30:23 +0000 |
commit | de6e8f85686ad3f63be7fba7b4bf10aa1912a09a (patch) | |
tree | aa4a061b01b810e38a6d3af245a2380aceb58839 /macosx/HBPreviewGenerator.m | |
parent | 9545f5c9b6c3160b0e6cba9344232cb9e1493aaf (diff) |
MacGui: add a method to return a CGImageRef for a preview in HBCore, and skip the alpha to use less memory. Use a dispatch_source as a timer in HBCore so we will be able to run the update loop on its own thread. Remove the pointer to hb_handle_t, no class outside HBCore uses it.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6816 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBPreviewGenerator.m')
-rw-r--r-- | macosx/HBPreviewGenerator.m | 97 |
1 files changed, 10 insertions, 87 deletions
diff --git a/macosx/HBPreviewGenerator.m b/macosx/HBPreviewGenerator.m index c4a0d2aa7..61ed448bb 100644 --- a/macosx/HBPreviewGenerator.m +++ b/macosx/HBPreviewGenerator.m @@ -10,11 +10,10 @@ #import "HBCore.h" #import "HBJob.h" -#import "HBJob+HBJobConversion.h" @interface HBPreviewGenerator () -@property (nonatomic, readonly, retain) NSMutableDictionary *picturePreviews; +@property (nonatomic, readonly) NSMutableDictionary *picturePreviews; @property (nonatomic, readonly) NSUInteger imagesCount; @property (nonatomic, readonly) HBCore *scanCore; @property (nonatomic, readonly) HBJob *job; @@ -46,26 +45,28 @@ * * @param index picture index in title. */ -- (NSImage *) imageAtIndex: (NSUInteger) index shouldCache: (BOOL) cache +- (CGImageRef) imageAtIndex: (NSUInteger) index shouldCache: (BOOL) cache { if (index >= self.imagesCount) return nil; // The preview for the specified index may not currently exist, so this method // generates it if necessary. - NSImage *theImage = [self.picturePreviews objectForKey:@(index)]; + CGImageRef theImage = (CGImageRef)[self.picturePreviews objectForKey:@(index)]; if (!theImage) { HBFilters *filters = self.job.filters; BOOL deinterlace = (filters.deinterlace && !filters.useDecomb) || (filters.decomb && filters.useDecomb); - theImage = [HBPreviewGenerator makeImageForPicture:index - libhb:self.scanCore.hb_handle - picture:self.job.picture - deinterlace:deinterlace]; + theImage = (CGImageRef)[(id)[self.scanCore copyImageAtIndex:index + forTitle:self.job.title + pictureFrame:self.job.picture + deinterlace:deinterlace] autorelease]; if (cache && theImage) - [self.picturePreviews setObject:theImage forKey:@(index)]; + { + [self.picturePreviews setObject:(id)theImage forKey:@(index)]; + } } return theImage; @@ -80,84 +81,6 @@ [self.picturePreviews removeAllObjects]; } -/** - * This function converts an image created by libhb (specified via pictureIndex) into - * an NSImage suitable for the GUI code to use. If removeBorders is YES, - * makeImageForPicture crops the image generated by libhb stripping off the gray - * border around the content. This is the low-level method that generates the image. - * -imageForPicture calls this function whenever it can't find an image in its cache. - * - * @param pictureIndex Index in title. - * @param handle Handle to hb_handle_t. - * @param title Handle to hb_title_t of desired title. - * @param deinterlace Whether the preview image must be deinterlaced or not. - */ -+ (NSImage *) makeImageForPicture: (NSUInteger) pictureIndex - libhb: (hb_handle_t *) handle - picture: (HBPicture *) picture - deinterlace: (BOOL) deinterlace -{ - NSImage *img = nil; - - hb_geometry_settings_t geo; - memset(&geo, 0, sizeof(geo)); - geo.geometry.width = picture.width; - geo.geometry.height = picture.height; - // HBPreviewController will scale the image later, - // ignore the par. - geo.geometry.par.num = 1; - geo.geometry.par.den = 1; - int crop[4] = {picture.cropTop, picture.cropBottom, picture.cropLeft, picture.cropRight}; - memcpy(geo.crop, crop, sizeof(int[4])); - - hb_image_t *image; - image = hb_get_preview2(handle, picture.title.hb_title->index, (int)pictureIndex, &geo, deinterlace); - - if (image) - { - // Create an NSBitmapImageRep and copy the libhb image into it, converting it from - // libhb's format to one suitable for NSImage. - - // The image data returned by hb_get_preview2 is 4 bytes per pixel, BGRA format. - // Alpha is ignored. - NSBitmapImageRep *imgrep = [[[NSBitmapImageRep alloc] - initWithBitmapDataPlanes:nil - pixelsWide:image->width - pixelsHigh:image->height - bitsPerSample:8 - samplesPerPixel:3 // ignore alpha - hasAlpha:NO - isPlanar:NO - colorSpaceName:NSCalibratedRGBColorSpace - bitmapFormat:NSAlphaFirstBitmapFormat - bytesPerRow:image->width * 4 - bitsPerPixel:32] autorelease]; - - UInt8 *src_line = image->data; - UInt32 *dst = (UInt32 *)[imgrep bitmapData]; - for (int r = 0; r < image->height; r++) - { - UInt32 *src = (UInt32 *)src_line; - for (int c = 0; c < image->width; c++) - { -#if TARGET_RT_LITTLE_ENDIAN - *dst++ = Endian32_Swap(*src++); -#else - *dst++ = *src++; -#endif - } - src_line += image->plane[0].stride; - } - - img = [[[NSImage alloc] initWithSize: NSMakeSize(image->width, image->height)] autorelease]; - [img addRepresentation:imgrep]; - } - - hb_image_close(&image); - - return img; -} - #pragma mark - #pragma mark Preview movie |