- public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, PixelBuffer buf) {
- buf.fillTrapezoid(x1, x2, y1, x3, x4, y2, color);
+ public void fillTrapezoid(float x1, float x2, float y1, float x3, float x4, float y2, PixelBuffer buf) {
+ buf.fillTrapezoid((int)Math.round(x1), (int)Math.round(x2), (int)Math.round(y1),
+ (int)Math.round(x3), (int)Math.round(x4), (int)Math.round(y2), color);
+ public static class TexturePaint extends Paint {
+ Affine a, invert;
+ Picture p;
+ public TexturePaint(Picture p, Affine a) { this.p = p; this.a = a.copy(); this.invert = a.copy().invert(); }
+ public void fillTrapezoid(float tx1, float tx2, float ty1, float tx3, float tx4, float ty2, PixelBuffer buf) {
+ /*
+ float x1 = invert.multiply_px(tx1, ty1);
+ float x2 = invert.multiply_px(tx2, ty1);
+ float x3 = invert.multiply_px(tx3, ty2);
+ float x4 = invert.multiply_px(tx4, ty2);
+ float y1 = invert.multiply_py(tx1, ty1);
+ float y2 = invert.multiply_py(tx3, ty2);
+ */
+ //buf.paintTrapezoid((int)tx1, (int)tx2, (int)ty1, (int)tx3, (int)tx4, (int)ty2, p, a);
+ }
+ }
- /*
- public static abstract class GradientPaint extends Paint {
- public GradientPaint(boolean reflect, boolean repeat, Affine gradientTransform,
- int[] stop_colors, float[] stop_offsets) {
- this.reflect = reflect; this.repeat = repeat;
- this.gradientTransform = gradientTransform;
- this.stop_colors = stop_colors;
- this.stop_offsets = stop_offsets;
- }
- Affine gradientTransform = Affine.identity();
- boolean useBoundingBox = false; // FIXME not supported
- boolean patternUseBoundingBox = false; // FIXME not supported
-
- // it's invalid for both of these to be true
- boolean reflect = false; // FIXME not supported
- boolean repeat = false; // FIXME not supported
- int[] stop_colors;
- float[] stop_offsets;
-
- public void fillTrapezoid(float tx1, float tx2, float ty1, float tx3, float tx4, float ty2, PixelBuffer buf) {
- Affine a = buf.a;
- Affine inverse = a.copy().invert();
- float slope1 = (tx3 - tx1) / (ty2 - ty1);
- float slope2 = (tx4 - tx2) / (ty2 - ty1);
- for(float y=ty1; y<ty2; y++) {
- float _x1 = (y - ty1) * slope1 + tx1;
- float _x2 = (y - ty1) * slope2 + tx2;
- if (_x1 > _x2) { float _x0 = _x1; _x1 = _x2; _x2 = _x0; }
+ public static abstract class GradientPaint extends Paint {
+ public GradientPaint(boolean reflect, boolean repeat, Affine gradientTransform, int[] stop_colors, float[] stop_offsets) {
+ this.reflect = reflect;
+ this.repeat = repeat;
+ this.gradientTransform = gradientTransform;
+ this.stop_colors = stop_colors;
+ this.stop_offsets = stop_offsets;
+ }
- for(float x=_x1; x<_x2; x++) {
+ Affine gradientTransform = Affine.identity();
+ boolean useBoundingBox = false; // FIXME not supported
+ boolean patternUseBoundingBox = false; // FIXME not supported
+
+ // it's invalid for both of these to be true
+ boolean reflect = false; // FIXME not supported
+ boolean repeat = false; // FIXME not supported
+ int[] stop_colors;
+ float[] stop_offsets;
+ float cx, cy, r, fx, fy;
+
+ public void fillTrapezoid(float tx1, float tx2, float ty1, float tx3, float tx4, float ty2, PixelBuffer buf) {
+ /*
+ Affine a = buf.a;
+ Affine inverse = a.copy().invert();
+ float slope1 = (tx3 - tx1) / (ty2 - ty1);
+ float slope2 = (tx4 - tx2) / (ty2 - ty1);
+ for(float y=ty1; y<ty2; y++) {
+ float _x1 = (y - ty1) * slope1 + tx1;
+ float _x2 = (y - ty1) * slope2 + tx2;
+ if (_x1 > _x2) { float _x0 = _x1; _x1 = _x2; _x2 = _x0; }
+
+ for(float x=_x1; x<_x2; x++) {
- // FIXME: offsets are 0..1, not 0..length(gradient)
- int i = 0; for(; i<stop_offsets.length; i++) if (distance < stop_offsets[i]) break;
-
- // FIXME: handle points beyond the bounds
- if (i < 0 || i >= stop_offsets.length) continue;
-
- // gradate from offsets[i - 1] to offsets[i]
- float percentage = ((distance - stop_offsets[i - 1]) / (stop_offsets[i] - stop_offsets[i - 1]));
-
- int a = (int)((((stop_colors[i] >> 24) & 0xff) - ((stop_colors[i - 1] >> 24) & 0xff)) * percentage) +
- ((stop_colors[i - 1] >> 24) & 0xff);
- int r = (int)((((stop_colors[i] >> 16) & 0xff) - ((stop_colors[i - 1] >> 16) & 0xff)) * percentage) +
- ((stop_colors[i - 1] >> 16) & 0xff);
- int g = (int)((((stop_colors[i] >> 8) & 0xff) - ((stop_colors[i - 1] >> 8) & 0xff)) * percentage) +
- ((stop_colors[i - 1] >> 8) & 0xff);
- int b = (int)((((stop_colors[i] >> 0) & 0xff) - ((stop_colors[i - 1] >> 0) & 0xff)) * percentage) +
- ((stop_colors[i - 1] >> 0) & 0xff);
- int argb = (a << 24) | (r << 16) | (g << 8) | b;
- buf.drawPoint((int)x, (int)Math.floor(y), argb);
- }
- }
- }
- }
-
- public static class LinearGradientPaint extends GradientPaint {
- public LinearGradientPaint(float x1, float y1, float x2, float y2, boolean reflect, boolean repeat,
- Affine gradientTransform, int[] stop_colors, float[] stop_offsets) {
- super(reflect, repeat, gradientTransform, stop_colors, stop_offsets);
- this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2;
- }
- float x1 = 0, y1 = 0, x2 = 300, y2 = 300;
- }
+ // FIXME: offsets are 0..1, not 0..length(gradient)
+ int i = 0; for(; i<stop_offsets.length; i++) if (distance < stop_offsets[i]) break;
+
+ // FIXME: handle points beyond the bounds
+ if (i < 0 || i >= stop_offsets.length) continue;
+
+ // gradate from offsets[i - 1] to offsets[i]
+ float percentage = ((distance - stop_offsets[i - 1]) / (stop_offsets[i] - stop_offsets[i - 1]));
+
+ int a = (int)((((stop_colors[i] >> 24) & 0xff) - ((stop_colors[i - 1] >> 24) & 0xff)) * percentage) +
+ ((stop_colors[i - 1] >> 24) & 0xff);
+ int r = (int)((((stop_colors[i] >> 16) & 0xff) - ((stop_colors[i - 1] >> 16) & 0xff)) * percentage) +
+ ((stop_colors[i - 1] >> 16) & 0xff);
+ int g = (int)((((stop_colors[i] >> 8) & 0xff) - ((stop_colors[i - 1] >> 8) & 0xff)) * percentage) +
+ ((stop_colors[i - 1] >> 8) & 0xff);
+ int b = (int)((((stop_colors[i] >> 0) & 0xff) - ((stop_colors[i - 1] >> 0) & 0xff)) * percentage) +
+ ((stop_colors[i - 1] >> 0) & 0xff);
+ int argb = (a << 24) | (r << 16) | (g << 8) | b;
+ buf.drawPoint((int)x, (int)Math.floor(y), argb);
+ }
+ }
+ */
+ }
+ }
+ /*
+ public static class LinearGradientPaint extends GradientPaint {
+ public LinearGradientPaint(float x1, float y1, float x2, float y2, boolean reflect, boolean repeat,
+ Affine gradientTransform, int[] stop_colors, float[] stop_offsets) {
+ super(reflect, repeat, gradientTransform, stop_colors, stop_offsets);
+ this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2;
+ }
+ float x1 = 0, y1 = 0, x2 = 300, y2 = 300;
+ }
- public static class RadialGradientPaint extends GradientPaint {
- public RadialGradientPaint(float cx, float cy, float fx, float fy, float r, boolean reflect, boolean repeat,
- Affine gradientTransform, int[] stop_colors, float[] stop_offsets) {
- super(reflect, repeat, gradientTransform, stop_colors, stop_offsets);
- this.cx = cx; this.cy = cy; this.fx = fx; this.fy = fy; this.r = r;
- }
+ public static class RadialGradientPaint extends GradientPaint {
+ public RadialGradientPaint(float cx, float cy, float fx, float fy, float r, boolean reflect, boolean repeat,
+ Affine gradientTransform, int[] stop_colors, float[] stop_offsets) {
+ super(reflect, repeat, gradientTransform, stop_colors, stop_offsets);
+ this.cx = cx; this.cy = cy; this.fx = fx; this.fy = fy; this.r = r;
+ }