NSBitmapImageRep and 1-bit image
NSBitmapImageRep and 1-bit image
- Subject: NSBitmapImageRep and 1-bit image
- From: Timofey Sherudilo <email@hidden>
- Date: Thu, 1 Dec 2005 11:24:45 +0600
Hello!
Here is my problem: I try to create a 1-bit image representation, like this:
imageRep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:nil
pixelsWide:width
pixelsHigh:height
bitsPerSample:1
samplesPerPixel:1
hasAlpha:NO
isPlanar:YES
colorSpaceName:NSDeviceBlackColorSpace
bytesPerRow:width
bitsPerPixel:1];
Then I get the bitmap plane:
[imageRep getBitmapDataPlanes:dataPlanes];
unsigned char *planeBitmap = dataPlanes[0];
And try to "draw" on the bitmap (changing a color of individual pixels) directly:
- (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:
http://tim.3dmix.com/rgb.tiff (right picture - about 300 Kb)
http://tim.3dmix.com/monochrome.tiff (wrong pucture - about 16 Kb)
The image you see is some printer test calculated with a special algorithm.
Do I create the monochrome image right? Is something wrong in my code?
Thank you in advance.
--
Timofey Sherudilo
email@hidden
http://tim.3dmix.com/
http://timsher.blogspot.com/
_______________________________________________
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