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 = evaluate(nx, ny); float f1 = results[0].distance; float f2 = results[1].distance; 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); int v = inPixels[srcy * width + srcx]; f = (f2 - f1) / edgeThickness; f = ImageMath.smoothStep(0, edgeThickness, f); if (fadeEdges) { srcx = ImageMath.clamp((int)((results[1].x-1000)*scale), 0, width-1); srcy = ImageMath.clamp((int)((results[1].y-1000)*scale), 0, height-1); int v2 = inPixels[srcy * width + srcx]; v2 = ImageMath.mixColors(0.5f, v2, v); v = ImageMath.mixColors(f, v2, v); } else v = ImageMath.mixColors(f, edgeColor, v); return v; }
private float calcSat(float mixFactor) { float s = lerp(mixFactor, sat, otherSat) + extraSat; if (s > 1.0f) { s = 1.0f; } else if (s < 0.0f) { s = 0.0f; } return s; }
/** * The triangle function. Returns a repeating triangle shape in the range 0..1 with wavelength 1.0 * @param x the input parameter * @return the output value */ public static float triangle(float x) { float r = mod(x, 1.0f); return 2.0f*(r < 0.5 ? r : 1-r); }
public int filterRGB(int x, int y, int rgb) { float nx = (m00*x + m01*y) / xScale; float ny = (m10*x + m11*y) / yScale; float f = ((int)(nx+100000) % 2 != (int)(ny+100000) % 2) ? 1.0f : 0.0f; if (fuzziness != 0) { float fuzz = (fuzziness/100.0f); float fx = ImageMath.smoothPulse(0, fuzz, 1-fuzz, 1, ImageMath.mod(nx, 1)); float fy = ImageMath.smoothPulse(0, fuzz, 1-fuzz, 1, ImageMath.mod(ny, 1)); f *= fx*fy; } return ImageMath.mixColors(f, foreground, background); }
public int filterRGB(int x, int y, int rgb) { int a = rgb & 0xff000000; int r = (rgb >> 16) & 0xff; int g = (rgb >> 8) & 0xff; int b = rgb & 0xff; int l = r + g + b; float f = ImageMath.smoothStep(lowerThreshold3, upperThreshold3, l); return ImageMath.mixColors(f, black, white); }
public int filterRGB(int x, int y, int rgb) { float dx = x-icentreX; float dy = y-icentreY; float distance = (float)Math.sqrt(dx*dx+dy*dy); float a = (float)Math.exp(-distance*distance*gauss)*mix + (float)Math.exp(-distance*linear)*(1-mix); float ring; a *= baseAmount; if (distance > radius + ringWidth) a = ImageMath.lerp((distance - (radius + ringWidth))/falloff, a, 0); if (distance < radius - ringWidth || distance > radius + ringWidth) ring = 0; else { ring = Math.abs(distance-radius)/ringWidth; ring = 1 - ring*ring*(3 - 2*ring); ring *= ringAmount; } a += ring; float angle = (float)Math.atan2(dx, dy)+ImageMath.PI; angle = (ImageMath.mod(angle/ImageMath.PI*17 + 1.0f + Noise.noise1(angle*10), 1.0f) - 0.5f)*2; angle = Math.abs(angle); angle = (float)Math.pow(angle, 5.0); float b = rayAmount * angle / (1 + distance*0.1f); a += b; a = ImageMath.clamp(a, 0, 1); return ImageMath.mixColors(a, rgb, color); }
public int filterRGB(int x, int y, int rgb) { float dx = x-centreX; float dy = y-centreY; float distance = dx*dx+dy*dy; float angle = (float)Math.atan2(dy, dx); float d = (angle+ImageMath.PI) / (ImageMath.TWO_PI) * rays; int i = (int)d; float f = d - i; if (radius != 0) { float length = ImageMath.lerp(f, rayLengths[i % rays], rayLengths[(i+1) % rays]); float g = length*length / (distance+0.0001f); g = (float)Math.pow(g, (100-amount) / 50.0); f -= 0.5f; // f *= amount/50.0f; f = 1 - f*f; f *= g; } f = ImageMath.clamp(f, 0, 1); return ImageMath.mixColors(f, rgb, color); }
public BufferedImage filter( BufferedImage src, BufferedImage dst ) { int width = src.getWidth(); int height = src.getHeight(); if ( dst == null ) dst = createCompatibleDestImage( src, null ); int[] inPixels = new int[width*height]; int[] outPixels = new int[width*height]; getRGB( src, 0, 0, width, height, inPixels ); if ( premultiplyAlpha ) ImageMath.premultiply( inPixels, 0, inPixels.length ); convolve(kernel, inPixels, outPixels, width, height, alpha, edgeAction); if ( premultiplyAlpha ) ImageMath.unpremultiply( outPixels, 0, outPixels.length ); setRGB( dst, 0, 0, width, height, outPixels ); return dst; }
final private int getPixel( int[] pixels, int x, int y, int width, int height ) { if (x < 0 || x >= width || y < 0 || y >= height) { switch (edgeAction) { case ZERO: default: return 0; case WRAP: return pixels[(ImageMath.mod(y, height) * width) + ImageMath.mod(x, width)]; case CLAMP: return pixels[(ImageMath.clamp(y, 0, height-1) * width) + ImageMath.clamp(x, 0, width-1)]; } } return pixels[ y*width+x ]; }
private float map(float v) { if (repeat) v = v > 1.0 ? 2.0f-v : v; switch (interpolation) { case INT_CIRCLE_UP: v = ImageMath.circleUp(ImageMath.clamp(v, 0.0f, 1.0f)); break; case INT_CIRCLE_DOWN: v = ImageMath.circleDown(ImageMath.clamp(v, 0.0f, 1.0f)); break; case INT_SMOOTH: v = ImageMath.smoothStep(0, 1, v); break; } return v; }
case SPLINE: t = ImageMath.smoothStep(0.15f, 0.85f, t); break; case CIRCLE_UP: map[j] = ImageMath.mixColors(t, rgb1, rgb2); break; case HUE_CW: hsb1[0] += 1.0f; float h = ImageMath.lerp(t, hsb1[0], hsb2[0]) % (ImageMath.TWO_PI); float s = ImageMath.lerp(t, hsb1[1], hsb2[1]); float b = ImageMath.lerp(t, hsb1[2], hsb2[2]); map[j] = 0xff000000 | Color.HSBtoRGB((float)h, (float)s, (float)b);//FIXME-alpha break;
ImageMath.premultiply( inPixels, 0, inPixels.length ); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { newX = ImageMath.mod( newX, width ); else break; newY = ImageMath.mod( newY, height ); else break; ImageMath.unpremultiply( outPixels, 0, inPixels.length );
public float evaluate(float x, float y) { float v = original.evaluate( x, y ); switch ( bumpShape ) { case 1: // v = v > 0.5f ? 0.5f : v; v *= ImageMath.smoothStep( 0.45f, 0.55f, v ); break; case 2: v = v < 0.5f ? 0.5f : v; break; case 3: v = ImageMath.triangle( v ); break; case 4: v = ImageMath.circleDown( v ); break; case 5: v = ImageMath.gain( v, 0.75f ); break; } return v; } };
int x = (int)(255 * ImageMath.splineClamped( f, nx.length, nx ) + 0.5f); int y = (int)(255 * ImageMath.spline( f, nx.length, ny ) + 0.5f); x = ImageMath.clamp( x, 0, 255 ); y = ImageMath.clamp( y, 0, 255 ); table[x] = y;
public int filterRGB(int x, int y, int rgb) { if ((x & 1) == (y & 1)) return rgb; return ImageMath.mixColors(0.25f, 0xff999999, rgb); }
private int getEnvironmentMapP(Vector3f normal, int[] inPixels, int width, int height) { if (environmentMap != null) { float x = 0.5f * (1 + normal.x); float y = 0.5f * (1 + normal.y); x = ImageMath.clamp(x * envWidth, 0, envWidth-1); y = ImageMath.clamp(y * envHeight, 0, envHeight-1); int ix = (int)x; int iy = (int)y; float xWeight = x-ix; float yWeight = y-iy; int i = envWidth*iy + ix; int dx = ix == envWidth-1 ? 0 : 1; int dy = iy == envHeight-1 ? 0 : envWidth; return ImageMath.bilinearInterpolate( xWeight, yWeight, envPixels[i], envPixels[i+dx], envPixels[i+dy], envPixels[i+dx+dy] ); } return 0; }
protected int[] makeTable() { int numKnots = x.length; float[] nx = new float[numKnots+2]; float[] ny = new float[numKnots+2]; System.arraycopy( x, 0, nx, 1, numKnots); System.arraycopy( y, 0, ny, 1, numKnots); nx[0] = nx[1]; ny[0] = ny[1]; nx[numKnots+1] = nx[numKnots]; ny[numKnots+1] = ny[numKnots]; int[] table = new int[256]; for (int i = 0; i < 1024; i++) { float f = i/1024.0f; int x = (int)(255 * ImageMath.spline( f, nx.length, nx ) + 0.5f); int y = (int)(255 * ImageMath.spline( f, nx.length, ny ) + 0.5f); x = ImageMath.clamp( x, 0, 255 ); y = ImageMath.clamp( y, 0, 255 ); table[x] = y; } return table; } }
public int filterRGB(int x, int y, int rgb) { float nx = m00*x + m01*y; float ny = m10*x + m11*y; if (sides == 2) nx = (float)Math.sqrt(nx*nx + ny*ny); else if (sides == 3) nx = ImageMath.mod(nx, 16); else if (sides == 4) nx = symmetry(nx, 16); int alpha = (int)(ImageMath.smoothStep(fadeStart, fadeStart+fadeWidth, nx) * 255); if (invert) alpha = 255-alpha; return (alpha << 24) | (rgb & 0x00ffffff); }