views:

252

answers:

0

I'm a newbie with iPhone programming, and I'm trying to create a custom ICC colorspace to create colors in. The "DeviceCMYK" is not accurate enough, so I need the ICC colorspace.

I can't figure out how to get it to work... I've tried with 4 different version of CMYK profiles, but none seem to work. I've even tested by using the "DeviceRGB" as the "alternate" (obviously wrong colorspace), and I can tell my code is kinda working because it shows total "white" for color because the CMYK number are 1 thru 100 (and it defaults to the ceiling of 1)... but I can not get my ICC profile to load as the colorspace.

Ive also tried with floats of my CMYK values (0.0 thru 1.0) but alas no luck. Does anyone have any suggestions of what i could try (or how to get the error) ?

Here's my code:

(void)viewDidLoad {
    [super viewDidLoad];
  //[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
 swatchNameLabel.text = [self.aSwatch objectForKey:@"swatchName"];
 NSArray *cmykArray = [[self.aSwatch objectForKey:@"cmykValues"] componentsSeparatedByString:@","];

  // set variables for displaying the swatch values
 int cyanValue = [[cmykArray objectAtIndex:0] intValue];
 int magentaValue = [[cmykArray objectAtIndex:1] intValue];
 int yellowValue = [[cmykArray objectAtIndex:2] intValue];
 int blackValue = [[cmykArray objectAtIndex:3] intValue];

 NSString *newText = [[NSString alloc] initWithFormat:@"%i.%i.%i.%i",cyanValue, magentaValue, yellowValue, blackValue];
 cmykValueLabel.text = newText;
 [newText release];

 // setup the default colorspace
 CGColorSpaceRef deviceColorSpace = CGColorSpaceCreateDeviceCMYK(); 


 // ICC Profile attempt here 
 // use the int values from separated string 

 float ranges[] = {0.0,100.0,0.0,100.0,0.0,100.0,0.0,100.0};
 NSString *profilePath  = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"WebCoatedSWOP2006Grade3.icc"];
 CGDataProviderRef profile = CGDataProviderCreateWithFilename([profilePath UTF8String]); 
 CGColorSpaceRef iccColorSpace = CGColorSpaceCreateICCBased(4, ranges, profile, deviceColorSpace);
 CGDataProviderRelease(profile);


 // create the CMYK Color
 CGFloat components[5] = {cyanValue*1.f, magentaValue*1.f, yellowValue*1.f, blackValue*1.f, 1.0f};
 CGColorRef newColor = CGColorCreate(iccColorSpace, components);
 CGColorSpaceRelease(iccColorSpace);

 UIColor *bgColor = [UIColor colorWithCGColor:newColor];
 CGColorRelease(newColor);
 CGColorSpaceRelease(deviceColorSpace);

  // set the background color
 [self.view setBackgroundColor:bgColor];
}