CMYK NSImage gets pixel data

I am loading a CMYK jpeg image into NSImage, How can I extract the c, m, y, k values ​​for a specific pixel? How can I get a byte array with all CMYK pixel data. in RGB images I use .bitmapData but it seems for CMYK images it's all 0xff.

I tried to convert NSImage to RGB color space but didn't like the results .. and I really want c, m, y, k values, not rgb equivalent values

    NSImage *image = [[NSImage alloc] initWithContentsOfFile:inputImageString];

        NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
    bool isCMYK = [rep.colorSpaceName isEqualToString: NSDeviceCMYKColorSpace];
    const unsigned char *bytes = rep.bitmapData;
// all values at bytes are not weird and does not represent CMYK values

      

ps I cant use main graphics as this cocoa code is compiled using GNUStep.

+3


source to share


2 answers


I haven't tested this, but does this code return the correct values?

NSImage *image = [[NSImage alloc] initWithContentsOfFile:inputImageString];

NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
bool isCMYK = [rep.colorSpaceName isEqualToString: NSDeviceCMYKColorSpace];
if(isCMYK){
    NSColor* aColor = [raw_img colorAtX:0 y:0];
    NSString* theColorSpace = [aColor colorSpaceName];

    if ([theColorSpace isEqualToString: NSDeviceCMYKColorSpace]){
        NSLog(@"C:%f,M%f,Y:%f,K%f",
            aColor.cyanComponent,
            aColor.magentaComponent,
            aColor.yellowComponent,
            aColor.blackComponent);
    }
}

      



This should be a good starting point if you want what you want.

+1


source


Have you seen this site? Is this close to what you want?



http://oleb.net/blog/2011/05/using-cocoa-to-convert-images-from-rgb-to-cmyk/

0


source







All Articles