/** * Set new knot location * @param index point index * @param p normalized point data */ public void setKnotPosition(int index, Point.Float p){ int lastIndex = curve.x.length - 1; if (index <0 || index > lastIndex) { return; } // check prev/next index - knots cannot change they index if (index > 0 && p.x < curve.x[index-1]) { p.x = curve.x[index-1]; } else if (index < lastIndex && p.x > curve.x[index+1]) { p.x = curve.x[index+1]; } curve.x[index] = ImageMath.clamp(p.x, 0, 1); curve.y[index] = ImageMath.clamp(p.y, 0, 1); isDirty = true; }
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)]; case RGB_CLAMP: return pixels[(ImageMath.clamp(y, 0, height-1) * width) + ImageMath.clamp(x, 0, width-1)] & 0x00ffffff; } } return pixels[ y*width+x ]; }
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; }
throw new IllegalArgumentException("Too few knots in spline"); x = clamp(x, 0, 1) * numSpans; span = (int)x; if (span > numKnots-4)
/** * Convert a value in the range 0..1 to an RGB color. * @param v a value in the range 0..1 * @return an RGB color */ public int getColor(float v) { return Spectrum.wavelengthToRGB(380+400*ImageMath.clamp(v, 0, 1.0f)); }
/** * Convert a value in the range 0..1 to an RGB color. * @param v a value in the range 0..1 * @return an RGB color */ public int getColor(float v) { return ImageMath.mixColors(ImageMath.clamp(v, 0, 1.0f), color1, color2); }
/** * Convert a value in the range 0..1 to an RGB color. * * @param v a value in the range 0..1 * @return an RGB color */ @Override public int getColor(float v) { return ImageMath.mixColors(ImageMath.clamp(v, 0, 1.0f), color1, color2); }
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 ]; }
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 ]; } }
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 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; 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]; if (fadeEdges) { float f2 = results[1].distance; 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]; v = ImageMath.mixColors(0.5f*f1/f2, v, v2); } else { f = 1-ImageMath.smoothStep(edgeThickness, edgeThickness+fuzziness, f1); v = ImageMath.mixColors(f, edgeColor, v); } return v; }
@Override 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); Point[] results = resultsTL.get(); float f1 = results[0].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]; if (fadeEdges) { float f2 = results[1].distance; 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]; v = ImageMath.mixColors(0.5f * f1 / f2, v, v2); } else { f = 1 - ImageMath.smoothStep(edgeThickness, edgeThickness + fuzziness, f1); v = ImageMath.mixColors(f, edgeColor, v); } return v; }
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; }
/** * Set a knot position. * @param n the knot index * @param x the knot position * @see #setKnotPosition */ public void setKnotPosition(int n, int x) { xKnots[n] = ImageMath.clamp(x, 0, 255); sortKnots(); rebuildGradient(); }
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 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; }
/** * Set a knot position. * * @param n the knot index * @param x the knot position * @see #setKnotPosition */ public void setKnotPosition(int n, int x) { xKnots[n] = ImageMath.clamp(x, 0, 255); sortKnots(); rebuildGradient(); }
protected void initialize() { initialized = true; if ( curves.length == 1 ) rTable = gTable = bTable = curves[0].makeTable(); else { rTable = new int[256]; gTable = new int[256]; bTable = new int[256]; int[] r = curves[0].makeTable(); int[] g = curves[1].makeTable(); int[] b = curves[2].makeTable(); int[] rgb = curves[3].makeTable(); for (int x = 0; x <= 255; x++) { rTable[x] = ImageMath.clamp(r[rgb[x]], 0, 255); gTable[x] = ImageMath.clamp(g[rgb[x]], 0, 255); bTable[x] = ImageMath.clamp(b[rgb[x]], 0, 255); } } }
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); }