protected void filter2(int[] inPixels, int[] outPixels, int width, int height) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int pixel = limitByte((int) (127 * (1 + PerlinNoise.noise2D(((double) x) / scale + randomX, ((double) y) / scale + randomY)))); outPixels[x + y * width] = (limitByte((int) 255) << 24) | (limitByte((int) pixel) << 16) | (limitByte((int) pixel) << 8) | (limitByte((int) pixel)); } } }
private int linear(int from, int to, double d) { int c = 0; for (int i = 0; i < 4; i++) { c += linear(from, to, i * 8, d); } return c; }
public WobbleRippleFilterFactory() { wobble = new WobbleImageOp(); }
protected void filter(int[] inPixels, int[] outPixels, int width, int height) { if (!initialized) { init(); initialized = true; } double[] t = new double[2]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { transform(x, y, t); int pixel = getPixelBilinear(inPixels, t[0], t[1], width, height, getEdgeMode()); outPixels[x + y * width] = pixel; } } }
public static double noise2D(double x, double y) { double fx = Math.floor(x); double fy = Math.floor(y); double u, v; int ix = ((int) fx) & 0xFF; int iy = ((int) fy) & 0xFF; x -= fx; y -= fy; int i = p[ix]; int j = p[ix + 1]; u = fade(x); v = fade(y); double grad1 = grad(p[i + iy], x, y); double grad2 = grad(p[j + iy], x - 1, y); double grad3 = grad(p[i + iy + 1], x, y - 1); double grad4 = grad(p[j + iy + 1], x - 1, y - 1); return lerp(v, lerp(u, grad1, grad2), lerp(u, grad3, grad4)); }
protected int getPixelBilinear(int pixels[], double x, double y, int width, int height, int edgeMode) { int xi = (int) Math.floor(x); int yi = (int) Math.floor(y); double xd = x - xi; double yd = y - yi; int nw = getPixel(pixels, xi, yi, width, height, edgeMode); int ne = getPixel(pixels, xi + 1, yi, width, height, edgeMode); int sw = getPixel(pixels, xi, yi + 1, width, height, edgeMode); int se = getPixel(pixels, xi + 1, yi + 1, width, height, edgeMode); return bilinear(nw, ne, sw, se, xd, yd); }
protected void filter(int[] inPixels, int[] outPixels, int width, int height) { long time1 = System.currentTimeMillis(); int matrixWidth = matrix[0].length; int matrixHeight = matrix.length; int mattrixLeft = -matrixWidth / 2; int matrixTop = -matrixHeight / 2; for (int y = 0; y < height; y++) { int ytop = y + matrixTop; int ybottom = y + matrixTop + matrixHeight; for (int x = 0; x < width; x++) { float[] sum = {0.5f, 0.5f, 0.5f, 0.5f}; int xleft = x + mattrixLeft; int xright = x + mattrixLeft + matrixWidth; int matrixY = 0; for (int my = ytop; my < ybottom; my++, matrixY++) { int matrixX = 0; for (int mx = xleft; mx < xright; mx++, matrixX++) { int pixel = getPixel(inPixels, mx, my, width, height, EDGE_ZERO); float m = matrix[matrixY][matrixX]; sum[0] += m * ((pixel >> 24) & 0xff); sum[1] += m * ((pixel >> 16) & 0xff); sum[2] += m * ((pixel >> 8) & 0xff); sum[3] += m * (pixel & 0xff); } } outPixels[x + y * width] = (limitByte((int) sum[0]) << 24) | (limitByte((int) sum[1]) << 16) | (limitByte((int) sum[2]) << 8) | (limitByte((int) sum[3])); } } }
public BufferedImage filter(BufferedImage src, BufferedImage dest) { if (dest == null) { dest = createCompatibleDestImage(src, null); } int width = src.getWidth(); int height = src.getHeight(); int[] inPixels = new int[width * height]; int[] outPixels = new int[width * height]; src.getRaster().getDataElements(0, 0, width, height, inPixels); filter(inPixels, outPixels, width, height); dest.getRaster().setDataElements(0, 0, width, height, outPixels); return dest; }
public AbstractTransformImageOp() { setEdgeMode(EDGE_CLAMP); }
public DoubleRippleFilterFactory() { ripple = new DoubleRippleImageOp(); }
public RippleFilterFactory() { ripple = new RippleImageOp(); }
public void setStrokeMax(float strokeMax) { curves.setStrokeMax(strokeMax); }
protected int limitByte(int v) { return limit(v, 0, 255); }
public void setStrokeMin(float strokeMin) { curves.setStrokeMin(strokeMin); }
private double catmullRomSpline(double x0, double x1, double x2, double x3, double t) { double a1 = (x2 - x0) / 2; double a2 = (x3 - x1) / 2; return hermiteSpline(x1, a1, x2, a2, t); }
private int linear(int from, int to, double d) { int c = 0; for (int i = 0; i < 4; i++) { c += linear(from, to, i * 8, d); } return c; }
protected void filter2(int[] inPixels, int[] outPixels, int width, int height) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int pixel = limitByte((int) (127 * (1 + PerlinNoise.noise2D(((double) x) / scale + randomX, ((double) y) / scale + randomY)))); outPixels[x + y * width] = (limitByte((int) 255) << 24) | (limitByte((int) pixel) << 16) | (limitByte((int) pixel) << 8) | (limitByte((int) pixel)); } } }