TweetFollow Us on Twitter

June 93 - PRINT HINTS

PRINT HINTS

SYNCING UP WITH COLORSYNC

[IMAGE 034-039_Print_Hints_rev1.GIF]

JOHN WANG


Apple's recently introduced ColorSync, a color matching software technology, provides a common platform for applications and device drivers to match colors by communicating color information between graphics devices with differing color characteristics. This column starts off with an overview and then delves deeper into the inner workings of ColorSync so that you'll have a better understanding of how to use this new technology. We'll also take a look at how applications and device drivers can take advantage of ColorSync.

WHAT IS COLORSYNC?
ColorSync is an extension to the Macintosh system that's distributed with the Apple Color Printer and the Color OneScanner. It provides a platform for maintaining quality and similarity of images that are moved between different devices. Because different devices typically reproduce different gamuts -- ranges of colors -- ColorSync can be used by applications and device drivers to perform color correction. For example, monitors from different manufacturers have dissimilar gamuts because they use different hardware that drives different cathode ray tubes. In fact, there are minute color differences among the same models due to the video card, internal settings, user adjustments, and even age. ColorSync uses color matching algorithms to visually equate the images produced by different devices. Applications that are ColorSync aware attempt to display a document faithfully on any monitor.

Besides supporting RGB, ColorSync supports color matching with other color spaces, such as CMYK. Printers normally work in the CMYK color space because CMYK colors are subtractive -- when added they move the image toward black or dark gray. This is entirely different from RGB monitors, which use additive colors -- colors that when added move the image toward white. Consequently, ColorSync is especially useful when it's necessary to match on-screen and printed colors -- colors with two very different gamuts.

PROFILES AND COLOR MATCHING METHODS
ColorSync uses two major elements to implement color matching between devices: profiles and color matching methods (CMMs). The profiles contain the device characterization while the CMMs contain the color matching code to perform the matching. A CMM performs matching between a source profile and a destination profile. A system will have at least one profile for each device to be matched and at least one CMM to perform the matching. Apple ships ColorSync with one Apple CMM and with ColorSync profiles for all Apple monitors currently being manufactured. The open architecture of ColorSync allows third-party developers to create their own profiles and CMMs.

A ColorSync profile is simply a file whose data fork contains a CMProfile record, usually stored in the ColorSyncTM Profiles folder. (This folder is in the Preferences folder in your System Folder; your code can get it by calling GetColorSyncFolderSpec.) Profiles may also be stored in a 'prof' resource,as discussed later. A device may have more than one profile; however, only one is selected for use at any given time. For example, printers have profiles for various paper types since the output onto different types of paper can vary. The Apple Color Printer has default profiles for coated paper, transparency film, and plain paper. A monitor may also have several profiles for various special gamma settings. ColorSync neither affects nor is affected by the gamma setting. For best results, the user must select a ColorSync profile that matches the gamma.

Here's the data structure for a CMProfile record:

typedef struct CMHeader {
    unsigned long   size;
    OSType          CMMType;
    unsigned long   applProfileVersion;
    OSType          dataType;
    OSType          deviceType;
    OSType          deviceManufacturer;
    unsigned long   deviceModel;
    unsigned long   deviceAttributes[2];
    unsigned long   profileNameOffset;
    unsigned long   customDataOffset;
    CMMatchFlag     flags;
    CMMatchOption   options;
    XYZColor        white;
    XYZColor        black;
} CMHeader;

typedef struct CMProfileChromaticities {
    XYZColor    red;
    XYZColor    green;
    XYZColor    blue;
    XYZColor    cyan;
    XYZColor    magenta;
    XYZColor    yellow;
} CMProfileChromaticities;

typedef struct CMProfileResponse {
    unsigned short  counts[onePlusLastResponse];
    CMResponseData  data[1];
} CMProfileResponse;

typedef struct CMProfile {
    CMHeader                header;
    CMProfileChromaticities profile;
    CMProfileResponse       response;
    IString                 profileName;
    char                    customData[1];
} CMProfile, *CMProfilePtr, **CMProfileHandle;

