All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.w3c.css.values.CssColor

java.lang.Object
   |
   +----org.w3c.css.values.CssValue
           |
           +----org.w3c.css.values.CssColor

public class CssColor
extends CssValue
implements CssColorConstants, CssOperator

   Color units

A color is a either a keyword or a numerical RGB specification.

The suggested list of keyword color names is: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow. These 16 colors are taken from the Windows VGA palette, and their RGB values are not defined in this specification.

   BODY {color: black; background: white }
   H1 { color: maroon }
   H2 { color: olive }
 

The RGB color model is being used in numerical color specifications. These examples all specify the same color:

   EM { color: #f00 }              / * #rgb * /
   EM { color: #ff0000 }           / * #rrggbb * /
   EM { color: rgb(255,0,0) }      / * integer range 0 - 255 * /
   EM { color: rgb(100%, 0%, 0%) } / * float range 0.0% - 100.0% * /
 

The format of an RGB value in hexadecimal notation is a '#' immediately followed by either three or six hexadecimal characters. The three-digit RGB notation (#rgb) is converted into six-digit form (#rrggbb) by replicating digits, not by adding zeros. For example, #fb0 expands to #ffbb00. This makes sure that white (#ffffff) can be specified with the short notation (#fff) and removes any dependencies on the color depth of the display.

The format of an RGB value in the functional notation is 'rgb(' followed by a comma-separated list of three numerical values (either three integer values in the range of 0-255, or three percentage values in the range of 0.0% to 100.0%) followed by ')'. Whitespace characters are allowed around the numerical values.

Values outside the numerical ranges should be clipped. The three rules below are therefore equivalent:

   EM { color: rgb(255,0,0) }       / * integer range 0 - 255 * /
   EM { color: rgb(300,0,0) }       / * clipped to 255 * /
   EM { color: rgb(110%, 0%, 0%) }  / * clipped to 100% * /
 

RGB colors are specified in the sRGB color space [9]. UAs may vary in the fidelity with which they represent these colors, but use of sRGB provides an unambiguous and objectively measurable definition of what the color should be, which can be related to international standards [10].

UAs may limit their efforts in displaying colors to performing a gamma-correction on them. sRGB specifies a display gamma of 2.2 under specified viewing conditions. UAs adjust the colors given in CSS such that, in combination with an output device's "natural" display gamma, an effective display gamma of 2.2 is produced. Appendix D gives further details of this. Note that only colors specified in CSS are affected; e.g., images are expected to carry their own color information.

Appendix D: Gamma correction

(This appendix is informative, not normative)

See the Gamma Tutorial in the PNG specification [12] if you aren't already familiar with gamma issues.

In the computation, UAs displaying on a CRT may assume an ideal CRT and ignore any effects on apparent gamma caused by dithering. That means the minimal handling they need to do on current platforms is:

PC using MS-Windows
none
Unix using X11
none
Mac using QuickDraw
apply gamma 1.39 [13] (ColorSync-savvy applications may simply pass the sRGB ICC profile [14] to ColorSync to perform correct color correction)
SGI using X
apply the gamma value from /etc/config/system.glGammaVal (the default value being 1.70; applications running on Irix 6.2 or above may simply pass the sRGB ICC profile to the color management system)
NeXT using NeXTStep
apply gamma 2.22

"Applying gamma" means that each of the three R, G and B must be converted to R'=Rgamma, G'=Ggamma, G'=Bgamma, before handing to the OS.

This may rapidly be done by building a 256-element lookup table once per browser invocation thus:

   for i := 0 to 255 do
     raw := i / 255;
     corr := pow (raw, gamma);
     table[i] := trunc (0.5 + corr * 255.0)
   end
 

which then avoids any need to do transcendental math per color attribute, far less per pixel. See also

[9] M Anderson, R Motta, S Chandrasekar, M Stokes: "Proposal for a Standard Color Space for the Internet - sRGB" (http://www.hpl.hp.com/personal/Michael_Stokes/srgb.htm)

[10] CIE Publication 15.2-1986, "Colorimetry, Second Edition", ISBN 3-900-734-00-3 (http://www.hike.te.chiba-u.ac.jp/ikeda/CIE/publ/abst/15-2-86.html)

[12] "PNG (Portable Network Graphics) Specification, Version 1.0 specification" (http://www.w3.org/pub/WWW/TR/REC-png-multi.html)

[13] Charles A. Poynton: "Gamma correction on the Macintosh Platform" (ftp://ftp.inforamp.net/pub/users/poynton/doc/Mac/Mac_gamma.pdf)

[14] International Color Consortium: "ICC Profile Format Specification, version 3.2", 1995 (ftp://sgigate.sgi.com/pub/icc/ICC32.pdf)


Constructor Index

 o CssColor()
Create a new CssColor.
 o CssColor(String)
Create a new CssColor with a color name.

Method Index

 o equals(Object)
Compares two values for equality.
 o get()
Return the internal value.
 o getBlue()
Gets the blue component of this color.
 o getGreen()
Gets the green component of this color.
 o getRed()
Gets the red component of this color.
 o isDefault()
Returns true if the internal value is the default value (e.g.
 o set(String, Frame)
Set the value from a defined color RBG.
 o setRGBColor(CssExpression, Frame)
Parse a RGB color.
 o toString()
Returns a string representation of the object.

Constructors

 o CssColor
 public CssColor()
Create a new CssColor.

 o CssColor
 public CssColor(String s) throws InvalidParamException
Create a new CssColor with a color name.

Parameters:
s - The name color.
Throws: InvalidParamException
the color is incorrect

Methods

 o set
 public void set(String s,
                 Frame frame) throws InvalidParamException
Set the value from a defined color RBG.

Parameters:
s - the string representation of the color.
Throws: InvalidParamException
the color is incorrect.
Overrides:
set in class CssValue
 o get
 public Object get()
Return the internal value.

Overrides:
get in class CssValue
 o isDefault
 public boolean isDefault()
Returns true if the internal value is the default value (e.g. 'inherited').

 o toString
 public String toString()
Returns a string representation of the object.

Overrides:
toString in class Object
 o setRGBColor
 public void setRGBColor(CssExpression exp,
                         Frame frame) throws InvalidParamException
Parse a RGB color. format rgb(%?, %?, %?)

 o equals
 public boolean equals(Object cssColor)
Compares two values for equality.

Parameters:
value - The other value.
Overrides:
equals in class CssValue
 o getRed
 public Object getRed()
Gets the red component of this color.

 o getGreen
 public Object getGreen()
Gets the green component of this color.

 o getBlue
 public Object getBlue()
Gets the blue component of this color.


All Packages  Class Hierarchy  This Package  Previous  Next  Index