public static int interpolate(int v1, int v2, float f) { return clamp((int)(v1+f*(v2-v1))); }
public int filterRGB(int x, int y, int rgb) { if ( randomNumbers.nextFloat() <= density ) { int a = rgb & 0xff000000; int r = (rgb >> 16) & 0xff; int g = (rgb >> 8) & 0xff; int b = rgb & 0xff; if (monochrome) { int n = (int)(((distribution == GAUSSIAN ? randomNumbers.nextGaussian() : 2*randomNumbers.nextFloat() - 1)) * amount); r = PixelUtils.clamp(r+n); g = PixelUtils.clamp(g+n); b = PixelUtils.clamp(b+n); } else { r = random(r); g = random(g); b = random(b); } return a | (r << 16) | (g << 8) | b; } return rgb; }
break; case ADD: r1 = clamp(r1+r2); g1 = clamp(g1+g2); b1 = clamp(b1+b2); break; case SUBTRACT: r1 = clamp(r2-r1); g1 = clamp(g2-g1); b1 = clamp(b2-b1); break; case DIFFERENCE: r1 = clamp(Math.abs(r1-r2)); g1 = clamp(Math.abs(g1-g2)); b1 = clamp(Math.abs(b1-b2)); break; case MULTIPLY: r1 = clamp(r1*r2/255); g1 = clamp(g1*g2/255); b1 = clamp(b1*b2/255); break; case DISSOLVE: break; case DST_IN: r1 = clamp((r2*a1)/255); g1 = clamp((g2*a1)/255); b1 = clamp((b2*a1)/255); a1 = clamp((a2*a1)/255);
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 nr = PixelUtils.clamp((intoR * (blueGreen*g+(255-blueGreen)*b)/255 + (255-intoR)*r)/255); int ng = PixelUtils.clamp((intoG * (redBlue*b+(255-redBlue)*r)/255 + (255-intoG)*g)/255); int nb = PixelUtils.clamp((intoB * (greenRed*r+(255-greenRed)*g)/255 + (255-intoB)*b)/255); return a | (nr << 16) | (ng << 8) | nb; }
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; r = PixelUtils.clamp((int)(r * rFactor)); g = PixelUtils.clamp((int)(g * gFactor)); b = PixelUtils.clamp((int)(b * bFactor)); return a | (r << 16) | (g << 8) | b; }
public GrayScaleLookup(int inputBlackValue, int inputWhiteValue, int outputBlackValue, int outputWhiteValue) { for (int i = 0; i < mapping.length; i++) { double multiplier = ((double) (outputWhiteValue - outputBlackValue)) / ((double) (inputWhiteValue - inputBlackValue)); double constant = (outputBlackValue) - (multiplier * inputBlackValue); mapping[i] = (short) PixelUtils.clamp((int) ((multiplier * i) + constant)); } }
public int filterRGB(int x, int y, int rgb) { if ( amount != 1 ) { int a = rgb & 0xff000000; int r = (rgb >> 16) & 0xff; int g = (rgb >> 8) & 0xff; int b = rgb & 0xff; int v = ( r + g + b )/3; // or a better brightness calculation if you prefer r = PixelUtils.clamp( (int)(v + amount * (r-v)) ); g = PixelUtils.clamp( (int)(v + amount * (g-v)) ); b = PixelUtils.clamp( (int)(v + amount * (b-v)) ); return a | (r << 16) | (g << 8) | b; } return rgb; }
public static int interpolate(int v1, int v2, float f) { return clamp((int)(v1+f*(v2-v1))); }
public int filterRGB(int x, int y, int rgb1, int rgb2) { int a1 = (rgb1 >> 24) & 0xff; int r1 = (rgb1 >> 16) & 0xff; int g1 = (rgb1 >> 8) & 0xff; int b1 = rgb1 & 0xff; int a2 = (rgb2 >> 24) & 0xff; int r2 = (rgb2 >> 16) & 0xff; int g2 = (rgb2 >> 8) & 0xff; int b2 = rgb2 & 0xff; int r = PixelUtils.clamp(r1 + r2); int g = PixelUtils.clamp(r1 + r2); int b = PixelUtils.clamp(r1 + r2); return (a1 << 24) | (r << 16) | (g << 8) | b; }
private void setupMappingsForTotallyAffected() { for (short i = 0; i < LUT_TABLE_SIZE; i++) { short r = (short) (i + cyanRed - (magentaGreen / 2) - (yellowBlue / 2)); r = PixelUtils.clamp(r); redMapping[i] = r; short g = (short) (i + magentaGreen - (cyanRed / 2) - (yellowBlue / 2)); g = PixelUtils.clamp(g); greenMapping[i] = g; short b = (short) (i + yellowBlue - (magentaGreen / 2) - (cyanRed / 2)); b = PixelUtils.clamp(b); blueMapping[i] = b; } }
public static int interpolate(int v1, int v2, float f) { return clamp((int) (v1 + f * (v2 - v1))); }
public int filterRGB(int x, int y, int rgb) { int a = (rgb >> 24) & 0xff; int r = (rgb >> 16) & 0xff; int g = (rgb >> 8) & 0xff; int b = rgb & 0xff; a = matrix[0]*a + matrix[1]*r + matrix[2]*g + matrix[3]*b + matrix[4]*255; r = matrix[5]*a + matrix[6]*r + matrix[7]*g + matrix[8]*b + matrix[9]*255; g = matrix[10]*a + matrix[11]*r + matrix[12]*g + matrix[13]*b + matrix[14]*255; b = matrix[15]*a + matrix[16]*r + matrix[17]*g + matrix[18]*b + matrix[19]*255; a = PixelUtils.clamp( a ); r = PixelUtils.clamp( r ); g = PixelUtils.clamp( g ); b = PixelUtils.clamp( b ); return (a << 24) | (r << 16) | (g << 8) | b; }
private int displace(int rgb, float amount) { int r = (rgb >> 16) & 0xff; int g = (rgb >> 8) & 0xff; int b = rgb & 0xff; r = PixelUtils.clamp(r + (int)(amount * (randomGenerator.nextFloat()-0.5))); g = PixelUtils.clamp(g + (int)(amount * (randomGenerator.nextFloat()-0.5))); b = PixelUtils.clamp(b + (int)(amount * (randomGenerator.nextFloat()-0.5))); return 0xff000000 | (r << 16) | (g << 8) | b; }
private void setupMappingsForPartiallyAffected() { float[] affectFactor = calculateAffectFactor(affect); for (short i = 0; i < LUT_TABLE_SIZE; i++) { short r = (short) (i + affectFactor[i] * (cyanRed - (magentaGreen / 2) - (yellowBlue / 2))); r = PixelUtils.clamp(r); redMapping[i] = r; short g = (short) (i + affectFactor[i] * (magentaGreen - (cyanRed / 2) - (yellowBlue / 2))); g = PixelUtils.clamp(g); greenMapping[i] = g; short b = (short) (i + affectFactor[i] * (yellowBlue - (magentaGreen / 2) - (cyanRed / 2))); b = PixelUtils.clamp(b); blueMapping[i] = b; } }
protected int[] makeTable() { int[] table = new int[256]; for (int i = 0; i < 256; i++) table[i] = PixelUtils.clamp( (int)( 255 * transferFunction( i / 255.0f ) ) ); return table; }
protected int[] makeTable() { int[] table = new int[256]; for (int i = 0; i < 256; i++) table[i] = PixelUtils.clamp( (int)( 255 * transferFunction( i / 255.0f ) ) ); return table; }
private int displacementMap(int x, int y) { return PixelUtils.clamp((int)(127 * (1+Noise.noise2(x / xScale, y / xScale)))); }
/** * Mutate the gradient. * @param amount the amount in the range zero to one */ public void mutate(float amount) { for (int i = 0; i < numKnots; i++) { int rgb = yKnots[i]; int r = ((rgb >> 16) & 0xff); int g = ((rgb >> 8) & 0xff); int b = (rgb & 0xff); r = PixelUtils.clamp( (int)(r + amount * 255 * (Math.random()-0.5)) ); g = PixelUtils.clamp( (int)(g + amount * 255 * (Math.random()-0.5)) ); b = PixelUtils.clamp( (int)(b + amount * 255 * (Math.random()-0.5)) ); yKnots[i] = 0xff000000 | (r << 16) | (g << 8) | b; knotTypes[i] = RGB|SPLINE; } sortKnots(); rebuildGradient(); }
private int displacementMap(int x, int y) { float noise = Noise.noise3(x / scale, y / scale, time); // mostly between -1 and 1 but not distributed uniformly return PixelUtils.clamp((int) (127 * (1 + noise))); }
/** * Set a knot position. * @param n the knot index * @param x the knot position */ public void setKnotPosition(int n, int x) { xKnots[n] = PixelUtils.clamp(x); sortKnots(); rebuildGradient(); }