1 18 19 package org.apache.batik.ext.awt.image.renderable; 20 21 import java.awt.Rectangle ; 22 import java.awt.Shape ; 23 import java.awt.color.ColorSpace ; 24 import java.awt.geom.AffineTransform ; 25 import java.awt.geom.NoninvertibleTransformException ; 26 import java.awt.geom.Rectangle2D ; 27 import java.awt.image.RenderedImage ; 28 import java.awt.image.renderable.RenderContext ; 29 30 import org.apache.batik.ext.awt.image.rendered.TurbulencePatternRed; 31 32 38 public class TurbulenceRable8Bit 39 extends AbstractColorInterpolationRable 40 implements TurbulenceRable { 41 42 int seed = 0; int numOctaves = 1; double baseFreqX = 0; double baseFreqY = 0; 46 boolean stitched = false; boolean fractalNoise = false; 49 Rectangle2D region; 50 51 public TurbulenceRable8Bit(Rectangle2D region) { 52 super(); 53 this.region = region; 54 } 55 56 public TurbulenceRable8Bit(Rectangle2D region, 57 int seed, 58 int numOctaves, 59 double baseFreqX, 60 double baseFreqY, 61 boolean stitched, 62 boolean fractalNoise) { 63 super(); 64 this.seed = seed; 65 this.numOctaves = numOctaves; 66 this.baseFreqX = baseFreqX; 67 this.baseFreqY = baseFreqY; 68 this.stitched = stitched; 69 this.fractalNoise = fractalNoise; 70 this.region = region; 71 } 72 73 76 public Rectangle2D getTurbulenceRegion() { 77 return (Rectangle2D )region.clone(); 78 } 79 80 83 public Rectangle2D getBounds2D() { 84 return (Rectangle2D )region.clone(); 85 } 86 87 91 public int getSeed() { 92 return seed; 93 } 94 95 99 public int getNumOctaves() { 100 return numOctaves; 101 } 102 103 107 public double getBaseFrequencyX() { 108 return baseFreqX; 109 } 110 111 115 public double getBaseFrequencyY() { 116 return baseFreqY; 117 } 118 119 123 public boolean isStitched() { 124 return stitched; 125 } 126 127 133 public boolean isFractalNoise() { 134 return fractalNoise; 135 } 136 137 141 public void setTurbulenceRegion(Rectangle2D turbulenceRegion) { 142 touch(); 143 this.region = turbulenceRegion; 144 } 145 146 150 public void setSeed(int seed) { 151 touch(); 152 this.seed = seed; 153 } 154 155 159 public void setNumOctaves(int numOctaves) { 160 touch(); 161 this.numOctaves = numOctaves; 162 } 163 164 168 public void setBaseFrequencyX(double baseFreqX) { 169 touch(); 170 this.baseFreqX = baseFreqX; 171 } 172 173 177 public void setBaseFrequencyY(double baseFreqY) { 178 touch(); 179 this.baseFreqY = baseFreqY; 180 } 181 182 186 public void setStitched(boolean stitched) { 187 touch(); 188 this.stitched = stitched; 189 } 190 191 195 public void setFractalNoise(boolean fractalNoise) { 196 touch(); 197 this.fractalNoise = fractalNoise; 198 } 199 200 public RenderedImage createRendering(RenderContext rc){ 201 202 Rectangle2D aoiRect; 203 Shape aoi = rc.getAreaOfInterest(); 204 if(aoi == null){ 205 aoiRect = getBounds2D(); 206 } else { 207 Rectangle2D rect = getBounds2D(); 208 aoiRect = aoi.getBounds2D(); 209 if (aoiRect.intersects(rect) == false) 210 return null; 211 Rectangle2D.intersect(aoiRect, rect, aoiRect); 212 } 213 214 AffineTransform usr2dev = rc.getTransform(); 215 216 final Rectangle devRect 221 = usr2dev.createTransformedShape(aoiRect).getBounds(); 222 223 if ((devRect.width <= 0) || 224 (devRect.height <= 0)) 225 return null; 226 227 ColorSpace cs = getOperationColorSpace(); 228 229 Rectangle2D tile = null; 230 if (stitched) 231 tile = (Rectangle2D )region.clone(); 232 233 AffineTransform patternTxf = new AffineTransform (); 234 try{ 235 patternTxf = usr2dev.createInverse(); 236 }catch(NoninvertibleTransformException e){ 237 } 238 239 return new TurbulencePatternRed 240 (baseFreqX, baseFreqY, numOctaves, seed, fractalNoise, 241 tile, patternTxf, devRect, cs, true); 242 } 243 } 244 | Popular Tags |