• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
More CoreImage / CGImage questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

More CoreImage / CGImage questions


  • Subject: More CoreImage / CGImage questions
  • From: Jim Crate <email@hidden>
  • Date: Mon, 19 Nov 2007 13:20:31 -0500

Thanks for all replies to my previous question.

I've gotten acceptable performance with large images in my program, by not using the large images until necessary. CGImageSourceCreateThumbnailAtIndex will create thumbnails at any size, so a simple thing to do is create a preview reference the size of the screen, which means it will always be scaled down to fit the view anyway. However, I now have a different problem.

I left the view as a normal NSImageView, and I create an NSImage with an NSCIImageRep. This works well, performance is great and the image displays correctly, although there are memory leaks that have to be chased down. Googling has found several people mentioning that using that method leaks lots of memory.

I also have to save these files, and since the existing code used an NSBitmapImageRep, I decided a category on CIImage might be nice:

-(NSImage *)NSImageWithNSCIImageRep
{
NSImage *image = [[[NSImage alloc] initWithSize:NSMakeSize([self extent].size.width, [self extent].size.height)] autorelease];
[image addRepresentation:[NSCIImageRep imageRepWithCIImage:self]];
return image;
}


However, the images wrote out with lines and other artifacts. I thought I had seen someone mention this before, but I cannot find that now. If I change the code that updates the view to create the view's NSImage using this method instead of the NSCIImageRep, the image displays rendered incorrectly as well, whether from the preview image or the full-sized image.

Since my end goal is to save the images using CGImage and Image I/O, I set up that code to see if it worked any better. As a category on CIImage:


- (CGImageRef)createCGImage
{
int width = [self extent].size.width;
int rows = [self extent].size.height;
int rowBytes = (width * 4);

CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault;

CGContextRef cgContext = CGBitmapContextCreate(NULL, width, rows, 8, rowBytes, colorSpace, bitmapInfo);

// get the CIContext and render the CIImage
CIContext* ciContext = [CIContext contextWithCGContext:cgContext options:nil];
CGImageRef cgImage = [ciContext createCGImage:self fromRect:[self extent]];

CGContextRelease(cgContext);
CGColorSpaceRelease(colorSpace);

return cgImage;
}



I also tried using this to create the CGImage in this method:

	[ciContext drawImage:self atPoint:CGPointZero fromRect: [self extent]];
	CGImageRef cgImage = CGBitmapContextCreateImage(cgContext);

However, the file saved has the same type of artifacts. The overlaid image may not display at all, or the file may have anything from a few thin white lines to being completely illegible, like this one:

http://www.quevivadev.com/test.jpg

In addition, while a large image (18000 x 14400) will render using NSCIImageRep or (incorrectly) into an NSBitmapImageRep, if I try to create a CGImage it will crash deep in the rendering code when calling [ciContext createCGImage:self fromRect:[self extent]]. Images up to 10000 x 8000 render into a CGImage, albeit similar to the test image above.

Has anyone seen this kind of problem before, or have any pointers on where to continue searching for a solution?

Thanks,

Jim

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >CoreImage problems with very large images (From: Jim Crate <email@hidden>)

  • Prev by Date: Re: Programatically creating a checkbox
  • Next by Date: Huge increase in memory usage on Leopard
  • Previous by thread: Re: CoreImage problems with very large images
  • Next by thread: re: CoreImage problems with very large images
  • Index(es):
    • Date
    • Thread