Can I output PNG files that don't depend on my monitor's colour profile?

1 view
Skip to first unread message

James Montgomerie

unread,
Jan 10, 2012, 1:23:35 PM1/10/12
to quart...@lists.apple.com
I'd like to create PNG files using an sRGB color space. In my imagination, I'll be able to bytewise-compare files output by different runs of my program for testing purposes, to check the rendering doesn't change. This works mainly, but if I change monitors, the files start to be different even with no changes in the program. Looking at them visually, it looks like the color profiles are different (colors are slightly different shades). Am I doing something wrong? Code below. This is being run on Lion.

CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);

CGContextRef renderingContext = CGBitmapContextCreate(NULL,
pageBounds.size.width,
pageBounds.size.height,
8,
pageBounds.size.width * 4,
colorSpace,
kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);

CGContextSetFillColorSpace(renderingContext, colorSpace);
CGContextSetStrokeColorSpace(renderingContext, colorSpace);

CGColorSpaceRelease(colorSpace);

const CGFloat white[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
CGContextSetFillColor(renderingContext, white);
CGContextFillRect(renderingContext, pageBounds);
CGContextSaveGState(renderingContext);


// Do some rendering, occasionally calling CGContextSetFillColor or CGContextSetStrokeColor,
// but not changing the color space (unless it can happen implicitly?)


CGImageRef image = CGBitmapContextCreateImage(renderingContext);

CGImageDestinationRef pngDestination = CGImageDestinationCreateWithURL(
(__bridge CFURLRef)[NSURL fileURLWithPath:testOutputPDFPath],
kUTTypePNG,
1,
NULL);
CGImageDestinationAddImage(pngDestination, image, NULL);
CGImageDestinationFinalize(pngDestination);
CFRelease(pngDestination);
CGImageRelease(image);


Thanks!

Jamie. _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list (Quart...@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartz-dev/quartz-dev-garchive-50095%40googlegroups.com

This email sent to quartz-dev-g...@googlegroups.com

Hamish Allan

unread,
Jan 10, 2012, 2:31:38 PM1/10/12
to James Montgomerie, quart...@lists.apple.com
On 10 January 2012 18:23, James Montgomerie
<ja...@th.ingsmadeoutofotherthin.gs> wrote:

> I'd like to create PNG files using an sRGB color space.  In my imagination, I'll be able to bytewise-compare files output by different runs of my program for testing purposes, to check the rendering doesn't change.  This works mainly, but if I change monitors, the files start to be different even with no changes in the program. Looking at them visually, it looks like the color profiles are different (colors are slightly different shades).

If you're using a script to do that bytewise comparison, you could
have it run pngcrush first:

http://en.wikipedia.org/wiki/Pngcrush#Reducing_filesize_by_removing_color-correction_data

I'd be interested to hear an answer at the Quartz level if there is one, though.

H

Reply all
Reply to author
Forward
0 new messages