diff options
author | ritsuka <[email protected]> | 2014-07-29 20:19:38 +0000 |
---|---|---|
committer | ritsuka <[email protected]> | 2014-07-29 20:19:38 +0000 |
commit | d410fe2120a7ec1115bf83634b9ae55cbb203ba5 (patch) | |
tree | 4c166d74fc6307f3009868f183c6897bb0ee5d11 | |
parent | 6942656aeac26e63e87d8c1772ccec3e64b437e1 (diff) |
MacGui: use the new preview generation method hb_get_preview2.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6243 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | macosx/HBPreviewGenerator.m | 75 |
1 files changed, 33 insertions, 42 deletions
diff --git a/macosx/HBPreviewGenerator.m b/macosx/HBPreviewGenerator.m index 45c4571a0..6e55af152 100644 --- a/macosx/HBPreviewGenerator.m +++ b/macosx/HBPreviewGenerator.m @@ -67,7 +67,7 @@ typedef enum EncodeState : NSUInteger { libhb:self.handle title:self.title deinterlace:self.deinterlace]; - if (cache) + if (cache && theImage) [self.picturePreviews setObject:theImage forKey:@(index)]; } @@ -90,76 +90,67 @@ typedef enum EncodeState : NSUInteger { * 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 picture Index in title. - * @param h Handle to hb_handle_t. + * @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 title: (hb_title_t *) title deinterlace: (BOOL) deinterlace { - static uint8_t *buffer; - static int bufferSize; - - // Make sure we have a big enough buffer to receive the image from libhb - int dstWidth = title->job->width; - int dstHeight = title->job->height; - - int newSize = dstWidth * dstHeight * 4; - if (!buffer || bufferSize < newSize) - { - bufferSize = newSize; - buffer = (uint8_t *) realloc( buffer, bufferSize ); - } - - // Enable and the disable deinterlace just for preview if deinterlace - // or decomb filters are enabled - int deinterlaceStatus = title->job->deinterlace; - if (deinterlace) title->job->deinterlace = 1; - - hb_get_preview( handle, title->job, (int)pictureIndex, buffer ); - - // Reset deinterlace status - title->job->deinterlace = deinterlaceStatus; + hb_ui_geometry_t geo; + geo.width = title->job->width; + geo.height = title->job->height; + // HBPreviewController will scale the image later, + // ignore the par. + geo.par.num = 1; + geo.par.den = 1; + memcpy(geo.crop, title->job->crop, sizeof(int[4])); + + hb_image_t *image; + image = hb_get_preview2(handle, title->index, (int)pictureIndex, &geo, deinterlace); // Create an NSBitmapImageRep and copy the libhb image into it, converting it from - // libhb's format to one suitable for NSImage. Along the way, we'll strip off the - // border around libhb's image. + // libhb's format to one suitable for NSImage. - // The image data returned by hb_get_preview is 4 bytes per pixel, BGRA format. + // The image data returned by hb_get_preview2 is 4 bytes per pixel, BGRA format. // Alpha is ignored. - - NSBitmapFormat bitmapFormat = (NSBitmapFormat)NSAlphaFirstBitmapFormat; - NSBitmapImageRep * imgrep = [[[NSBitmapImageRep alloc] + NSBitmapImageRep *imgrep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil - pixelsWide:dstWidth - pixelsHigh:dstHeight + pixelsWide:image->width + pixelsHigh:image->height bitsPerSample:8 samplesPerPixel:3 // ignore alpha hasAlpha:NO isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace - bitmapFormat:bitmapFormat - bytesPerRow:dstWidth * 4 + bitmapFormat:NSAlphaFirstBitmapFormat + bytesPerRow:image->width * 4 bitsPerPixel:32] autorelease]; - UInt32 * src = (UInt32 *)buffer; - UInt32 * dst = (UInt32 *)[imgrep bitmapData]; - int r, c; - for (r = 0; r < dstHeight; r++) + UInt8 *src_line = image->data; + UInt32 *dst = (UInt32 *)[imgrep bitmapData]; + for (int r = 0; r < image->height; r++) { - for (c = 0; c < dstWidth; c++) + 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; } - NSImage * img = [[[NSImage alloc] initWithSize: NSMakeSize(dstWidth, dstHeight)] autorelease]; + NSImage *img = [[[NSImage alloc] initWithSize: NSMakeSize(image->width, image->height)] autorelease]; [img addRepresentation:imgrep]; + hb_image_close(&image); + return img; } |