2 * $RCSfile: Color4b.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 four-byte color value represented by byte x, y, z, and w values.
39 * The x, y, z, and w values represent the red, green, blue, and alpha
40 * values, respectively.
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 Color4b extends Tuple4b implements java.io.Serializable {
54 // Compatible with 1.1
55 static final long serialVersionUID = -105080578052502155L;
58 * Constructs and initializes a Color4b from the four specified values.
59 * @param b1 the red color value
60 * @param b2 the green color value
61 * @param b3 the blue color value
62 * @param b4 the alpha value
64 public Color4b(byte b1, byte b2, byte b3, byte b4) {
70 * Constructs and initializes a Color4b from the array of length 4.
71 * @param c the array of length 4 containing r, g, b, and alpha in order
73 public Color4b(byte[] c) {
79 * Constructs and initializes a Color4b from the specified Color4b.
80 * @param c1 the Color4b containing the initialization r,g,b,a
83 public Color4b(Color4b c1) {
89 * Constructs and initializes a Color4b from the specified Tuple4b.
90 * @param t1 the Tuple4b containing the initialization r,g,b,a
93 public Color4b(Tuple4b t1) {
99 * Constructs and initializes a Color4b from the specified AWT
101 * No conversion is done on the color to compensate for
104 * @param color the AWT color with which to initialize this
109 public Color4b(Color color) {
110 super((byte)color.getRed(),
111 (byte)color.getGreen(),
112 (byte)color.getBlue(),
113 (byte)color.getAlpha());
118 * Constructs and initializes a Color4b to (0,0,0,0).
126 * Sets the r,g,b,a values of this Color4b object to those of the
127 * specified AWT Color object.
128 * No conversion is done on the color to compensate for
131 * @param color the AWT color to copy into this Color4b object
135 public final void set(Color color) {
136 x = (byte)color.getRed();
137 y = (byte)color.getGreen();
138 z = (byte)color.getBlue();
139 w = (byte)color.getAlpha();
144 * Returns a new AWT color object initialized with the r,g,b,a
145 * values of this Color4b object.
147 * @return a new AWT Color object
151 public final Color get() {
152 int r = (int)x & 0xff;
153 int g = (int)y & 0xff;
154 int b = (int)z & 0xff;
155 int a = (int)w & 0xff;
157 return new Color(r, g, b, a);