• 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: NSImage representations
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage representations


  • Subject: Re: NSImage representations
  • From: Jeremy Rotsztain <email@hidden>
  • Date: Sun, 8 Jul 2007 12:27:22 -0400


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


On Jul 8, 2007, at 12:03 PM, Dorian Johnson wrote:

You're using integer division, which I don't think is what you want:

	p2[0] = (unsigned char)rint(p1[0] / 25.0 * 25); // update red
	p2[1] = (unsigned char)rint(p1[1] / 25.0 * 25); // update gree
	p2[2] = (unsigned char)rint(p1[2] / 25.0 * 25); // update blue

I don't exactly know what that's supposed to do, since dividing by 25 then multiplying by the same number is just * 1.


Since this is all in-place operations, I'd suggest something like:

NSBitmapImageRep *paintImageRep = [NSBitmapImageRep imageRepWithData:[myImage TIFFRepresentation]];

NSSize imageSize = NSMakeSize([paintImageRep pixelsWide], [paintImageRep pixelsHigh]);


unsigned char *data = [paintImageRep bitmapData], *p1;
int n = ([paintImageRep bitsPerPixel] + 7) / 8, x, y;

for (x=0; x<imageSize.width; x++
{
for (y=0; y<imageSize.height; y++)
{

p1 = data + n * (y * (int)imageSize.width + x);

p1[0] = p1[0]/2; // note this will simply darken the image, but I don't know what you actually want to do
p1[1] = p1[1]/2;
p1[2] = p1[2]/2;
}
}

NSImage *quantizedImage = [[NSImage alloc] initWithSize:imageSize];
[quantizedImage addRepresentation:paintImageRep];

return quantizedImage;

_______________________________________________

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: NSImage representations
      • From: Dorian Johnson <email@hidden>
References: 
 >Fwd: NSImage representations (From: Jeremy Rotsztain <email@hidden>)
 >Re: NSImage representations (From: Dorian Johnson <email@hidden>)
 >Re: NSImage representations (From: Dorian Johnson <email@hidden>)
 >Re: NSImage representations (From: Jeremy Rotsztain <email@hidden>)
 >Re: NSImage representations (From: Dorian Johnson <email@hidden>)

  • Prev by Date: Re: Totally stumped on extern NSString
  • Next by Date: Re: Totally stumped on extern NSString
  • Previous by thread: Re: NSImage representations
  • Next by thread: Re: NSImage representations
  • Index(es):
    • Date
    • Thread