]> gerrit.simantics Code Review - simantics/3d.git/blob - javax.vecmath/src/javax/vecmath/Color4f.java
Included old javax.vecmath 1.5.2 to org.simantics.g3d.feature
[simantics/3d.git] / javax.vecmath / src / javax / vecmath / Color4f.java
1 /*
2  * $RCSfile: Color4f.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-element color represented by single precision floating point 
39  * x, y, z, and w values.  The x, y, z, and w values represent the red,
40  * blue, green, and alpha color values, respectively. Color and alpha 
41  * components should be in the range [0.0, 1.0].
42  * <p>
43  * Java 3D assumes that a linear (gamma-corrected) visual is used for
44  * all colors.
45  *
46  */
47 public class Color4f extends Tuple4f implements java.io.Serializable {
48
49     // Compatible with 1.1
50     static final long serialVersionUID = 8577680141580006740L;
51
52     /**
53      * Constructs and initializes a Color4f from the specified xyzw
54      * coordinates.
55      * @param x the red color value
56      * @param y the green color value
57      * @param z the blue color value
58      * @param w the alpha value
59      */
60     public Color4f(float x, float y, float z, float w) {
61         super(x,y,z,w);
62     }
63
64
65     /**
66      * Constructs and initializes a Color4f from the array of length 4.
67      * @param c the array of length 4 containing r,g,b,a in order
68      */
69     public Color4f(float[] c) {
70         super(c);
71     }
72
73
74     /**
75      * Constructs and initializes a Color4f from the specified Color4f.
76      * @param c1 the Color4f containing the initialization r,g,b,a data
77      */
78     public Color4f(Color4f c1) {
79         super(c1);
80     }
81
82
83     /**
84      * Constructs and initializes a Color4f from the specified Tuple4f.
85      * @param t1 the Tuple4f containing the initialization r,g,b,a data
86      */
87     public Color4f(Tuple4f t1) {
88         super(t1);
89     }
90
91
92     /**
93      * Constructs and initializes a Color4f from the specified Tuple4d.
94      * @param t1 the Tuple4d containing the initialization r,g,b,a data
95      */
96     public Color4f(Tuple4d t1) {
97         super(t1);
98     }
99
100
101     /**
102      * Constructs and initializes a Color4f from the specified AWT
103      * Color object.
104      * No conversion is done on the color to compensate for
105      * gamma correction.
106      *
107      * @param color the AWT color with which to initialize this
108      * Color4f object
109      *
110      * @since vecmath 1.2
111      */
112     public Color4f(Color color) {
113         super((float)color.getRed() / 255.0f,
114               (float)color.getGreen() / 255.0f,
115               (float)color.getBlue() / 255.0f,
116               (float)color.getAlpha() / 255.0f);
117     }
118
119
120     /**
121      * Constructs and initializes a Color4f to (0.0, 0.0, 0.0, 0.0).
122      */
123     public Color4f() {
124         super();
125     }
126
127
128     /**
129      * Sets the r,g,b,a values of this Color4f object to those of the
130      * specified AWT Color object.
131      * No conversion is done on the color to compensate for
132      * gamma correction.
133      *
134      * @param color the AWT color to copy into this Color4f object
135      *
136      * @since vecmath 1.2
137      */
138     public final void set(Color color) {
139         x = (float)color.getRed() / 255.0f;
140         y = (float)color.getGreen() / 255.0f;
141         z = (float)color.getBlue() / 255.0f;
142         w = (float)color.getAlpha() / 255.0f;
143     }
144
145
146     /**
147      * Returns a new AWT color object initialized with the r,g,b,a
148      * values of this Color4f object.
149      *
150      * @return a new AWT Color object
151      *
152      * @since vecmath 1.2
153      */
154     public final Color get() {
155         int r = Math.round(x * 255.0f);
156         int g = Math.round(y * 255.0f);
157         int b = Math.round(z * 255.0f);
158         int a = Math.round(w * 255.0f);
159
160         return new Color(r, g, b, a);
161     }
162
163 }