3

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

I have tried converting the NSImage to RGB color-space but i didn't like the results.. and i actually want the c,m,y,k values and not the equivalent rgb 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

p.s i can't use core graphics since this cocoa code is compiled using GNUStep.

ibm123
  • 1,214
  • 2
  • 15
  • 39
  • I think that's a problem with gnustep you're having there. Using apples regular LLVM compiler, your code works fine on my mac. Try `[rep colorAtX:0 y:0]` and see what you get back. It should be something like `NSDeviceCMYKColorSpace` followed by 4 color values. http://i.imgur.com/YqExUqc.png – Tim Bodeit Jun 15 '15 at 11:09

1 Answers1

1

I did not test this, but does this code return the right 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 it gives you want you want.

Moustach
  • 2,904
  • 1
  • 13
  • 23