1 7 8 package java.awt; 9 10 import java.awt.MultipleGradientPaint.CycleMethod ; 11 import java.awt.MultipleGradientPaint.ColorSpaceType ; 12 import java.awt.geom.AffineTransform ; 13 import java.awt.geom.Point2D ; 14 import java.awt.geom.Rectangle2D ; 15 import java.awt.image.ColorModel ; 16 17 26 final class LinearGradientPaintContext extends MultipleGradientPaintContext { 27 28 33 private float dgdX, dgdY, gc; 34 35 59 LinearGradientPaintContext(LinearGradientPaint paint, 60 ColorModel cm, 61 Rectangle deviceBounds, 62 Rectangle2D userBounds, 63 AffineTransform t, 64 RenderingHints hints, 65 Point2D start, 66 Point2D end, 67 float[] fractions, 68 Color [] colors, 69 CycleMethod cycleMethod, 70 ColorSpaceType colorSpace) 71 { 72 super(paint, cm, deviceBounds, userBounds, t, hints, fractions, 73 colors, cycleMethod, colorSpace); 74 75 85 float startx = (float)start.getX(); 86 float starty = (float)start.getY(); 87 float endx = (float)end.getX(); 88 float endy = (float)end.getY(); 89 90 float dx = endx - startx; float dy = endy - starty; float dSq = dx*dx + dy*dy; 94 float constX = dx/dSq; 96 float constY = dy/dSq; 97 98 dgdX = a00*constX + a10*constY; 100 dgdY = a01*constX + a11*constY; 102 103 gc = (a02-startx)*constX + (a12-starty)*constY; 105 } 106 107 115 protected void fillRaster(int[] pixels, int off, int adjust, 116 int x, int y, int w, int h) 117 { 118 float g = 0; 120 121 int rowLimit = off + w; 123 124 float initConst = (dgdX*x) + gc; 126 127 for (int i = 0; i < h; i++) { 129 g = initConst + dgdY*(y+i); 131 132 while (off < rowLimit) { pixels[off++] = indexIntoGradientsArrays(g); 135 136 g += dgdX; 138 } 139 140 off += adjust; 142 143 rowLimit = off + w; 145 } 146 } 147 } 148
| Popular Tags
|