CMMs are components of type 'cmm ' that contain code to perform matching. The component subtype distinguishes between different CMMs. ColorSync ships with the default Apple CMM, which has the subtype 'appl'. Developers who want to provide custom CMMs to perform matching beyond the capabilities of Apple's basic color matching method need to register their CMM subtype with the Apple Registry (AppleLink REGISTRY) to avoid conflict with other CMM manufacturers. The only requirement for subtype naming is that all-lowercase types are not used, because they're reserved by Apple.

A CMM can have six routines, three of which are required:

  • CMInit: Given the source and destination profile, prepare to perform color matching.
  • CMMatchColors: Match a list of colors using profiles specified by a call to CMInit.
  • CMCheckColors: Check a list of colors and determine whether they fall within the gamut of the destination device's color space.

The optional CMM routines are as follows:

  • CMMatchPixMap: Match the colors of a pixel map using profiles specified by a call to CMInit.
  • CMCheckPixMap: Check a pixel map to determine which pixels fall outside the destination profile's gamut.
  • CMConcatenateProfiles: Concatenate two profiles to create one new profile.

WHICH CMM TO USE?
ColorSync profiles that refer to the custom CMMs can be created by setting the CMMType field in the CMHeader to the subtype of the CMM. ColorSync will attempt to use the corresponding CMM when using that profile. However, the custom profiles must still contain the data necessary for compatibility with Apple's default color matching method so that the Apple CMM can be used if the custom CMM is unavailable. The rules for deciding which CMM to use depend on the source and destination profile:

  1. If the source and destination profiles use the same CMM and the corresponding CMM is available, the matching is performed entirely by that CMM. If the CMM is not available, the Apple CMM is used.
  2. If the source and destination profiles use different CMMs, then: a) If the CMM for the destination profile is available, try using that CMM. If the CMM returns an error because it can't perform the color matching, try step b. Since the Apple CMM will never return an error because it's always able to perform matching between two profiles, this is considered a special case, so skip to b. b) If the CMM for the source profile is available, try using that CMM. If the CMM returns an error because it can't perform the color matching, try step 3. Again, since the Apple CMM will never return an error, this is considered a special case, so skip to step 3.
  3. If the CMMs for both the source and destination profiles are available but can't perform the matching as described in step 2, ColorSync matches using the source CMM from the source profile color space to the XYZ color space, and then using the destination CMM from the XYZ color space to the destination profile color space.
  4. If step 3 doesn't work because a CMM is missing, the Apple CMM is substituted for the missing one.

COLORSYNC ROUTINES
ColorSync provides high-level and low-level routines that may be used by application and device driver developers. Except for BeginMatching, EndMatching, and DrawMatchedPicture -- which are available in System 7 only -- the routines are available in system software version 6.0.7 and later. On all systems, ColorSync must be installed. The gestalt selector 'cmtc' returns gestaltColorSync10 (0x0100) for the version of ColorSync that works with system software version 6.0.7, and gestaltColorSync11 (0x0110) for the version that works with System 7. (Note that 6.0.7 must also have version 1.2 of the 32-Bit QuickDraw INIT installed.)

// Use Gestalt to get version of ColorSync.
if (Gestalt(gestaltColorMatchingVersion, &CMversion) != noErr)
    CMversion = 0;

The high-level profile management routines are as follows:

  • GetProfile: Get the profile currently selected for a device.
  • SetProfile: Add a profile to the device's profile list.
  • SetProfileDescription: Set profile description fields for a new profile (typically created by a calibrator).
  • GetColorSyncFolderSpec: Get the folder in which ColorSync profiles should be stored.
  • GetProfileName: Given a profile, return its name.
  • GetProfileAdditionalDataOffset: Given a profile, return the custom data offset.
  • ConcatenateProfiles: Concatenate two profiles into one.
  • GetIndexedProfile: Return the number of profiles and the profiles from the device's profile list.
  • DeleteDeviceProfile: Delete a profile from a device's profile list.

