• 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: NSBitmapImageRep and 1-bit image
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSBitmapImageRep and 1-bit image


  • Subject: Re: NSBitmapImageRep and 1-bit image
  • From: Thomas Engelmeier <email@hidden>
  • Date: Thu, 1 Dec 2005 12:08:58 +0100

Here is my problem: I try to create a 1-bit image representation, like this:

- (void)setPixColorX:(int)x Y:(int)y clr1:(int)clr1 clr2:(int)clr2 clr3:(int)clr3
{
int offset = x + [imageRep bytesPerRow] * y;
// If we receive an RGB triplet, we'll write 1 if at least one color isn't 0:
*((unsigned char*)(planeBitmap + offset)) = (clr1 || clr2 || clr3) ? 1 : 0;
}

This routine works perfectly for RGB or grayscale bitmaps, but for a 1-bit image I get very strange results. You can see the samples here:


Do I create the monochrome image right? Is something wrong in my code?


Are you sure you want to set 8 pixels (each pixel is 1 bit, after all) if the color matches? For 1 bit the formula for byteoffset is
(x / 8) + [imageRep bytesPerRow] * y, the bitoffset is x % 8, an way to set / unset is byte[byteoffset] = ([byte[byteoffset] & ~((0x1) << bitoffset) ] | (valueToSet << bitoffset)), i.e. first mask, then or the value.

Besides this, you are writing way beyond the the memory block of mono bitmap, at least (imageRep.pixelsWide - [imageRep bytesPerRow] ) bytes.

Regards,
Tom_E

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Prev by Date: Re: NSBitmapImageRep and 1-bit image
  • Next by Date: Re: more than one plist in a file.
  • Previous by thread: Re: NSBitmapImageRep and 1-bit image
  • Next by thread: Re: more than one plist in a file.
  • Index(es):
    • Date
    • Thread