diff options
author | Damiano Galassi <[email protected]> | 2018-10-10 19:58:21 +0200 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2018-10-10 19:58:21 +0200 |
commit | 2264d25308238210892840d7de3fa1edf9de105e (patch) | |
tree | 0285fd80ba9717f50219a45b8891d072f030c77f /macosx/HBImageUtilities.m | |
parent | 210164589bd29a2b21cfd58a928aa11e603782eb (diff) |
MacGui: add touch bars in the preview window, improve touch bars in the main and queue windows.
Diffstat (limited to 'macosx/HBImageUtilities.m')
-rw-r--r-- | macosx/HBImageUtilities.m | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/macosx/HBImageUtilities.m b/macosx/HBImageUtilities.m index 07530d815..d5858c60d 100644 --- a/macosx/HBImageUtilities.m +++ b/macosx/HBImageUtilities.m @@ -8,6 +8,59 @@ #import <Cocoa/Cocoa.h> #include "hb.h" +CGImageRef CreateScaledCGImageFromCGImage(CGImageRef image, CGFloat thumbnailHeight) +{ + // Create the bitmap context + CGContextRef context = NULL; + void * bitmapData; + int bitmapByteCount; + int bitmapBytesPerRow; + + // Get image width, height. We'll use the entire image. + int width = (CGFloat)CGImageGetWidth(image) / (CGFloat)CGImageGetHeight(image) * thumbnailHeight; + int height = thumbnailHeight; + + // Declare the number of bytes per row. Each pixel in the bitmap in this + // example is represented by 4 bytes; 8 bits each of red, green, blue, and + // alpha. + bitmapBytesPerRow = (width * 4); + bitmapByteCount = (bitmapBytesPerRow * height); + + // Allocate memory for image data. This is the destination in memory + // where any drawing to the bitmap context will be rendered. + bitmapData = malloc(bitmapByteCount); + if (bitmapData == NULL) + { + return nil; + } + + // Create the bitmap context. We want pre-multiplied ARGB, 8-bits + // per component. Regardless of what the source image format is + // (CMYK, Grayscale, and so on) it will be converted over to the format + // specified here by CGBitmapContextCreate. + CGColorSpaceRef colorspace = CGImageGetColorSpace(image); + context = CGBitmapContextCreate (bitmapData,width,height,8,bitmapBytesPerRow, + colorspace,kCGImageAlphaNoneSkipFirst); + + if (context == NULL) + { + // error creating context + return nil; + } + + // Draw the image to the bitmap context. Once we draw, the memory + // allocated for the context for rendering will then contain the + // raw image data in the specified color space. + CGContextDrawImage(context, CGRectMake(0,0,width, height), image); + + CGImageRef imgRef = CGBitmapContextCreateImage(context); + CGContextRelease(context); + free(bitmapData); + + return imgRef; +} + + CGImageRef CGImageRotated(CGImageRef imgRef, CGFloat angle, BOOL flipped) CF_RETURNS_RETAINED { CGFloat angleInRadians = angle * (M_PI / 180); |