Re: Reading Adobe Photoshop header, Obj-C
Re: Reading Adobe Photoshop header, Obj-C
- Subject: Re: Reading Adobe Photoshop header, Obj-C
- From: Jens Alfke <email@hidden>
- Date: Tue, 28 Jun 2011 10:00:51 -0700
On Jun 28, 2011, at 6:23 AM, Kevin Muldoon wrote:
> As you can see from the output, the 'version' & 'reserved' isn't being read at all. Must I coerce/parse something here? Much thanks…
I’m not familiar with the PSD format, but aren’t ‘version’ and ‘reserved’ binary? You’re printing them as C strings.
Assuming ‘version’ is a 16-bit big-endian integer, you could read it like this:
const uint8_t* bytes = [signature bytes];
uint16_t version = *(const uint16_t*)(bytes + 2);
version = NSSwapBigShortToHost(version);
Another way (that I often use) is to define a C struct that matches the fields and layout of the header, then cast the bytes to a pointer to that struct and read the fields. It makes your code look a lot cleaner, but you have to be careful to (a) make sure the compiler packs the struct fields properly, and (b) you byte-swap all integer/float fields appropriately.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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