Skip navigation.
 
mlRe: CGContextSetRGBFillColor() off by one?
FROM : Ken Ferry
DATE : Fri May 30 21:38:12 2008

> Well... I'm not sure that's true any more is it?  I mean, don't all the
> DeviceXXX colour spaces get mapped to the new "Generic" ones as of 10.4?


I don't believe so, and that isn't what I see in testing.

I filed a bug for this yesterday.  My understanding, which may be
flawed, is that using a 'device' colorspace is a pledge that you know
that your color components are already with respect to the colorspace
of the destination, so require no further color correction.

The generic colorspaces are device-independent.

int main (int argc, const char * argv[]) {
    uint32_t pixel = 0;

    CGColorSpaceRef genericColorSpace =
CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
    CGColorSpaceRef deviceColorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef ctx = CGBitmapContextCreate(&pixel, 1, 1, 8, 4,
genericColorSpace,
kCGImageAlphaPremultipliedLast|kCGBitmapByteOrder32Host);
    CGFloat components[4] = {(CGFloat)0xaa/0xff, (CGFloat)0xbb/0xff,
(CGFloat)0xcc/0xff, 1.0};

    pixel = 0;
    CGContextSetFillColorSpace(ctx, deviceColorSpace);
    CGContextSetFillColor(ctx, components);
    CGContextFillRect(ctx, CGRectMake(0, 0, 1, 1));
    uint32_t deviceColorPixel = pixel;

    pixel = 0;
    CGContextSetFillColorSpace(ctx, genericColorSpace);
    CGContextSetFillColor(ctx, components);
    CGContextFillRect(ctx, CGRectMake(0, 0, 1, 1));
    uint32_t genericColorPixel = pixel;

    printf("Expected same result for device:%#X and generic:%#X
fills\n", deviceColorPixel, genericColorPixel);

    CFRelease(genericColorSpace);
    CFRelease(deviceColorSpace);
    CFRelease(ctx);

    return 0;
}


On Fri, May 30, 2008 at 9:52 AM, Alastair Houghton
<<email_removed>> wrote:
> On 30 May 2008, at 02:21, Ken Ferry wrote:
>

>> Well, if you use CGContextSetRGBFillColor as you said, then that sets
>> a device RGB colorspace up as the fill colorspace, and device
>> colorspaces don't do color matching.  Device means 'untagged'.  Which
>> is to say, I don't know, sounds strange.

>
> Well... I'm not sure that's true any more is it?  I mean, don't all the
> DeviceXXX colour spaces get mapped to the new "Generic" ones as of 10.4?  So
> it may well be doing some sort of colour correction.
>
> Kind regards,
>
> Alastair.
>
> --
> http://alastairs-place.net
>
>
>

Related mailsAuthorDate
mlCGContextSetRGBFillColor() off by one? Mike Manzano May 29, 09:21
mlRe: CGContextSetRGBFillColor() off by one? Uli Kusterer May 29, 11:40
mlRe: CGContextSetRGBFillColor() off by one? Mike Manzano May 29, 23:17
mlRe: CGContextSetRGBFillColor() off by one? Ken Ferry May 30, 03:21
mlRe: CGContextSetRGBFillColor() off by one? Uli Kusterer May 30, 06:40
mlRe: CGContextSetRGBFillColor() off by one? Mike Manzano May 30, 07:16
mlRe: CGContextSetRGBFillColor() off by one? Alastair Houghton May 30, 18:52
mlRe: CGContextSetRGBFillColor() off by one? Ken Ferry May 30, 21:38
mlRe: CGContextSetRGBFillColor() off by one? Michael Vannorsdel May 31, 02:15
mlRe: CGContextSetRGBFillColor() off by one? Ken Ferry Jun 1, 07:01