The following high-level matching routines provide a layer of code between application and device driver code and the CMM component code. They simplify color matching by performing matching of all QuickDraw drawing routines.

  • BeginMatching: Tell Color QuickDraw to begin matching for the current graphics device using the specified source and destination profiles. (Not available in system software version 6.0.7.)
  • EndMatching: Tell Color QuickDraw to stop matching. (Not available in 6.0.7.)
  • EnableMatching: Insert picComments to turn matching on or off inside a picture.
  • UseProfile: Insert a profile into an open picture.
  • DrawMatchedPicture: Draw a picture using color matching. (Not available in 6.0.7.)

These low-level routines perform color matching:

  • CWNewColorWorld: Create a color matching world using the specified source and destination profiles.
  • CWDisposeColorWorld: Dispose of a color matching world to end the session.
  • CWMatchColors: Match a list of colors using the current color matching world.
  • CWCheckColors: Check a list of colors to see if they fall within a device's gamut. Use the current color matching world.
  • CWMatchPixMap: Match a pixel map using the current color matching world.
  • CWCheckPixMap: Check the colors of a pixel map using the current color matching world to determine whether the colors are in the gamut of the destination device.

HOW DOES COLORSYNC WORK?
Now that you have an overview of the basic elements of ColorSync -- profiles, CMMs, and routines -- we can discuss how ColorSync works by putting all these pieces together.

As mentioned earlier, ColorSync profiles are normally stored in the ColorSyncTM Profiles folder in the Preferences folder. In this folder, you'll find a selection of monitor profiles for all Apple color monitor products. In some cases, there are duplicates to account for the color differences between different gamma settings for the monitor. For example, the Apple 16-inch monitor has two profiles: Apple 16" RGB Page-White and Apple 16" RGB Standard. The user selects the profile that corresponds to the Use Special Gamma setting made in the Monitors control panel. This profile -- also called the system profile -- is selected in the ColorSync control panel. The system profile is used as the default source profile whenever you're matching from a document that doesn't specify a profile or matching to a device that doesn't otherwise have an associated profile.

You may be wondering how to use the ColorSync control panel to select more than one system profile for multiple monitors. Unfortunately, the system profile is an abstraction that shouldn't be associated with any particular device. As described earlier in "Which CMM to Use?" it should be used whenever a profile isn't explicitly specified for a source or destination. ColorSync-awareapplications can support multiple monitors by matching to specific graphics devices, thereby overriding the system profile selection. But this isn't recommended except with high-end applications because of difficulties in implementation and complexities for the user.

Applications can determine the current system profile selection with GetProfile. In fact, GetProfile works with any device to get the current profile selection for that device. However, for the call to work, the devices must register their profile responder. Every device that uses ColorSync to perform matching must have a profile responder, which is a component that supports the following routines:

  • CMGetProfile: Return the profile that the driver would use to perform a match.
  • CMSetProfile: Add the profile to the driver's profile list.
  • CMSetProfileDescription: Set the device-specific fields in a profile. This allows newly created profiles to be used with the device.
  • CMGetIndexedProfile: Get the profile that matches the search criteria.
  • CMDeleteDeviceProfile: Delete the profile from the driver's profile list.

The system profile responder is always registered globally in a system, so you can use the ColorSync high-level profile management routines on the system device. Printer driver profile responders are registered only if requested; you register one by calling PrGeneral with the driver opened. The PrGeneral opcode is registerProfileOp (13). By using a profile responder, an application can communicate with any device to request ColorSync profile information. This is especially useful for calibration applications. For example, an application can create a new profile for a printer, call SetProfileDescription to set the device-specific fields in the profile, and then call SetProfile to add the profile to the device driver's profile list.

The following code excerpt demonstrates how to register a device driver profile responder. The complete sample code (including error checking!) is provided on this issue's CD.

// Register printer profile responder.
PrOpen();
if ((prError = PrError()) == noErr) {
    printerOpened = true;
    prRecHdl = (THPrint)NewHandle(sizeof(TPrint));
    PrintDefault(prRecHdl);
    
    regProfileBlk.iOpCode = registerProfileOp;
    regProfileBlk.iError = 0; 
    regProfileBlk.lReserved = 0;
    regProfileBlk.hPrint = prRecHdl;
    regProfileBlk.fRegisterIt = true;
    PrGeneral((Ptr)&regProfileBlk);
    prError = regProfileBlk.iError;
}

