1 18 package org.apache.batik.ext.awt.image; 19 20 27 public final class CompositeRule implements java.io.Serializable { 28 29 30 public static final int RULE_OVER = 1; 31 32 33 public static final int RULE_IN = 2; 34 35 36 public static final int RULE_OUT = 3; 37 38 39 public static final int RULE_ATOP = 4; 40 41 42 public static final int RULE_XOR = 5; 43 44 45 public static final int RULE_ARITHMETIC = 6; 46 47 48 public static final int RULE_MULTIPLY = 7; 49 50 51 public static final int RULE_SCREEN = 8; 52 53 54 public static final int RULE_DARKEN = 9; 55 56 57 public static final int RULE_LIGHTEN = 10; 58 59 60 70 public static final CompositeRule OVER = new CompositeRule(RULE_OVER); 71 72 82 public static final CompositeRule IN = new CompositeRule(RULE_IN); 83 84 94 public static final CompositeRule OUT = new CompositeRule(RULE_OUT); 95 96 107 public static final CompositeRule ATOP = new CompositeRule(RULE_ATOP); 108 109 118 public static final CompositeRule XOR = new CompositeRule(RULE_XOR); 119 120 125 public static CompositeRule ARITHMETIC 126 (float k1, float k2, float k3, float k4) { 127 return new CompositeRule(k1, k2, k3, k4); 128 } 129 130 137 public static final CompositeRule MULTIPLY = 138 new CompositeRule(RULE_MULTIPLY); 139 140 147 public static final CompositeRule SCREEN = 148 new CompositeRule(RULE_SCREEN); 149 150 158 public static final CompositeRule DARKEN = 159 new CompositeRule(RULE_DARKEN); 160 161 162 170 public static final CompositeRule LIGHTEN = 171 new CompositeRule(RULE_LIGHTEN); 172 173 174 177 public int getRule() { 178 return rule; 179 } 180 181 184 private int rule; 185 186 187 private float k1, k2, k3, k4; 188 189 private CompositeRule(int rule) { 190 this.rule = rule; 191 } 192 193 private CompositeRule(float k1, float k2, float k3, float k4) { 194 rule = RULE_ARITHMETIC; 195 this.k1 = k1; 196 this.k2 = k2; 197 this.k3 = k3; 198 this.k4 = k4; 199 } 200 201 public float [] getCoefficients() { 202 if (rule != RULE_ARITHMETIC) 203 return null; 204 205 return new float[] {k1, k2, k3, k4}; 206 } 207 208 215 private Object readResolve() throws java.io.ObjectStreamException { 216 switch(rule){ 217 case RULE_OVER: 218 return OVER; 219 case RULE_IN: 220 return IN; 221 case RULE_OUT: 222 return OUT; 223 case RULE_ATOP: 224 return ATOP; 225 case RULE_XOR: 226 return XOR; 227 case RULE_ARITHMETIC: 228 return this; 229 case RULE_MULTIPLY: 230 return MULTIPLY; 231 case RULE_SCREEN: 232 return SCREEN; 233 case RULE_DARKEN: 234 return DARKEN; 235 case RULE_LIGHTEN: 236 return LIGHTEN; 237 default: 238 throw new Error ("Unknown Composite Rule type"); 239 } 240 } 241 242 249 public String toString() { 250 switch(rule){ 251 case RULE_OVER: 252 return "[CompositeRule: OVER]"; 253 case RULE_IN: 254 return "[CompositeRule: IN]"; 255 case RULE_OUT: 256 return "[CompositeRule: OUT]"; 257 case RULE_ATOP: 258 return "[CompositeRule: ATOP]"; 259 case RULE_XOR: 260 return "[CompositeRule: XOR]"; 261 case RULE_ARITHMETIC: 262 return ("[CompositeRule: ARITHMATIC k1:" + 263 k1 + " k2: " + k2 + " k3: " + k3 + " k4: " + k4 + "]"); 264 case RULE_MULTIPLY: 265 return "[CompositeRule: MULTIPLY]"; 266 case RULE_SCREEN: 267 return "[CompositeRule: SCREEN]"; 268 case RULE_DARKEN: 269 return "[CompositeRule: DARKEN]"; 270 case RULE_LIGHTEN: 271 return "[CompositeRule: LIGHTEN]"; 272 default: 273 throw new Error ("Unknown Composite Rule type"); 274 } 275 } 276 277 } 278 | Popular Tags |