1 50 51 package org.openlaszlo.iv.flash.api; 52 53 import java.io.*; 54 import java.util.*; 55 import java.lang.Math ; 56 import org.openlaszlo.iv.flash.parser.*; 57 import org.openlaszlo.iv.flash.util.*; 58 59 65 public class Color extends FlashItem { 66 67 protected int r; 68 protected int g; 69 protected int b; 70 71 public Color() {} 72 73 78 public Color( int rgb ) { 79 setRGB( rgb ); 80 } 81 82 90 public Color( int r, int g, int b ) { 91 this.r = r; 92 this.g = g; 93 this.b = b; 94 } 95 96 104 public Color( float r, float g, float b ) { 105 this.r = Math.round( r * 255 ); 106 this.g = Math.round( g * 255 ); 107 this.b = Math.round( b * 255 ); 108 } 109 110 public int getRed() { 111 return r; 112 } 113 114 public int getGreen() { 115 return g; 116 } 117 118 public int getBlue() { 119 return b; 120 } 121 122 public int getAlpha() { 123 return 255; 124 } 125 126 131 public int getRGB() { 132 return r<<16 | g<<8 | b; 133 } 134 135 public void setRed( int r ) { 136 this.r = r; 137 } 138 public void setGreen( int g ) { 139 this.g = g; 140 } 141 public void setBlue( int b ) { 142 this.b = b; 143 } 144 145 150 public void setRGB( int rgb ) { 151 r = (rgb&0x00ff0000)>>16; 152 g = (rgb&0x0000ff00)>>8; 153 b = (rgb&0x000000ff); 154 } 155 156 159 public boolean hasAlpha() { return false; } 160 161 171 public Color brighter( double f ) { 172 return CXForm.newBrightness(f, hasAlpha()).transform(this); 173 } 174 175 178 public java.awt.Color getAWTColor() { 179 java.awt.Color color; 180 if( hasAlpha() ) { 181 color = new java.awt.Color (r, g, b, getAlpha()); 182 } else { 183 color = new java.awt.Color (r, g, b); 184 } 185 return color; 186 } 187 188 public void write( FlashOutput fob ) { 189 writeRGB( fob ); 190 } 191 192 197 public void writeRGB( FlashOutput fob ) { 198 fob.writeByte( r ); 199 fob.writeByte( g ); 200 fob.writeByte( b ); 201 } 202 203 209 public void writeRGBA( FlashOutput fob ) { 210 fob.writeByte( r ); 211 fob.writeByte( g ); 212 fob.writeByte( b ); 213 fob.writeByte( 255 ); 214 } 215 216 public void printContent( PrintStream out, String indent ) { 217 out.println( indent+"Color: (0x"+Util.b2h(r)+",0x"+Util.b2h(g)+",0x"+Util.b2h(b)+")" ); 218 } 219 220 226 public static Color parseRGB( Parser p ) { 227 return new Color(p.getUByte(),p.getUByte(),p.getUByte()); 228 } 229 230 236 public static AlphaColor parseRGBA( Parser p ) { 237 return new AlphaColor(p.getUByte(),p.getUByte(),p.getUByte(),p.getUByte()); 238 } 239 240 248 public static Color parse( Parser p, boolean withAlpha ) { 249 if( withAlpha ) return parseRGBA(p); 250 return parseRGB(p); 251 } 252 253 public static void skip( Parser p ) { 254 p.skip(3); 255 } 256 257 public static void skip( Parser p, boolean withAlpha ) { 258 if( withAlpha ) p.skip(4); 259 else p.skip(3); 260 } 261 262 protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) { 263 super.copyInto( item, copier ); 264 ((Color)item).r = r; 265 ((Color)item).g = g; 266 ((Color)item).b = b; 267 return item; 268 } 269 public FlashItem getCopy( ScriptCopier copier ) { 270 return copyInto( new Color(), copier ); 271 } 272 273 public boolean equals( Object o ) { 274 if( o instanceof Color ) { 275 Color c = (Color) o; 276 return r == c.r && g == c.g && b == c.b; 277 } 278 return false; 279 } 280 281 } 282 | Popular Tags |