You don't see the default profiles for device drivers such as the Apple Color Printer in the ColorSyncTM Profiles folder because they're stored as 'prof' resources in the device drivers themselves. However, applications can still create profiles for the printer driver to use by placing them in the ColorSyncTM Profiles folder. All printer drivers should search not only in their private profile storage location but in the ColorSyncTM Profiles folder as well. In the Apple Color Printer Print Options dialog box, users can choose custom profiles in a pop-up menu if Customized Color Matching is selected. The driver even filters the profiles, so only profiles that match the paper type appear in the menu. This is accomplished by reading in each profile in the folder and searching for the desired values in the CMHeader record. The Apple Color Printer driver stores the profile's paper type in the deviceAttributes field of the profile's CMHeader record. This field is used differently by various devices; for instance, monitor profiles use it to store the gamma setting. When you finally print to a color printer such as the Apple Color Printer, the printer driver performs matching from the system profile to the printer profile. The application must pass the ColorSync picComments through to the printer for matching to occur. If the application strips out picComments, the printer driver assumes the document uses the system profile. If the picComments contain a custom profile, the printer driver uses that profile as the source profile instead of the system profile. Even a matching method chosen in the Customized Color Matching pop-up menu is overridden by such custom profiles. For example, if a document contains scanned images, the images may have a custom profile that uses photographic matching while the rest of the document uses the solid color system profile.

WHAT DOES AN APPLICATION HAVE TO DO?
In a way, most applications are already ColorSync compatible because they can print to ColorSync- aware printers such as the Apple Color Printer. However, for an application to become ColorSync savvy, it should have three key features:

  • It should allow users to tag color matching information to documents and to be able to display them using ColorSync. ColorSync calls such as UseProfile, DrawMatchedPicture, and BeginMatching/EndMatching can be used to do this.
  • Applications should allow users to preview the output to a ColorSync-aware printer by matching from the document to the printer profile and back to the system profile. The user can thus view color differences that occur in the color matching transition between gamuts. The application can even visually outline colors that can't be displayed faithfully, using the CheckColors routine.
  • Most important, the application must preserve picComments in its documents. The application can allow modification of the ColorSync picComments as appropriate, but it must save the information in the document and allow the information to be passed through to the printer.

WHAT DOES A PRINTER DRIVER HAVE TO DO?
A printer driver must first have a responder component that implements the responder routines mentioned earlier. The responder allows ColorSync to communicate with the printer driver. By watching for picComments in the printer port bottleneck procs, the driver is notified of source profile changes and other information as well. The printer driver can then adjust the color matching accordingly.

Matching can be performed with high-level calls such as BeginMatching or with low-level calls such as CWMatchColors. If the printer driver spools pages in the PICT format and uses DrawPicture with an off-screen graphics device for rendering, the high-level calls can be used. Otherwise, matching is best performed with the low-level calls from the QuickDraw bottleneck procs. The Apple Color Printer uses low-level calls and performs color matching in its custom bottleneck procs before rendering occurs. Applications that generate PostScriptTM code directly must perform color matching themselves using the low-level calls. They can determine what destination printer profile to use by calling GetProfile.

Apple doesn't ship an updated LaserWriter driver to support ColorSync because it would require a major rewrite of current code. However, applications can work around this by performing the color matching in the application. On the other hand, PostScript Level 2 has color matching support built into the PostScript language, so it would be possible to offload color matching to the PostScript imaging device.

YOUR COLORFUL FUTURE
ColorSync is an open architecture platform that enables third-party developers to create profiles, CMMs, and drivers that are mutually compatible. As shown in the past, open architecture promotes market acceptance and user adoption. By using ColorSync as your color matching platform, you're ensured of continued compatibility with future Apple technologies.

As a developer, you can influence the direction of ColorSync; send your feedback to AppleLink DEVSUPPORT. In fact, you can even send me your ColorSync-savvy application (AppleLink WANG.JY) and I'd be thrilled to evaluate it.

