# > So how the heck do you convert CMYK to RGB to make CoreImage happy?
#
# Naively, you do:
# r = 1.0 - (c + k);
# g = 1.0 - (m + k);
# b = 1.0 - (y + k);
I already do that with setColorSpaceName.
# The better answer is to use ColorSync, which has all sorts of routines
# for converting pixels between different color spaces.
I've looking for an answer for quite some time, and I find
answers like 'that's a complicated subject discussed on
the web' or 'use Colorsync'. Problem I can never find actual
code to do this.
And since CoreImage can only operate on a fraction of the
images out there (especially small fraction with printers),
you would think Apple would somewhere give people a clear
code example that can convert planar or CMYK or indexed or
6/6/4 or whatever else into the 8 bit RGB(A) chunky that
CoreImage requires. The code I've managed to work out by
myself that discarded profiles and works on everything but
1 bps is
NSSize imagesize = [rep size];
NSRect imagerect = NSMakeRect(0,0,imagesize.width,imagesize.height);
NSImage *contextimage = [[NSImage alloc] initWithSize: imagesize];
[contextimage lockFocus];
if ([[rep colorSpaceName] rangeOfString: @"RGB"].location==NSNotFound) {
[rep setColorSpaceName: NSDeviceRGBColorSpace];
}
if ([rep hasAlpha]) [[NSColor clearColor] set]; else [[NSColor whiteColor] set];
NSRectFill(imagerect);
[rep drawInRect: imagerect];
rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect: imagerect];
[contextimage unlockFocus];
So if anybody can point out the Colorsync calls that convert
to RGB with the image profile, I'd appreciate it.
# ColorSync is hardly something that Apple is trying to hide...
So where is it?
It's sort of like should I use this fancy new CoreVideo instead of
the old Quicktime to pick out PICT frames and convert to GIF? And the
guide points out this is one of the more frequent tasks. Which they
then follow with a hundred lines or so of code that I really don't
want to decipher.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
You face forward, or you face the possibility of shock and damage.
Russell Sheptak - 01 Nov 2006 19:46 GMT
> # > So how the heck do you convert CMYK to RGB to make CoreImage happy?
> #
[quoted text clipped - 38 lines]
> So if anybody can point out the Colorsync calls that convert
> to RGB with the image profile, I'd appreciate it.
Maybe I misunderstand your request, but as part of the Developer tools
you got a whole slew of example programs with source code. Take a look
in /Develper/Examples/ColorSync, and make note of DemoCMM since I think
its example code to do what you want.
rus
SM Ryan - 30 Dec 2006 17:14 GMT
# Maybe I misunderstand your request, but as part of the Developer tools
# you got a whole slew of example programs with source code. Take a look
# in /Develper/Examples/ColorSync, and make note of DemoCMM since I think
# its example code to do what you want.
Finally had a chance to look it up and it's a thousand lines of
uncommented code. I have no idea how to do kust one simple damned
thing and the turkeys at Apple are not giving any f.cking hints.
I don't mind their insistence on 8-bit RGBA chunky, but why the
hell can't they provide one function to convert anything to this,
and one to convert from this to anything. I keep getting hints that
it's real easy, all you have to do is waste a few years learning
every aspect of quartz just to do this one thing.
Hey, Apple, if it's so f.cking easy just provide the damned code
to do it and stop wasting everybody's time.
glenn andreas - 02 Nov 2006 02:09 GMT
> # > So how the heck do you convert CMYK to RGB to make CoreImage happy?
> #
[quoted text clipped - 48 lines]
> then follow with a hundred lines or so of code that I really don't
> want to decipher.
Hm, developer.apple.com, select "Graphics and Imaging", select
"Reference Library", select "ColorSync":
<http://developer.apple.com/referencelibrary/GraphicsImaging/idxColorSync
-date.html>
Complete list of guides, reference docs, technotes, and sample code.
Even more particularly, check out:
<http://developer.apple.com/samplecode/ImageApp/index.html>
Demonstrates basic image handling using the ImageIO API in Mac OS 10.4
Tiger. This includes the following:
opening images
- getting image properties
- image thumbnails
- image profile issues
displaying images with Quartz
- assigning default profiles for untagged images
- matching across multiple display
- respecting image orientation and aspect ratio
filtering images (Core Image + color management)
- using Core Image filters
- dealing with non-RGB images
printing images
saving images
- setting image properties
- saving results from CI filtered images
See also "Setting the ColorSync profile for a NSBitmapImageRep object"
<http://developer.apple.com/qa/qa2004/qa1369.html>