Scheme for efficiently archiving images.
Scheme for efficiently archiving images.
- Subject: Scheme for efficiently archiving images.
- From: Graham Cox <email@hidden>
- Date: Thu, 27 Nov 2008 12:26:34 +1100
In my app I have a class that "has a" NSImage which it displays.
Currently, when I archive the whole kit-n-kaboodle when saving to a
file, the image simply gets archived as an object. With small images
it's not too bad, but I have noticed for some larger images a huge
amount of inflation occurs. For example, loading a 400K JPEG image
then archiving the result inflates to >20MB. This is unsurprising
since archiving the raw NSImage object will save off all of its
representations...
So, I'm thinking about ways to improve the situation. Images can enter
the app in three ways, from a file, from the pasteboard and by
unarchiving a file saved earlier. For images from a file, I am
thinking I can copy the original file into my package and simply
archive a relative path to it. For the pasteboard case I don't have a
file but it could be in compressed form as NSData so I could archive
that. I would also like to deal with the possibility that two objects
have the same image, in which case I only need to save one copy.
There are a few issues though. When my image-owning objects gets its -
encodeWithCoder: message, the package it's going to create may not
exist yet, and I'm not sure how I can find out at that point what it
will be. So I wondered if I could archive a file wrapper at that point
with the original file data. Would that achieve anything? (I'm
guessing not - a file wrapper embedded in the archive stream will not
be visible to the high-level file archiving done by NSDocument so it's
no advantage over archiving NSData - but correct me if I'm wrong).
Also, NSImage has -setDataRetained which could help, but I can't see a
way to get that data from the image. Again, I assume I can workaround
it by retaining the original data myself directly.
As for sharing copies of an image, I thought maybe a global or per-
document dictionary that held the data and then just archive the key...
For bitmap images I could also archive a compressed TIFFRepresentation
which would help somewhat without being lossy, but saving the original
JPEG data would be better (most images come in as JPEG, but I support
all formats that NSImage supports), and for PDF images, I want to keep
them in that format, not convert to bitmaps.
Has anyone had experience of dealing with this, or has any ideas? At
this stage I guess I'm just kicking around ideas to try and get a
clearer idea of the right way to go.
thanks, Graham
_______________________________________________
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