# 6 - Doing Raster Color Management

This chapter describes how to use the built-in raster color management functions to produce enhanced color and grayscale output on raster printers.

## Overview of Raster Color Management

CUPS provides several ways for CUPS-based raster printer drivers to manage the colors produced by a non-PostScript printer. Figure 6-1 shows the raster processing workflow within CUPS. Starting with the print file, applications can embed ICC and other types of color profiles to alter the printed output.

Once converted to a RIP file format, the standard RIP filters can perform various linear transformations during rasterization, such as gamma correction, density adjustment, and color transforms using a matrix.

Upon arrival at the printer driver filter, the driver can perform any number of linear and non-linear transformations as needed. The DDK drivers and custom driver API offer non-linear 3D lookup tables for transforming grayscale and RGB colors to a K or CMYK representation and non-linear 2D lookup tables for transforming K or CMYK colors to device color values.

Figure 6-1, The CUPS raster processing workflow

Once converted to a device color, the color values are then dithered, as necessary, using per-color dithering parameters specific to the target device, rendering mode, resolution, and media.

Color management for PostScript and Ghostscript-based printer drivers is not currently supported by CUPS. Please consult the corresponding vendor documentation for any color management capabilities that are offered for those printers and drivers.

## RIP-Based Color Profiles

The first type of color profile supported by CUPS is provided by the RIP filters and is defined using the `cupsColorProfile` attribute in the PPD file or the `profile` attribute in the job options. Each profile consists of 11 numbers: the density, gamma, and CMY 3x3 color transform matrix. The `cupsColorProfile` PPD attribute value contains 11 real numbers separated by spaces, while the `profile` job attribute contains 11 integers separated by commas (`,`); multiple the PPD attribute numbers by 1000 to compute the job attribute numbers.

The `cupsColorProfile` attribute is specified using the `ColorProfile` or `SimpleColorProfile` directives in a driver information file. Each color profile can apply to a specific combination of resolution and media type or to all resolutions or media types. The RIP filter will use the first matching profile in the PPD file, so it is important to specify the specific profiles first followed by the general ones.

The `cupsprofile(1)` utility can be used to generate a RIP-based color profile using a series of four test pages. The results are suitable for calibrating basic business-type graphics to a particular combination of resolution and media.

One limitation of RIP-based color profiles is that they do not allow for non-linear color transformations typically required for accurate color reproduction.

## Driver-Based Color Profiles

The DDK drivers and driver API provide two types of color profiles: non-linear 3D RGB or grayscale color lookup table-based profiles, linear and non-linear 2D device color lookup table-based profiles, and 2D color dithering tables. Driver profiles are available only as attributes in the printer's PPD file.

### RGB Color Profiles

RGB profiles utilize 3D color lookup tables that map from sRGB color values to CMYK color values. Two PPD attributes, `cupsRGBProfile` and `cupsRGBSample`, are used to specify an RGB color profile. The `cupsRGBProfile` attribute specifies the number of samples on each side of the lookup cube, the number of color channels (1, 3, or 4 for K, CMY, and CMYK devices), and the number of color samples in the profile:

        *cupsRGBProfile Glossy.720dpi: "3 4 27"

Currently, the number of color samples must equal the cube of the cube size, that is an RGB color profile with a cube size of 4 must have 4 * 4 * 4 = 64 color samples which map the sRGB colors to CMYK. Also, the RGB samples must be spread evenly over the color cube.

Each color sample is represented using `cupsRGBSample` attributes. The value of each attribute consists of the sRGB and CMYK color values separated by spaces. Each color value is a real number from 0 to 1. For example, a sample for black which maps to a CMYK color of 0,0,0,1 might look like the following:

        *cupsRGBSample Glossy.720dpi: "0 0 0 0 0 0 1"

