Exemplo n.º 1
0
  public Raster getRaster(int x, int y, int w, int h) {
    WritableRaster rast = cm.createCompatibleWritableRaster(w, h);

    int[] buf = rast.getDataBuffer();

    int c = x * dy - y * dx - delta;
    int cx = dy;
    int cy = -w * dy - dx;
    int k = 0;

    if (cyclic) {
      for (int j = 0; j < h; j++) {
        for (int i = 0; i < w; i++) {
          buf[k++] = table[(c >> 8) & LOOKUP_MASK];
          c += cx;
        }
        c += cy;
      }
    } else {
      for (int j = 0; j < h; j++) {
        for (int i = 0; i < w; i++) {
          int index = c >> 8;
          buf[k++] = index < 0 ? c1 : index >= LOOKUP_SIZE ? c2 : table[index];
          c += cx;
        }
        c += cy;
      }
    }

    return rast;
  }
Exemplo n.º 2
0
  /**
   * Constructs a new GradientPaintcontext
   *
   * @param cm - not used
   * @param t - the fill transformation
   * @param point1 - the start fill point
   * @param color1 - color of the start point
   * @param point2 - the end fill point
   * @param color2 - color of the end point
   * @param cyclic - the indicator of cycle filling
   */
  GradientPaintContext(
      ColorModel cm,
      AffineTransform t,
      Point2D point1,
      Color color1,
      Point2D point2,
      Color color2,
      boolean cyclic) {
    this.cyclic = cyclic;
    this.cm = ColorModel.getRGBdefault();

    c1 = color1.getRGB();
    c2 = color2.getRGB();

    double px = point2.getX() - point1.getX();
    double py = point2.getY() - point1.getY();

    Point2D p = t.transform(point1, null);
    Point2D bx = new Point2D.Double(px, py);
    Point2D by = new Point2D.Double(py, -px);

    t.deltaTransform(bx, bx);
    t.deltaTransform(by, by);

    double vec = bx.getX() * by.getY() - bx.getY() * by.getX();

    if (Math.abs(vec) < ZERO) {
      dx = dy = delta = 0;
      table = new int[1];
      table[0] = c1;
    } else {
      double mult = LOOKUP_SIZE * 256 / vec;
      dx = (int) (by.getX() * mult);
      dy = (int) (by.getY() * mult);
      delta = (int) ((p.getX() * by.getY() - p.getY() * by.getX()) * mult);
      createTable();
    }
  }