summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2016-01-15 09:51:23 +0100
committerDamiano Galassi <[email protected]>2016-01-15 09:51:23 +0100
commit7372e56f3f3c98c4c70d9cf3bf81fd4b85c3fe9b (patch)
tree8b5a32fb2fdd713538f3a351b48acd14bb80d5b3 /macosx
parent9d4bbeefaba8f6dabdc8e48b34feb7de2d057a68 (diff)
MacGui: update the preview window to reflect the rotate filter state.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/HBCore.h8
-rw-r--r--macosx/HBCore.m65
-rw-r--r--macosx/HBPreviewGenerator.m4
3 files changed, 71 insertions, 6 deletions
diff --git a/macosx/HBCore.h b/macosx/HBCore.h
index 2c1830f5b..6a50142ca 100644
--- a/macosx/HBCore.h
+++ b/macosx/HBCore.h
@@ -144,9 +144,11 @@ typedef void (^HBCoreCompletionHandler)(HBCoreResult result);
* @return a CGImageRef of the wanted image, NULL if the index is out of bounds.
*/
- (nullable CGImageRef)copyImageAtIndex:(NSUInteger)index
- forTitle:(HBTitle *)title
- pictureFrame:(HBPicture *)frame
- deinterlace:(BOOL)deinterlace CF_RETURNS_RETAINED;
+ forTitle:(HBTitle *)title
+ pictureFrame:(HBPicture *)frame
+ deinterlace:(BOOL)deinterlace
+ rotate:(int)angle
+ flipped:(BOOL)flipped CF_RETURNS_RETAINED;
/**
* Returns the counts of the available previews images.
diff --git a/macosx/HBCore.m b/macosx/HBCore.m
index cdb831fb3..829fcfdce 100644
--- a/macosx/HBCore.m
+++ b/macosx/HBCore.m
@@ -279,10 +279,62 @@ static void hb_error_handler(const char *errmsg)
#pragma mark - Preview images
+- (CGImageRef)CGImageRotatedByAngle:(CGImageRef)imgRef angle:(CGFloat)angle flipped:(BOOL)flipped CF_RETURNS_RETAINED
+{
+ CGFloat angleInRadians = angle * (M_PI / 180);
+ CGFloat width = CGImageGetWidth(imgRef);
+ CGFloat height = CGImageGetHeight(imgRef);
+
+ CGRect imgRect = CGRectMake(0, 0, width, height);
+ CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians);
+ CGRect rotatedRect = CGRectApplyAffineTransform(imgRect, transform);
+
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+ CGContextRef bmContext = CGBitmapContextCreate(NULL,
+ (size_t)rotatedRect.size.width,
+ (size_t)rotatedRect.size.height,
+ 8,
+ 0,
+ colorSpace,
+ kCGImageAlphaPremultipliedFirst);
+ CGContextSetAllowsAntialiasing(bmContext, FALSE);
+ CGContextSetInterpolationQuality(bmContext, kCGInterpolationNone);
+ CGColorSpaceRelease(colorSpace);
+
+ // Rotate
+ CGContextTranslateCTM(bmContext,
+ + (rotatedRect.size.width / 2),
+ + (rotatedRect.size.height / 2));
+ CGContextRotateCTM(bmContext, -angleInRadians);
+ CGContextTranslateCTM(bmContext,
+ - (rotatedRect.size.width / 2),
+ - (rotatedRect.size.height / 2));
+
+ // Flip
+ if (flipped) {
+ CGAffineTransform flipHorizontal = CGAffineTransformMake(-1, 0, 0, 1, floor(rotatedRect.size.width), 0);
+ CGContextConcatCTM(bmContext, flipHorizontal);
+ }
+
+ CGContextDrawImage(bmContext,
+ CGRectMake((rotatedRect.size.width - width)/2.0f,
+ (rotatedRect.size.height - height)/2.0f,
+ width,
+ height),
+ imgRef);
+
+ CGImageRef rotatedImage = CGBitmapContextCreateImage(bmContext);
+ CFRelease(bmContext);
+
+ return rotatedImage;
+}
+
- (CGImageRef)copyImageAtIndex:(NSUInteger)index
forTitle:(HBTitle *)title
pictureFrame:(HBPicture *)frame
deinterlace:(BOOL)deinterlace
+ rotate:(int)angle
+ flipped:(BOOL)flipped CF_RETURNS_RETAINED
{
CGImageRef img = NULL;
@@ -339,8 +391,17 @@ static void hb_error_handler(const char *errmsg)
hb_image_close(&image);
}
-
- return img;
+
+ if (angle || flipped)
+ {
+ CGImageRef rotatedImg = [self CGImageRotatedByAngle:img angle:angle flipped:flipped];
+ CGImageRelease(img);
+ return rotatedImg;
+ }
+ else
+ {
+ return img;
+ }
}
- (NSUInteger)imagesCountForTitle:(HBTitle *)title
diff --git a/macosx/HBPreviewGenerator.m b/macosx/HBPreviewGenerator.m
index d85f102e3..06f442317 100644
--- a/macosx/HBPreviewGenerator.m
+++ b/macosx/HBPreviewGenerator.m
@@ -81,7 +81,9 @@
theImage = (CGImageRef)[self.scanCore copyImageAtIndex:index
forTitle:self.job.title
pictureFrame:self.job.picture
- deinterlace:deinterlace];
+ deinterlace:deinterlace
+ rotate:self.job.filters.rotate
+ flipped:self.job.filters.flip];
if (cache && theImage)
{
// The cost is the number of pixels of the image