2 * $RCSfile: Color3b.java,v $
4 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 * This code is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 only, as
9 * published by the Free Software Foundation. Sun designates this
10 * particular file as subject to the "Classpath" exception as provided
11 * by Sun in the LICENSE file that accompanied this code.
13 * This code is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * version 2 for more details (a copy is included in the LICENSE file that
17 * accompanied this code).
19 * You should have received a copy of the GNU General Public License version
20 * 2 along with this work; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
24 * CA 95054 USA or visit www.sun.com if you need additional information or
28 * $Date: 2008/02/28 20:18:50 $
32 package javax.vecmath;
34 import java.awt.Color;
38 * A three-byte color value represented by byte x, y, and z values. The
39 * x, y, and z values represent the red, green, and blue values,
42 * Note that Java defines a byte as a signed integer in the range
43 * [-128, 127]. However, colors are more typically represented by values
44 * in the range [0, 255]. Java 3D recognizes this and for color
45 * treats the bytes as if the range were [0, 255]---in other words, as
46 * if the bytes were unsigned.
48 * Java 3D assumes that a linear (gamma-corrected) visual is used for
52 public class Color3b extends Tuple3b implements java.io.Serializable {
54 // Compatible with 1.1
55 static final long serialVersionUID = 6632576088353444794L;
58 * Constructs and initializes a Color3b from the specified three values.
59 * @param c1 the red color value
60 * @param c2 the green color value
61 * @param c3 the blue color value
63 public Color3b(byte c1, byte c2, byte c3) {
69 * Constructs and initializes a Color3b from input array of length 3.
70 * @param c the array of length 3 containing the r,g,b data in order
72 public Color3b(byte[] c) {
78 * Constructs and initializes a Color3b from the specified Color3b.
79 * @param c1 the Color3b containing the initialization r,g,b data
81 public Color3b(Color3b c1) {
87 * Constructs and initializes a Color3b from the specified Tuple3b.
88 * @param t1 the Tuple3b containing the initialization r,g,b data
90 public Color3b(Tuple3b t1) {
96 * Constructs and initializes a Color3b from the specified AWT
97 * Color object. The alpha value of the AWT color is ignored.
98 * No conversion is done on the color to compensate for
101 * @param color the AWT color with which to initialize this
106 public Color3b(Color color) {
107 super((byte)color.getRed(),
108 (byte)color.getGreen(),
109 (byte)color.getBlue());
114 * Constructs and initializes a Color3b to (0,0,0).
122 * Sets the r,g,b values of this Color3b object to those of the
123 * specified AWT Color object.
124 * No conversion is done on the color to compensate for
127 * @param color the AWT color to copy into this Color3b object
131 public final void set(Color color) {
132 x = (byte)color.getRed();
133 y = (byte)color.getGreen();
134 z = (byte)color.getBlue();
139 * Returns a new AWT color object initialized with the r,g,b
140 * values of this Color3b object.
142 * @return a new AWT Color object
146 public final Color get() {
147 int r = (int)x & 0xff;
148 int g = (int)y & 0xff;
149 int b = (int)z & 0xff;
151 return new Color(r, g, b);