]> gerrit.simantics Code Review - simantics/3d.git/blob - javax.vecmath/src/javax/vecmath/Color4b.java
Included old javax.vecmath 1.5.2 to org.simantics.g3d.feature
[simantics/3d.git] / javax.vecmath / src / javax / vecmath / Color4b.java
1 /*
2  * $RCSfile: Color4b.java,v $
3  *
4  * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6  *
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.
12  *
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).
18  *
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.
22  *
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
25  * have any questions.
26  *
27  * $Revision: 1.6 $
28  * $Date: 2008/02/28 20:18:50 $
29  * $State: Exp $
30  */
31
32 package javax.vecmath;
33
34 import java.awt.Color;
35
36
37 /**
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.
41  * <p>
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.
47  * <p>
48  * Java 3D assumes that a linear (gamma-corrected) visual is used for
49  * all colors.
50  *
51  */
52 public class Color4b extends Tuple4b implements java.io.Serializable {
53
54     // Compatible with 1.1
55     static final long serialVersionUID = -105080578052502155L;
56
57     /**
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
63      */
64     public Color4b(byte b1, byte b2, byte b3, byte b4) {
65         super(b1,b2,b3,b4);
66     }
67
68
69     /**
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
72      */
73     public Color4b(byte[] c) {
74         super(c);
75     }
76
77
78     /**
79      * Constructs and initializes a Color4b from the specified Color4b.
80      * @param c1 the Color4b containing the initialization r,g,b,a
81      * data
82      */
83     public Color4b(Color4b c1) {
84         super(c1);
85     }
86
87
88     /**
89      * Constructs and initializes a Color4b from the specified Tuple4b.
90      * @param t1 the Tuple4b containing the initialization r,g,b,a
91      * data
92      */
93     public Color4b(Tuple4b t1) {
94         super(t1);
95     }
96
97
98     /**
99      * Constructs and initializes a Color4b from the specified AWT
100      * Color object.
101      * No conversion is done on the color to compensate for
102      * gamma correction.
103      *
104      * @param color the AWT color with which to initialize this
105      * Color4b object
106      *
107      * @since vecmath 1.2
108      */
109     public Color4b(Color color) {
110         super((byte)color.getRed(),
111               (byte)color.getGreen(),
112               (byte)color.getBlue(),
113               (byte)color.getAlpha());
114     }
115
116
117     /**
118      * Constructs and initializes a Color4b to (0,0,0,0).
119      */
120     public Color4b() {
121         super();
122     }
123
124
125     /**
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
129      * gamma correction.
130      *
131      * @param color the AWT color to copy into this Color4b object
132      *
133      * @since vecmath 1.2
134      */
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();
140     }
141
142
143     /**
144      * Returns a new AWT color object initialized with the r,g,b,a
145      * values of this Color4b object.
146      *
147      * @return a new AWT Color object
148      *
149      * @since vecmath 1.2
150      */
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;
156
157         return new Color(r, g, b, a);
158     }
159
160 }