Esempio n. 1
0
 public int getPixel(int x, int y, int[] inPixels, int width, int height) {
   float nx = m00 * x + m01 * y;
   float ny = m10 * x + m11 * y;
   nx /= scale;
   ny /= scale * stretch;
   nx += 1000;
   ny += 1000; // Reduce artifacts around 0,0
   float f = turbulence == 1.0f ? evaluate(nx, ny) : turbulence2(nx, ny, turbulence);
   // Normalize to 0..1
   //		f = (f-min)/(max-min);
   f *= 2;
   f *= amount;
   int a = 0xff000000;
   int v;
   if (colormap != null) {
     v = colormap.getColor(f);
     if (useColor) {
       int srcx = ImageMath.clamp((int) ((results[0].x - 1000) * scale), 0, width - 1);
       int srcy = ImageMath.clamp((int) ((results[0].y - 1000) * scale), 0, height - 1);
       v = inPixels[srcy * width + srcx];
       f =
           (results[1].distance - results[0].distance)
               / (results[1].distance + results[0].distance);
       f = ImageMath.smoothStep(coefficients[1], coefficients[0], f);
       v = ImageMath.mixColors(f, 0xff000000, v);
     }
     return v;
   } else {
     v = PixelUtils.clamp((int) (f * 255));
     int r = v << 16;
     int g = v << 8;
     int b = v;
     return a | r | g | b;
   }
 }
Esempio n. 2
0
  protected int[] filterPixels(int width, int height, int[] inPixels, Rectangle transformedSpace) {
    int[] outPixels = new int[width * height];

    randomGenerator.setSeed(seed);

    int w1 = width - 1;
    int h1 = height - 1;
    putPixel(0, 0, randomRGB(inPixels, 0, 0), outPixels, width);
    putPixel(w1, 0, randomRGB(inPixels, w1, 0), outPixels, width);
    putPixel(0, h1, randomRGB(inPixels, 0, h1), outPixels, width);
    putPixel(w1, h1, randomRGB(inPixels, w1, h1), outPixels, width);
    putPixel(w1 / 2, h1 / 2, randomRGB(inPixels, w1 / 2, h1 / 2), outPixels, width);
    putPixel(0, h1 / 2, randomRGB(inPixels, 0, h1 / 2), outPixels, width);
    putPixel(w1, h1 / 2, randomRGB(inPixels, w1, h1 / 2), outPixels, width);
    putPixel(w1 / 2, 0, randomRGB(inPixels, w1 / 2, 0), outPixels, width);
    putPixel(w1 / 2, h1, randomRGB(inPixels, w1 / 2, h1), outPixels, width);

    int depth = 1;
    while (doPixel(0, 0, width - 1, height - 1, outPixels, width, depth, 0)) depth++;

    if (useColormap && colormap != null) {
      int index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          outPixels[index] = colormap.getColor((outPixels[index] & 0xff) / 255.0f);
          index++;
        }
      }
    }
    return outPixels;
  }
Esempio n. 3
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;
  }
Esempio n. 4
0
  protected int[] filterPixels(int width, int height, int[] inPixels, Rectangle transformedSpace) {
    int[] outPixels = new int[width * height];

    int i = 0;
    int max = 0;

    float x = 0.1f;
    float y = 0.3f;

    for (int n = 0; n < 20; n++) {
      float mx = ImageMath.PI * x;
      float my = ImageMath.PI * y;
      float smx2 = (float) Math.sin(2 * mx);
      float smy2 = (float) Math.sin(2 * my);
      float x1 =
          (float)
              (a * smx2
                  + b * smx2 * Math.cos(2 * my)
                  + c * Math.sin(4 * mx)
                  + d * Math.sin(6 * mx) * Math.cos(4 * my)
                  + k * x);
      x1 = x1 >= 0 ? x1 - (int) x1 : x1 - (int) x1 + 1;

      float y1 =
          (float)
              (a * smy2
                  + b * smy2 * Math.cos(2 * mx)
                  + c * Math.sin(4 * my)
                  + d * Math.sin(6 * my) * Math.cos(4 * mx)
                  + k * y);
      y1 = y1 >= 0 ? y1 - (int) y1 : y1 - (int) y1 + 1;
      x = x1;
      y = y1;
    }

    for (int n = 0; n < iterations; n++) {
      float mx = ImageMath.PI * x;
      float my = ImageMath.PI * y;
      float x1 =
          (float)
              (a * Math.sin(2 * mx)
                  + b * Math.sin(2 * mx) * Math.cos(2 * my)
                  + c * Math.sin(4 * mx)
                  + d * Math.sin(6 * mx) * Math.cos(4 * my)
                  + k * x);
      x1 = x1 >= 0 ? x1 - (int) x1 : x1 - (int) x1 + 1;

      float y1 =
          (float)
              (a * Math.sin(2 * my)
                  + b * Math.sin(2 * my) * Math.cos(2 * mx)
                  + c * Math.sin(4 * my)
                  + d * Math.sin(6 * my) * Math.cos(4 * mx)
                  + k * y);
      y1 = y1 >= 0 ? y1 - (int) y1 : y1 - (int) y1 + 1;
      x = x1;
      y = y1;
      int ix = (int) (width * x);
      int iy = (int) (height * y);
      if (ix >= 0 && ix < width && iy >= 0 && iy < height) {
        int t = outPixels[width * iy + ix]++;
        if (t > max) max = t;
      }
    }

    if (colormap != null) {
      int index = 0;
      for (y = 0; y < height; y++) {
        for (x = 0; x < width; x++) {
          outPixels[index] = colormap.getColor(outPixels[index] / (float) max);
          index++;
        }
      }
    }
    return outPixels;
  }