- (BOOL)exportManagerShouldWriteImageData:(NSData *)imageData
toRelativePath:(NSString *)path forImageAtIndex:(unsigned)index
{
NSUInteger width, height;
NSUInteger longestEdge;
double scaleFactor;
BOOL longestEdgeIsWidth;
NSString *resizedImagePath = [path copy];
NSLog(@"Examining: %@", resizedImagePath);
CGImageRef resizedImageRef = NULL;
CFURLRef baseURLRef =
CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
(CFStringRef)_exportPath, kCFURLPOSIXPathStyle, true);
// Create our full size CGImage from the provided data
CGImageSourceRef imageSourceRef =
CGImageSourceCreateWithData((CFDataRef)imageData, NULL);
if (imageSourceRef != NULL) {
CGImageRef fullSizeImageRef =
CGImageSourceCreateImageAtIndex(imageSourceRef, 0, NULL);
CFRelease(imageSourceRef);
CGContextRef context = NULL;
width = CGImageGetWidth(fullSizeImageRef);
height = CGImageGetHeight(fullSizeImageRef);
if (width > height) {
longestEdge = width;
longestEdgeIsWidth = YES;
}
else {
longestEdge = height;
longestEdgeIsWidth=NO;
}
if (longestEdge >1280) {
NSLog(@" and resizing....");
scaleFactor = 1280.0/longestEdge;
NSUInteger newWidth = round(width*scaleFactor);
NSUInteger newHeight = round(height*scaleFactor);
CGColorSpaceRef colorspace = CGImageGetColorSpace(fullSizeImageRef);
void * bitmapData;
int bitmapBytesPerRow = (newWidth * 4);
int bitmapByteCount = (bitmapBytesPerRow * newHeight);
bitmapData = malloc( bitmapByteCount );
context = CGBitmapContextCreate(bitmapData, newWidth,
newHeight, 8,bitmapBytesPerRow, colorspace,
kCGImageAlphaNoneSkipFirst);
CGContextDrawImage(context, CGRectMake(0, 0, newWidth,
newHeight), fullSizeImageRef);
resizedImageRef= CGBitmapContextCreateImage(context);
CFRelease(fullSizeImageRef);
CFRelease(colorspace);
CFRelease(context);
free(bitmapData);
}
else {
//Image is within requirements, simply use a copy.
resizedImageRef = CGImageCreateCopy(fullSizeImageRef);
CFRelease(fullSizeImageRef);
}
resizedImagePath = [resizedImagePath stringByDeletingPathExtension];
resizedImagePath = [resizedImagePath stringByAppendingPathExtension:@"jpg"];
NSDictionary* image_dict = [_exportManager propertiesForImageAtIndex:index];
NSString* project_name = [[image_dict
objectForKey:kExportKeyProjectName] retain];
CFURLRef resizedFileURLRef =
CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorDefault,
(CFStringRef)resizedImagePath, kCFURLPOSIXPathStyle, false,
baseURLRef);
CGImageDestinationRef imageDestinationRef =
CGImageDestinationCreateWithURL(resizedFileURLRef, kUTTypeJPEG, 1,
NULL);
NSMutableDictionary *imageProperties = [[NSMutableDictionary alloc] init];
[imageProperties setObject:[NSNumber numberWithInt:1]
forKey:(NSString *)kCGImageDestinationLossyCompressionQuality];
CGImageDestinationAddImage(imageDestinationRef, resizedImageRef,
(CFDictionaryRef) imageProperties);
CGImageDestinationFinalize(imageDestinationRef);
CFRelease(imageDestinationRef);
[imageProperties release];
CFRelease(resizedImageRef);
NSNumber *fileSize = [self sizeOfFileAtPath:(NSURL*) resizedFileURLRef];
NSString* fileRefString = [self fileSystemStringOfPath:(NSURL
*)resizedFileURLRef];
CFRelease(resizedFileURLRef);
CFRelease(baseURLRef);
totalBytes += [fileSize longValue];
// Increment the current progress
[self lockProgress];
exportProgress.currentValue++;
[self unlockProgress];}
return NO;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Aperture-dev mailing list (Apertu...@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/aperture-dev/aperture-dev%2Bgarchive-9674%40googlegroups.com
This email sent to aperture-dev+...@googlegroups.com
The CGImageGetColorSpace() function does not follow the Create Rule <http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html>, so you should _not_ be calling CFRelease(colorSpace) — you've over-released the object.
> http://lists.apple.com/mailman/options/aperture-dev/clarence%40blueroomsoftware.com
>
> This email sent to clar...@blueroomsoftware.com
You're a lifesaver :) Thank you so much! That seems to have fixed it.
Best regards,
Chris.