I'm trying to flip an NSImage created with a NSImageBitmapRep representation. After some digging (Flipping Quicktime preview & capture and Mirroring CIImage/NSImage) I tried two ways via a CIImage and applying a scaling transformation with -1 for both factors.
First using CIImage imageByApplyingTransform:
NSBitmapImageRep *imgRep = ...
CGImageRef cgi = [imgRep CGImage];
CIImage *cii = [CIImage imageWithCGImage:cgi];
CGAffineTransform at = CGAffineTransformTranslate(CGAffineTransformMakeScale(-1, -1), 0, 0);
NSCIImageRep *ciiRep = [NSCIImageRep imageRepWithCIImage:[cii imageByApplyingTransform:at]];
NSImage *img = [[[NSImage alloc] init] autorelease];
[img addRepresentation:ciiRep];
[self.ivImage setImage:img];
then using a CIAffineTransform filter:
NSBitmapImageRep *imgRep = ...
CGImageRef cgi = [imgRep CGImage];
CIImage *cii = [CIImage imageWithCGImage:cgi];
CIFilter *f = [CIFilter filterWithName:@"CIAffineTransform"];
NSAffineTransform *t = [NSAffineTransform transform];
[t scaleXBy:1.0 yBy:1.0];
//[t translateXBy:width yBy:0];
[f setValue:t forKey:@"inputTransform"];
[f setValue:cii forKey:@"inputImage"];
CIImage *cii2 = [f valueForKey:@"outputImage"];
NSCIImageRep *ciiRep = [NSCIImageRep imageRepWithCIImage:cii2];
NSImage *img = [[[NSImage alloc] init] autorelease];
[img addRepresentation:ciiRep];
[self.ivImage setImage:img];
Both ways produce a blank image. I've also tried to translate the image, in case it is out of screen because of the -1 scalings, but to no avail. If I use positive values for scaling I can see that the transformation is applied correctly.
self.ivImage is an NSImageView. I want an actual NSImage which is flipped, so applying a transformation to the NSImageView is not an option.
This is 32bits, Xcode 4.3.2 on Lion.