Re: NSImage representations
Re: NSImage representations
- Subject: Re: NSImage representations
- From: Dorian Johnson <email@hidden>
- Date: Sun, 8 Jul 2007 14:32:06 -0500
Ah, alright, sorry for my confusion. The + 7/8 trick makes sure that
for things like 15 bit color, it's still counted as 2bpp. It's not
necessary, but I've gotten into the habit of doing it since it helps
with esoteric (read: microsoft) bitmap formats and doesn't hurt for
normal bitmap formats.
Please post the tiff representation of the NSImage objects it doesn't
work on. It sounds like the bitmaprep isn't being created and
bitmapData is returning NULL. You might try calling +[NSImageRep
canInitWithData] on the tiff representation to see if that's what's
causing it. Additionally, if you load 8-bit or 16-bit images, that
code will fail, since it tries to set 3 bytes for each pixel.
The way I generally do it, to avoid TIFFRepresentation and ensure
that all of my bitmap image reps are 32 ARGB is create the bitmap rep
explicitly, then lock focus onto it (there's a method for that in
NSGraphicsContext) and draw the NSImage on it. It may be a bit
slower, but I've found that it ensures that you know the exact
details of the bitmap data and is overall more future proof. It's
still far quicker than setPixel.
- Dorian
On Jul 8, 2007, at 11:27 AM, Jeremy Rotsztain wrote:
Hi Dorian,
Just to clarify, I'm trying to simplify the image from millions of
colors to 1000 colors. This is essentially a rounding (or binning)
technique.
22 / 25 * 25 = 0
25 / 25 * 25 = 25
29 / 25 * 25 = 25
If I used decimal division, then my code won't work.
Even still. Sometimes when I run this function on some (not all)
NSImage objects, this line throws an error.
Could it be an issue with compression?
p1[0] = p1[0];
Could you explain why you've done this?
int n = ([paintImageRep bitsPerPixel] + 7
That makes sense that I don't make an extra representation, since
it is an all-in-place operation.
Thanks again for your advice.
All the best,
Jeremy
_______________________________________________
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