I am trying to draw specific colored rectangles in a CGBitmapContext and then compare the pixel values โโwith the color that I painted (a kind of hit).
On Leopard, this works great, but on SnowLeopard, the pixel values โโI choose are different from the color values โโI draw - I think because of the confusion of colors and ignorance on my part.
The main steps that I take: -
- create a raster context with the kCGColorSpaceGenericRGB color space
- set the fillColorSpace context to the same color space kCGColorSpaceGenericRGB
- set context fill color
- to do
- get bitmapContextData, iterate over pixel values, etc.
As an example, on Leopard, if I do: -
CGContextSetRGBFillColor(cntxt, 1.0, 0.0, 0.0, 1.0 );
CGContextFillRect(cntxt, cntxtBounds);
UInt8 red == 255, green == 0, blue == 0, alpha == 255
Snow Lepard, ,
UInt8 red == 243, == 31, == 6, alpha == 255
( - . , - "", (1.0,0,0). , (1.0,1.0,1.0), (255,255,255) (0,0,0) (0,0,0)).
colorSpaces, . , .
UPDATE
, , .
NSUInteger arbitraryPixSize = 10;
size_t components = 4;
size_t bitsPerComponent = 8;
size_t bytesPerRow = (arbitraryPixSize * bitsPerComponent * components + 7)/8;
size_t dataLength = bytesPerRow * arbitraryPixSize;
UInt32 *bitmap = malloc( dataLength );
memset( bitmap, 0, dataLength );
CGColorSpaceRef colSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
CGContextRef context = CGBitmapContextCreate ( bitmap, arbitraryPixSize, arbitraryPixSize, bitsPerComponent,bytesPerRow, colSpace, kCGImageAlphaPremultipliedFirst );
CGContextSetFillColorSpace( context, colSpace );
CGContextSetStrokeColorSpace( context, colSpace );
CGContextSetRGBFillColor( context, 1.0f, 0.0f, 0.0f, 1.0f );
CGContextFillRect( context, CGRectMake( 0, 0, arbitraryPixSize, arbitraryPixSize ) );
UInt8 *baseAddr = (UInt8 *)CGBitmapContextGetData(context);
UInt8 alpha = baseAddr[0];
UInt8 red = baseAddr[1];
UInt8 green = baseAddr[2];
UInt8 blue = baseAddr[3];
CGContextRelease(context);
CGColorSpaceRelease(colSpace);
Leopard โ red == 255, green == 0, blue == 0, alpha == 255
โ == 228, == 29, == 29, == 255