Re: NSBitmapImageRep returns wrong bitsPerSample and bitsPerPixel values for 8 & 16-bit BMP's
Re: NSBitmapImageRep returns wrong bitsPerSample and bitsPerPixel values for 8 & 16-bit BMP's
- Subject: Re: NSBitmapImageRep returns wrong bitsPerSample and bitsPerPixel values for 8 & 16-bit BMP's
- From: Wade Tregaskis <email@hidden>
- Date: Tue, 30 Mar 2004 17:53:42 +1000
Okay, scratch all that - this just in, I'm an idiot.
I was of course comparing the pixel data for the 8/16-bit versions
against the 32-bit version, which just doesn't work because some pixels
get bumped up or down a bit.
For the record, since this doesn't seem to be documented or mentioned
anywhere anyway, BMP's opened via NSImage's (and thus
NSBitmapImageRep's) are automatically decompressed [if necessary] and
converted to a nice pleasant RGBA format*, as accessible via the
bitmapData method. However, this doesn't happen for all image formats
NSBitmapImageRep supports - gif's stay pretty close to their real
format (e.g. 8-bit greyscale ones remain at single-sample 8bpp, 8-bit
colour ones are expanded to tri-sample 24bpp, 8bps, etc). JPEG's and
JPEG 2000's seem to be expanded in the same way as bitmaps, although I
haven't tested conclusively yet.
So, all in all things look fantastic - I get beautiful, byte-aligned,
palette-converted data to work with. I'm a bit miffed that this
doesn't hold true for all formats (e.g. gif, probably png, etc), but as
I mentioned earlier, if I'm desperate I can always render to an RGBA
buffer.
Since I've wasted the lists time again with this
apology/answer-to-self, I might as well throw in a meaningful question
- is there any reliable way to determine if an NSBitmapImageRep
contains greyscale data? When using 8-bit greyscale gif's I can tell
because number of samples = 1 (and bits per sample = bits per pixel, as
a result). However, for the converted formats (bmp, at least) I can't
use this hack. Is there any other method, short of peeking at the
relevant bytes in the file header (which I'd rather not do, since it
potentially means learning how to read several file formats, at least
briefly).
I know that question's been asked a bit before, but the answer has
generally been check if number of samples = 1, and just die miserably
if not. Not really suitable for my purposes. :)
Wade Tregaskis
-- Sed quis custodiet ipsos custodes?
* = Just to clarify, the conversion always occurs, even if the source
is not compressed. It also works for paletted bmp's.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.