Table 6-1, CMYK color profile attributes
Attribute | Description
--- | ---
`cupsAllGamma` | Set default curve using gamma + density
`cupsAllXY` | Set default curve using XY points
`cupsBlackGamma` | Set black curve using gamma + density
`cupsBlackGeneration` | Set black generation
`cupsBlackLightDark` | Set black light/dark transition
`cupsBlackXY` | Set black curve using XY points
`cupsCyanGamma` | Set cyan curve using gamma + density
`cupsCyanLightDark` | Set cyan light/dark transition
`cupsCyanXY` | Set cyan curve using XY points
`cupsInkChannels` | Set number of color channels
`cupsInkLimit` | Set total ink limit
`cupsLightBlackGamma` | Set light black curve using gamma + density
`cupsLightBlackXY` | Set light black curve using XY points
`cupsLightCyanGamma` | Set light cyan curve using gamma + density
`cupsLightCyanXY` | Set light cyan curve using XY points
`cupsLightMagentaGamma` | Set light magenta curve using gamma + density
`cupsLightMagentaXY` | Set light magenta curve using XY points
`cupsMagentaGamma` | Set magenta curve using gamma + density
`cupsMagentaLightDark` | Set magenta light/dark transition
`cupsMagentaXY` | Set magenta curve using XY points
`cupsYellowGamma` | Set yellow curve using gamma + density
`cupsYellowXY` | Set yellow curve using XY points

Similarly, blue mapping to a CMYK value of 1,0.5,0,0 would look like:

        *cupsRGBSample Glossy.720dpi: "0 0 1 1 0.5 0 0"

### CMYK Color Profiles

CMYK color profiles map K, CMY, or CMYK colors to device colors. They are normally used to provide linear CMYK output and to transition between light and dark inks. When combined with application or RGB profiles, CMYK profiles allow for easier profiling using existing 4-color profiling software.

The CMYK color profiles are implemented as 2D lookup tables; the tables can be generated automatically using gamma and density values, or manually using measurements of specific values. For printers that support more than 4 inks, the light ink lookup tables are driven by the main color, e.g. the light cyan output value is based upon the cyan input value.

CMYK color profiles are only available via PPD attributes. Table 6-1 lists the supported attributes. The `cupsInkChannels` attribute specifies the number of output color channels, typically 1, 3, 4, 6, or 7.

The `cupsInkLimit` attribute specifies the maximum amount of ink that can be placed on the page. When the total amount of ink exceeds the ink limit, all color channels are scaled linearly to the specified limit.

The `cupsBlackGeneration` attribute specifies a transition range for representing shades of gray as a combination of CMY or as K. The first number specifies the start of the transition range where K = 0 and the second the end of the transition range where CMY = 0.

The gamma attributes define the gamma and density of the specified color channel. For example, the following attribute sets the default gamma and density at 1440dpi to 2.0 and 0.9, respectively:

        Attribute cupsAllGamma 1440dpi "2.0 0.9"

The XY attributes specify a point in a piecewise linear curve from an input color value to a measured output value. For example, the XY values for four measurements at 1440dpi would look like the following:

        Attriute cupsAllXY 1440dpi "0.25 0.337"
        Attriute cupsAllXY 1440dpi "0.5 0.633"
        Attriute cupsAllXY 1440dpi "0.75 0.91"
        Attriute cupsAllXY 1440dpi "1.0 1.24"

The `LtDk` ("light dark") attributes specify a transition area for light to dark inks using the dark ink lookup table. The first value specifies the input color value which maps to 100% of the light color output value and the second value specifies the input color value which maps to 0% of the light color output value. The dark color is mapped to 0 up to the first value and is ramped up to the second value as the light color decreases.

Table 6-2, Dither attributes
Attribute | Description
--- | ---
`cupsAllDither` | Sets the default dither values
`cupsBlackDither` | Sets the black dither values
`cupsCyanDither` | Sets the cyan dither values
`cupsLightBlackDither` | Sets the light black dither values
`cupsLightCyanDither` | Sets the light cyan dither values
`cupsLightMagentaDither` | Sets the light magenta dither values
`cupsMagentaDither` | Sets the maenta dither values
`cupsYellowDither` | Sets the yellow dither values

### Dithering Tables

Once converted to device colors, the dither functions use PPD attributes to define the dot densities for each supported size. Table 6-2 lists the supported attributes. For example, the following attributes might be used to define the default dither values for three resolutions:

        Attribute cupsAllDither 360dpi "0.5 0.75 1.0"
        Attribute cupsAllDither 720dpi "0.6 0.9 1.2"
        Attribute cupsAllDither 1440dpi "0.9 1.35"