JOHN WANG (AppleLink WANG.JY) is standing in for Pete ("Luke") Alexander, who was busy working on his QuickDraw GX article for a future issue of develop. We expect various members of Developer Technical Support's Printing, Imaging, and Graphics group to take turns writing this column in the future. John also found the time to write his regular QuickTime column; look there (later in this issue) for the real John Wang bio. *

The ColorSync Utilities document on this issue's CD is the comprehensive document that developers should refer to for ColorSync development. However, having worked with many ColorSync developers, I've come across several issues that aren't covered in the ColorSync Utilities document. This column is a conglomeration of hours of discussion and mutual enlightenment.*You make gamma settings in the Monitors control panel by Option-clicking the Options button and, in the dialog box that appears, selecting Use Special Gamma and choosing the special gamma from the pop-up menu. *

Components are described in the Component Manager documentation in the QuickTime Developer's Kit v. 1.5. The information will soon be published in Inside Macintosh: More Macintosh Toolbox. *

XYZ is a device-independent color space defined by the Commission Internationale de l'Eclairage (CIE). It's an additive color space similar to RGB. Each of the XYZ components is a 1.15-bit unsigned fixed-point number.*

Color matching to multiple monitors is implemented by setting the destination profile for each graphics device with SetProfile and then performing matching with DrawMatchedPicture or BeginMatching/EndMatching. *

