Source code: com/anotherbigidea/flash/structs/Color.java
1 /****************************************************************
2 * Copyright (c) 2001, David N. Main, All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the
6 * following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 *
17 * 3. The name of the author may not be used to endorse or
18 * promote products derived from this software without specific
19 * prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ****************************************************************/
34 package com.anotherbigidea.flash.structs;
35
36 import java.io.*;
37 import com.anotherbigidea.io.*;
38
39 /**
40 * An RGB Color without alpha
41 */
42 public class Color
43 {
44 protected int red;
45 protected int green;
46 protected int blue;
47
48 public int getRed() { return red; }
49 public int getGreen() { return green; }
50 public int getBlue() { return blue; }
51
52 public void setRed ( int red ) { this.red = red; }
53 public void setGreen( int green ) { this.green = green; }
54 public void setBlue ( int blue ) { this.blue = blue; }
55
56 public Color( int red, int green, int blue )
57 {
58 this.red = red;
59 this.green = green;
60 this.blue = blue;
61 }
62
63 public Color( InStream in ) throws IOException
64 {
65 red = in.readUI8();
66 green = in.readUI8();
67 blue = in.readUI8();
68 }
69
70 public void write( OutStream out ) throws IOException
71 {
72 writeRGB( out );
73 }
74
75 public boolean equals( Color color )
76 {
77 return ( red == color.getRed() )
78 &&( green == color.getGreen() )
79 &&( blue == color.getBlue() );
80 }
81
82 public void writeRGB( OutStream out ) throws IOException
83 {
84 out.writeUI8( red );
85 out.writeUI8( green );
86 out.writeUI8( blue );
87 }
88
89 public void writeWithAlpha( OutStream out ) throws IOException
90 {
91 writeRGB( out );
92 out.writeUI8( 0xff ); //fully opaque alpha
93 }
94
95 public String toString()
96 {
97 return "RGB("+red+","+green+","+blue+")";
98 }
99 }