• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Copy an NSImage to another, keeping the color profile
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Copy an NSImage to another, keeping the color profile


  • Subject: Copy an NSImage to another, keeping the color profile
  • From: Stephan Burlot <email@hidden>
  • Date: Tue, 22 Nov 2005 12:14:11 +0100

Hi,

Using the code below, I'm trying to copy an NSImage to another. (in my app, I do some geometric transformations to the image, I've simplified the example)
The source image has a colorsync profile of sRGB IEC61966-2.1.
Problem is, when I create an NSImage, even if I specify the colorsync profile, colors are shifted (verified with PhotoShop).
It seems like the destination image has been converted using my screen profile.


How can I avoid this color conversion to happen?

Any help would be greatly appreciated!

Thanks,
Stephan

  NSData              *colorSyncProfile = nil;
  NSRect              srcRect;
  NSImage             *dstImage;
  NSBitmapImageRep    *dstImageRep;

NSImage *srcImage = [[NSImage alloc] initWithContentsOfFile:SRC];
NSBitmapImageRep *theBitmap= [NSBitmapImageRep imageRepWithData: [srcImage TIFFRepresentation]];


if (theBitmap != nil)
{
colorSyncProfile = [theBitmap valueForProperty:NSImageColorSyncProfileData];
srcRect = NSMakeRect(0, 0, [theBitmap pixelsWide], [theBitmap pixelsHigh]);
[srcImage setSize:srcRect.size];
}
else
{
NSLog(@"image has no bitmaprep");
return;
}


  dstImage = [[NSImage alloc] initWithSize:srcRect.size];
  if (dstImage == NULL)
  {
    NSLog(@"dstImage is NULL!");
    return;
  }
#if 0
  // tried to create myself a bitmap, didnt change anything
  dstImageRep  = [[NSBitmapImageRep alloc]
                  initWithBitmapDataPlanes:NULL
                  pixelsWide:srcRect.size.width
                  pixelsHigh:srcRect.size.height
                  bitsPerSample:[theBitmap bitsPerSample]
                  samplesPerPixel:[theBitmap samplesPerPixel]
                  hasAlpha:[theBitmap hasAlpha]
                  isPlanar:NO
                  colorSpaceName:NSCalibratedRGBColorSpace
                  bytesPerRow:nil
                  bitsPerPixel:nil];

if (dstImageRep == NULL)
{
NSLog(@"dstImageRep is NULL!");
return;
}
[dstImageRep setProperty:NSImageColorSyncProfileData withValue:colorSyncProfile];
[dstImage addRepresentation:dstImageRep];
[dstImageRep release];
#endif


[dstImage setBackgroundColor:[NSColor whiteColor]];
[dstImage lockFocus];
NSEraseRect(srcRect);
[srcImage drawInRect:srcRect fromRect:srcRect operation:NSCompositeCopy fraction:1.0];
[dstImage unlockFocus];
[srcImage release];


[dstImage lockFocus];
theBitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:srcRect];
[dstImage unlockFocus];


// if I dont add the following line, the color profile will be my Mac's profile (but colors will still be wrong)
[theBitmap setProperty:NSImageColorSyncProfileData withValue:colorSyncProfile];
NSData *bitmapData = [(NSBitmapImageRep *)theBitmap representationUsingType: NSJPEGFileType
properties:[NSDictionary dictionaryWithObject: [NSDecimalNumber numberWithFloat:0.8]
forKey:NSImageCompressionFactor]];
[bitmapData writeToFile:DST atomically:NO];


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Finding application's idle time?
  • Next by Date: NSURLConnection and 403 Error
  • Previous by thread: Re: Finding application's idle time?
  • Next by thread: NSURLConnection and 403 Error
  • Index(es):
    • Date
    • Thread