diff options
author | ritsuka <[email protected]> | 2014-07-30 06:30:21 +0000 |
---|---|---|
committer | ritsuka <[email protected]> | 2014-07-30 06:30:21 +0000 |
commit | 87197ca0eba8e17328594a21dc0ba67cd0728435 (patch) | |
tree | 2bdb2a8983ef5cf26809a311021d80cc46943cfa /macosx/HBPreviewGenerator.m | |
parent | d410fe2120a7ec1115bf83634b9ae55cbb203ba5 (diff) |
MacGui: check if the image returned by hb_get_preview2 is null to avoid a crash. The preview window will try to show the number of previews selected in the preferences, but an already loaded title might not have enough preview images.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6244 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBPreviewGenerator.m')
-rw-r--r-- | macosx/HBPreviewGenerator.m | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/macosx/HBPreviewGenerator.m b/macosx/HBPreviewGenerator.m index 6e55af152..2ea7b2aad 100644 --- a/macosx/HBPreviewGenerator.m +++ b/macosx/HBPreviewGenerator.m @@ -100,6 +100,8 @@ typedef enum EncodeState : NSUInteger { title: (hb_title_t *) title deinterlace: (BOOL) deinterlace { + NSImage *img = nil; + hb_ui_geometry_t geo; geo.width = title->job->width; geo.height = title->job->height; @@ -112,42 +114,45 @@ typedef enum EncodeState : NSUInteger { 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. - - // 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++) + if (image) { - UInt32 *src = (UInt32 *)src_line; - for (int c = 0; c < image->width; c++) + // 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++); + *dst++ = Endian32_Swap(*src++); #else - *dst++ = *src++; + *dst++ = *src++; #endif + } + src_line += image->plane[0].stride; } - src_line += image->plane[0].stride; - } - NSImage *img = [[[NSImage alloc] initWithSize: NSMakeSize(image->width, image->height)] autorelease]; - [img addRepresentation:imgrep]; + img = [[[NSImage alloc] initWithSize: NSMakeSize(image->width, image->height)] autorelease]; + [img addRepresentation:imgrep]; + } hb_image_close(&image); |