]> gerrit.simantics Code Review - simantics/3d.git/blob - javax.vecmath/src/javax/vecmath/Color3b.java
Included old javax.vecmath 1.5.2 to org.simantics.g3d.feature
[simantics/3d.git] / javax.vecmath / src / javax / vecmath / Color3b.java
1 /*
2  * $RCSfile: Color3b.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 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,
40  * 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 Color3b extends Tuple3b implements java.io.Serializable {
53
54     // Compatible with 1.1
55     static final long serialVersionUID = 6632576088353444794L;
56
57     /**
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
62      */
63     public Color3b(byte c1, byte c2, byte c3) {
64         super(c1,c2,c3);
65     }
66
67
68     /**
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
71      */
72     public Color3b(byte[] c) {
73         super(c);
74     }
75
76
77     /**
78      * Constructs and initializes a Color3b from the specified Color3b.
79      * @param c1 the Color3b containing the initialization r,g,b data
80      */
81     public Color3b(Color3b c1) {
82         super(c1);
83     }
84
85
86     /**
87      * Constructs and initializes a Color3b from the specified Tuple3b.
88      * @param t1 the Tuple3b containing the initialization r,g,b data
89      */
90     public Color3b(Tuple3b t1) {
91         super(t1);
92     }
93
94
95     /**
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
99      * gamma correction.
100      *
101      * @param color the AWT color with which to initialize this
102      * Color3b object
103      *
104      * @since vecmath 1.2
105      */
106     public Color3b(Color color) {
107         super((byte)color.getRed(),
108               (byte)color.getGreen(),
109               (byte)color.getBlue());
110     }
111
112
113     /**
114      * Constructs and initializes a Color3b to (0,0,0).
115      */
116     public Color3b() {
117         super();
118     }
119
120
121     /**
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
125      * gamma correction.
126      *
127      * @param color the AWT color to copy into this Color3b object
128      *
129      * @since vecmath 1.2
130      */
131     public final void set(Color color) {
132         x = (byte)color.getRed();
133         y = (byte)color.getGreen();
134         z = (byte)color.getBlue();
135     }
136
137
138     /**
139      * Returns a new AWT color object initialized with the r,g,b
140      * values of this Color3b object.
141      *
142      * @return a new AWT Color object
143      *
144      * @since vecmath 1.2
145      */
146     public final Color get() {
147         int r = (int)x & 0xff;
148         int g = (int)y & 0xff;
149         int b = (int)z & 0xff;
150
151         return new Color(r, g, b);
152     }
153
154 }