Exemplo n.º 1
0
 private void singleGradient(int[] pixels, int w, int h, float rowrel, float dx, float dy) {
   int off = 0;
   for (int y = 0; y < h; y++) {
     float colrel = rowrel;
     int j = w;
     int rgb;
     if (colrel <= 0.0) {
       rgb = colormap.getColor(0);
       do {
         pixels[off] = PixelUtils.combinePixels(rgb, pixels[off], paintMode);
         off++;
         colrel += dx;
       } while (--j > 0 && colrel <= 0.0);
     }
     while (colrel < 1.0 && --j >= 0) {
       if (type == BILINEAR) rgb = colormap.getColor(map(ImageMath.triangle(colrel)));
       else rgb = colormap.getColor(map(colrel));
       pixels[off] = PixelUtils.combinePixels(rgb, pixels[off], paintMode);
       off++;
       colrel += dx;
     }
     if (j > 0) {
       if (type == BILINEAR) rgb = colormap.getColor(0.0f);
       else rgb = colormap.getColor(1.0f);
       do {
         pixels[off] = PixelUtils.combinePixels(rgb, pixels[off], paintMode);
         off++;
       } while (--j > 0);
     }
     rowrel += dy;
   }
 }
Exemplo n.º 2
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    if (dst == null) dst = createCompatibleDestImage(src, null);

    int width = src.getWidth();
    int height = src.getHeight();
    int numScratches = (int) (density * width * height / 100);
    ArrayList<Line2D> lines = new ArrayList<Line2D>();
    {
      float l = length * width;
      Random random = new Random(seed);
      Graphics2D g = dst.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(new Color(color));
      g.setStroke(new BasicStroke(this.width));
      for (int i = 0; i < numScratches; i++) {
        float x = width * random.nextFloat();
        float y = height * random.nextFloat();
        float a = angle + ImageMath.TWO_PI * (angleVariation * (random.nextFloat() - 0.5f));
        float s = (float) Math.sin(a) * l;
        float c = (float) Math.cos(a) * l;
        float x1 = x - c;
        float y1 = y - s;
        float x2 = x + c;
        float y2 = y + s;
        g.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
        lines.add(new Line2D.Float(x1, y1, x2, y2));
      }
      g.dispose();
    }

    if (false) {
      //		int[] inPixels = getRGB( src, 0, 0, width, height, null );
      int[] inPixels = new int[width * height];
      int index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float sx = x, sy = y;
          for (int i = 0; i < numScratches; i++) {
            Line2D.Float l = (Line2D.Float) lines.get(i);
            float dot = (l.x2 - l.x1) * (sx - l.x1) + (l.y2 - l.y1) * (sy - l.y1);
            if (dot > 0) inPixels[index] |= (1 << i);
          }
          index++;
        }
      }

      Colormap colormap = new LinearColormap();
      index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float f = (float) (inPixels[index] & 0x7fffffff) / 0x7fffffff;
          inPixels[index] = colormap.getColor(f);
          index++;
        }
      }
      setRGB(dst, 0, 0, width, height, inPixels);
    }
    return dst;
  }
Exemplo n.º 3
0
 private void repeatGradient(int[] pixels, int w, int h, float rowrel, float dx, float dy) {
   int off = 0;
   for (int y = 0; y < h; y++) {
     float colrel = rowrel;
     int j = w;
     int rgb;
     while (--j >= 0) {
       if (type == BILINEAR) rgb = colormap.getColor(map(ImageMath.triangle(colrel)));
       else rgb = colormap.getColor(map(ImageMath.mod(colrel, 1.0f)));
       pixels[off] = PixelUtils.combinePixels(rgb, pixels[off], paintMode);
       off++;
       colrel += dx;
     }
     rowrel += dy;
   }
 }
Exemplo n.º 4
0
 private void conicalGradient(int[] pixels, int y, int w, int h) {
   int off = 0;
   float angle0 = (float) Math.atan2(p2.x - p1.x, p2.y - p1.y);
   for (int x = 0; x < w; x++) {
     float angle = (float) (Math.atan2(x - p1.x, y - p1.y) - angle0) / (ImageMath.TWO_PI);
     angle += 1.0f;
     angle %= 1.0f;
     if (type == BICONICAL) angle = ImageMath.triangle(angle);
     int rgb = colormap.getColor(map(angle));
     pixels[off] = PixelUtils.combinePixels(rgb, pixels[off], paintMode);
     off++;
   }
 }
Exemplo n.º 5
0
 private void squareGradient(int[] pixels, int y, int w, int h) {
   int off = 0;
   float radius = Math.max(Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y));
   for (int x = 0; x < w; x++) {
     float distance = Math.max(Math.abs(x - p1.x), Math.abs(y - p1.y));
     float ratio = distance / radius;
     if (repeat) ratio = ratio % 2;
     else if (ratio > 1.0) ratio = 1.0f;
     int rgb = colormap.getColor(map(ratio));
     pixels[off] = PixelUtils.combinePixels(rgb, pixels[off], paintMode);
     off++;
   }
 }