On 28.06.2011, at 15:23, Kevin Muldoon wrote: > Was writing a program to create thumbnails using SIPS, GhostScript, > ImageMagick. During testing I found I needed to read the header file of Adobe > Photoshop native documents directly because Duotone image color mode simply > wasn't returning the proper color mode (in a variety of programs). > > So I threw together this bit of code which works great for the first tag, > but.... > > // References > > //http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/PhotoshopFileFormats.htm#50577409_pgfId-1055726 > > //http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/psir/ps_image_resources.pdf > > NSFileHandle *fileHandler = [NSFileHandle > fileHandleForReadingAtPath:@"/Users/kevin/Desktop/balloon.psd"]; > > NSData *psdFileHeader = [NSData dataWithData:[fileHandler > readDataOfLength:26]]; // read entire PSD header > > NSData *signature = [psdFileHeader subdataWithRange: NSMakeRange(0,4)]; > NSData *version = [psdFileHeader subdataWithRange: NSMakeRange(4,2)]; > NSData *reserved = [psdFileHeader subdataWithRange: NSMakeRange(6,6)];
You're doing the worst case for performancewise. The usual way would be to define a struct #pragma pack (push, 2) typedef struct { uint32_t psdMagic; uint16_t version; uint16_t reserved1; uint32_t reserved2; } PSDHeader; and use it with code like: NSData * psdHdrData = [NSData dataWithData:[fileHandler readDataOfLength:sizeof( PSDHeader )]]; // read entire PSD header PSDHeader *header = (psdHeader *) [psdHdrData bytes]; psdMagic = CFEndianBToN( header->psdMagic ); _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com