home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Book Home Java Enterprise in a Nutshell Search this book

4.12. Color Spaces

The java.awt.Color class represents a color in Java. As we discussed earlier, Java 2D has added several new constructors to the Color class, to support the creation of translucent colors. Another important change to the Color class is support for arbitrary color spaces. A color space is a system for representing a color using some characteristic set of axes.

Java 2D introduces the java.awt.color package for working with color spaces. The most important piece of this package is the abstract ColorSpace class, which represents a color space and defines a number of constants for commonly used spaces. By default, Java colors are represented in the standard, device-independent sRGB color space, in which colors are represented by idealized red, green, and blue components. There are other ways of representing colors, however. One commonly used standard is the CIEXYZ space, which represents colors in terms of three abstract components named X, Y, and Z. Applications that represent colors to be displayed on a printed page often use the CMYK color space, which represents the cyan, magenta, yellow, and black inks used in the four-color printing process. Another familiar color space is the grayscale color space, which represents shades of gray as individual values between 0.0 (black) and 1.0 (white).

An application that cares about accurate color reproduction often uses a device-independent color space to ensure that the colors it displays look the same on different monitors, printers, and other devices. To make device-independent color representation work, each monitor, printer, scanner, or other device needs to be calibrated, so that device-independent colors can be correctly and accurately converted to appropriate device-dependent colors for that device. The result of a device calibration is called a "profile." The International Color Consortium (ICC) has defined a standard file format for profiles, and the java.awt.color package defines classes that implement color spaces in terms of these profiles. Sun's implementation of the Java 1.2 runtime environment includes five sample profiles for five different color spaces, stored in the jre/lib/cmm directory of the Java installation. A more sophisticated implementation would obtain profiles from the color management system of the native OS.

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.