Applications that strip picComments from pictures before sending them to the printer driver are not ColorSync compatible because they remove the information that ColorSync uses to perform matching. For general information on picComments, see the Macintosh (Imaging) Technical Note "Picture Comments -- The Real Deal" (formerly #91). *

Thanks to Bill Guschwan, Tom Mohr, Konstantin Othmer, Steve Swen, and Forrest Tanaka for reviewing this column. *

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

The beginner's guide to Warbits
Warbits is a turn-based strategy that's clearly inspired by Nintendo's Advance Wars series. Since turn-based strategy games can be kind of tricky to dive into, see below for a few tips to help you in the beginning. Positioning is crucial [Read... | Read more »
How to upgrade your character in Spellsp...
So you’ve mastered the basics of Spellspire. By which I mean you’ve realised it’s all about spelling things in a spire. What next? Well you’re going to need to figure out how to toughen up your character. It’s all well and good being able to spell... | Read more »
5 slither.io mash-ups we'd love to...
If there's one thing that slither.io has proved, it's that the addictive gameplay of Agar.io can be transplanted onto basically anything and it will still be good fun. It wouldn't be surprising if we saw other developers jumping on the bandwagon,... | Read more »
How to navigate the terrain in Sky Charm...
Sky Charms is a whimsical match-'em up adventure that uses creative level design to really ramp up the difficulty. [Read more] | Read more »
Victorious Knight (Games)
Victorious Knight 1.3 Device: iOS Universal Category: Games Price: $1.99, Version: 1.3 (iTunes) Description: New challenges awaits you! Experience fresh RPG experience with a unique combat mechanic, packed with high quality 3D... | Read more »
Agent Gumball - Roguelike Spy Game (Gam...
Agent Gumball - Roguelike Spy Game 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: Someone’s been spying on Gumball. What the what?! Two can play at that game! GO UNDERCOVERSneak past enemy... | Read more »
Runaway Toad (Games)
Runaway Toad 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: It ain’t easy bein’ green! Tap, hold, and swipe to help Toad hop to safety in this gorgeous new action game from the creators of... | Read more »
PsyCard (Games)
PsyCard 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: From the makers och Card City Nights, Progress To 100 and Ittle Dew PSYCARD is a minesweeper-like game set in a cozy cyberpunk... | Read more »
Sago Mini Robot Party (Education)
Sago Mini Robot Party 1.0 Device: iOS Universal Category: Education Price: $2.99, Version: 1.0 (iTunes) Description: -- Children's Technology Review Editor's Choice -- | Read more »
Egz – The Origin of the Universe (Games...
Egz – The Origin of the Universe 1.0.2 Device: iOS Universal Category: Games Price: $3.99, Version: 1.0.2 (iTunes) Description: ►►► Special offer until 2nd may : get the game at 2.99€ instead of 3.99€ ! ◄◄◄ Egz is a mesmerizing mix... | Read more »

Price Scanner via MacPrices.net

Apple restocks Certified Refurbished Mac mini...
Apple has restocked Certified Refurbished 2014 Mac minis, with models available starting at $419. Apple’s one-year warranty is included with each mini, and shipping is free: - 1.4GHz Mac mini: $419 $... Read more
15-inch 2.2GHz Retina MacBook Pro on sale for...
Amazon.com has the 15″ 2.2GHz Retina MacBook Pro on sale for $1699.99 including free shipping. Their price is $300 off MSRP, and it’s the lowest price available for this model from any reseller (and... Read more
Apple Beats Microsoft at Own Game; Amazon Pri...
First quarter seasonality combined with an overall disinterested customer base led to an annual decline of 14.7% in worldwide tablet shipments during the first quarter of 2016 (1Q16). Worldwide... Read more
Tablets Had Worst Quarter Since 2012, says St...
The global tablet market began 2016 just as 2015 left off, down. Tablet shipments fell 10% to 46.5 million units during the Q1 2016, according to the new “Preliminary Global Tablet Shipments and... Read more
Clearance 13-inch MacBook Airs, Apple refurbi...
Apple recently dropped prices on certified refurbished 2015 13″ MacBook Airs with 4GB of RAM with models now available starting at $759. An Apple one-year warranty is included with each MacBook, and... Read more
Clearance 12-inch Retina MacBooks, Apple refu...
Apple has dropped prices on Certified Refurbished 2015 12″ Retina MacBooks with models now available starting at $929. Apple will include a standard one-year warranty with each MacBook, and shipping... Read more
Aleratec Releases Mac Software Upgrade for 1...
California based Aleratec Inc., designer, developer and manufacturer of Portable Device Management (PDM) charge/sync products for mobile devices and professional-grade duplicators for hard disk... Read more
Sale! Amazon offers 27-inch iMac, 13-inch 2.9...
Amazon has the 27″ 3.2GHz 5K iMac and the 13″ 3.9GHz Retina MacBook Pro on sale for $300 off MSRP, each including free shipping, for a limited time: - 27″ 3.2GHz/1TB HD 5K iMac (model MK462LL/A): $... Read more
Apple refurbished 13-inch Retina MacBook Pros...
Apple has Certified Refurbished 13″ Retina MacBook Pros available for up to $270 off the cost of new models. An Apple one-year warranty is included with each model, and shipping is free: - 13″ 2.7GHz... Read more
13-inch 2.7GHz/128GB Retina MacBook Pro on sa...
Take $200 off MSRP on the price of a new 13″ 2.7GHz/128GB Retina MacBook Pro (model MF839LL/A) at Amazon. Shipping is free: - 13″ 2.7GHz/128GB Retina MacBook Pro: $1099.99 $200 off MSRP Act now if... Read more

Jobs Board

Restaurant Manager (Neighborhood Captain) - A...
…in every aspect of daily operation. WHY YOU'LL LIKE IT: You'll be the Big Apple . You'll solve problems. You'll get to show your ability to handle the stress and Read more
Automotive Sales Consultant - Apple Ford Linc...
…you. The best candidates are smart, technologically savvy and are customer focused. Apple Ford Lincoln Apple Valley is different, because: $30,000 annual salary Read more
*Apple* Retail - Multiple Positions - Apple,...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
*Apple* Solutions Consultant - Apple (United...
# Apple Solutions Consultant Job Number: 48260200 Phoenix, Arizona, United States Posted: Apr. 22, 2016 Weekly Hours: 40.00 **Job Summary** As an Apple Solutions Read more
Restaurant Manager (Neighborhood Captain) - A...
…in every aspect of daily operation. WHY YOU'LL LIKE IT: You'll be the Big Apple . You'll solve problems. You'll get to show your ability to handle the stress and Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.