Re: some questions about creating image thumbnails
Re: some questions about creating image thumbnails
- Subject: Re: some questions about creating image thumbnails
- From: "Adam R. Maxwell" <email@hidden>
- Date: Wed, 09 Apr 2008 10:48:35 -0700
On Wednesday, April 09, 2008, at 08:35AM, "Jesse Grosjean" <email@hidden> wrote:
>I have a situation where I've got a NSImage reference in memory and
>I'd like to save that image at full size and in a number of thumbnail
>sizes as quickly as possible. I know how to implement the basics, but
>I have no idea if I'm doing it in the most efficient way. In particular:
>
>To save the full sizes image I'm using some code like this:
>
> [[artworkImage
>TIFFRepresentationUsingCompression:NSTIFFCompressionNone factor:0]
>writeToFile:file atomically:NO]
>
>That brings up these questions:
>
>1. If I don't care about on disk size is NSTIFFCompressionNone a fast
>way to write? (assuming that compression would take more time). Or
>maybe compression will actually save me time since the disk write will
>be faster?
You really need to use Shark to figure this out for your use case. In my testing, compressing image data with zlib at the lowest compression level was a big win over zero compression in overall time spent to create an image, just because of the smaller reads.
>2. And how does the image format effect read time, after all that's
>what I'm really trying to optimize in the first place by creating the
>caches?
>2. Is TIFFRepresentation a good way to go or should I really be using
>some other framework like image IO or something else if I'm concerned
>with efficiency.
Again, Shark will tell you if it's significant. Using ImageIO will require you to use CGImage, so you'd incur some additional overhead creating NSImages from CGImages.
If you want lossless compression, PNG is good quality, but may be slow; same story for JPEG2000. I have performance problems drawing Finder icons that are apparently compressed internally as JPEG2000, so my suspicion is that it might be slow across the board. But don't take my word for it: use Shark :).
>For the thumbnails I'm just creating new NSImages of the correct size,
>locking focus on them, and then drawing the original image into the
>smaller image, and writing them out as above. Is there a smarter way?
If you want more control, you could use CoreImage with a Lanczos filter, or use vImage on an NSBitmapImageRep. I'm using vImage for my thumbnail scaling, but it ended up being nontrivial. E-mail me offlist if you want the link; it's a BSD licensed framework for a grid view of images, with code for multithreaded scaling and creating/saving/loading thumbnails, mainly optimized for memory usage.
hth,
Adam
_______________________________________________
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