• 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
Re: Reading Adobe Photoshop header, Obj-C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reading Adobe Photoshop header, Obj-C


  • Subject: Re: Reading Adobe Photoshop header, Obj-C
  • From: Kevin Muldoon <email@hidden>
  • Date: Tue, 28 Jun 2011 13:11:39 -0400

Hey Jens,

I suppose the trouble here is that I'm familiar with Objective-C code and not so familiar with its parent, C.

On Jun 28, 2011, at 1:00 PM, Jens Alfke wrote:


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


Kevin Muldoon
e: email@hidden

_______________________________________________

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


  • Follow-Ups:
    • Re: Reading Adobe Photoshop header, Obj-C
      • From: Jens Alfke <email@hidden>
References: 
 >Reading Adobe Photoshop header, Obj-C (From: Kevin Muldoon <email@hidden>)
 >Re: Reading Adobe Photoshop header, Obj-C (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: sorting a pair of arrays
  • Next by Date: Re: Reading Adobe Photoshop header, Obj-C
  • Previous by thread: Re: Reading Adobe Photoshop header, Obj-C
  • Next by thread: Re: Reading Adobe Photoshop header, Obj-C
  • Index(es):
    • Date
    • Thread