public static int combinePixels(int rgb1, int rgb2, int op) { return combinePixels(rgb1, rgb2, op, 0xff); }
public static int interpolate(int v1, int v2, float f) { return clamp((int)(v1+f*(v2-v1))); }
public void blur( int[] in, int[] out, int width, int radius ) { int widthMinus1 = width-1; int r2 = 2*radius+1; int tr = 0, tg = 0, tb = 0; for ( int i = -radius; i <= radius; i++ ) { int rgb = in[mod(i, width)]; tr += (rgb >> 16) & 0xff; tg += (rgb >> 8) & 0xff; tb += rgb & 0xff; } for ( int x = 0; x < width; x++ ) { out[x] = 0xff000000 | ((tr/r2) << 16) | ((tg/r2) << 8) | (tb/r2); int i1 = x+radius+1; if ( i1 > widthMinus1 ) i1 = mod( i1, width ); int i2 = x-radius; if ( i2 < 0 ) i2 = mod( i2, width ); int rgb1 = in[i1]; int rgb2 = in[i2]; tr += ((rgb1 & 0xff0000)-(rgb2 & 0xff0000)) >> 16; tg += ((rgb1 & 0xff00)-(rgb2 & 0xff00)) >> 8; tb += (rgb1 & 0xff)-(rgb2 & 0xff); } }
dst = createCompatibleDestImage( src, null ); inPixels[x] = a | (clamp(tr+n) << 16) | (clamp(tg+n) << 8) | clamp(tb+n); } else { inPixels[x] = a | (random(tr) << 16) | (random(tg) << 8) | random(tb); blur( inPixels, outPixels, width, radius ); setRGB( dst, 0, y, width, 1, outPixels ); } else setRGB( dst, 0, y, width, 1, inPixels );
public BufferedImage filter( BufferedImage src, BufferedImage dst ) { int width = src.getWidth(); int height = src.getHeight(); int type = src.getType(); WritableRaster srcRaster = src.getRaster(); if ( dst == null ) dst = createCompatibleDestImage( src, null ); WritableRaster dstRaster = dst.getRaster(); setDimensions( width, height); int[] inPixels = new int[width]; for ( int y = 0; y < height; y++ ) { // We try to avoid calling getRGB on images as it causes them to become unmanaged, causing horrible performance problems. if ( type == BufferedImage.TYPE_INT_ARGB ) { srcRaster.getDataElements( 0, y, width, 1, inPixels ); for ( int x = 0; x < width; x++ ) inPixels[x] = filterRGB( x, y, inPixels[x] ); dstRaster.setDataElements( 0, y, width, 1, inPixels ); } else { src.getRGB( 0, y, width, 1, inPixels, 0, width ); for ( int x = 0; x < width; x++ ) inPixels[x] = filterRGB( x, y, inPixels[x] ); dst.setRGB( 0, y, width, 1, inPixels, 0, width ); } } return dst; }
public BufferedImage filter( BufferedImage src, BufferedImage dst ) { dst = new GaussianFilter( (int)radius ).filter( src, null ); lowerThreshold3 = 255*3*(threshold - softness*0.5f); upperThreshold3 = 255*3*(threshold + softness*0.5f); return super.filter(dst, dst); }
@Override public void paint(Canvas canvas, Look look) { Colors colors = look.colors(); BrushedMetalFilter filter = new BrushedMetalFilter(); filter.setColor(colors.background().getRGB()); filter.setRadius(10); filter.setAmount(0.15f); filter.setMonochrome(true); filter.setShine(0.2f); canvas.applyFilter(filter); }
/** * 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(); }
GaussianFilter filter = new GaussianFilter(size); g2d.dispose(); imgBlur = filter.filter(imgBlur, null);
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; }
public int filterRGB(int x, int y, int rgb) { int v = PixelUtils.brightness( rgb ); float f = ImageMath.smoothStep( lowerThreshold, upperThreshold, v ); return (rgb & 0xff000000) | (ImageMath.mixColors( f, black, white ) & 0xffffff); }
/** * 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(); }
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; }
@Override public void paint(Canvas canvas, Look look) { Colors colors = look.colors(); canvas.paintGradient(colors.background()); NoiseFilter filter = new NoiseFilter(); filter.setMonochrome(true); filter.setDensity(0.5f); filter.setAmount(13); canvas.applyFilter(filter); }
public BufferedImage filter( BufferedImage src, BufferedImage dst ) { if (!initialized) initialize(); return super.filter( src, dst ); }
public void morph(int[] srcPixels, int[] destPixels, int[] outPixels, WarpGrid srcGrid, WarpGrid destGrid, int width, int height, float t) { WarpGrid newGrid = new WarpGrid(srcGrid.rows, srcGrid.cols, width, height); srcGrid.lerp(t, destGrid, newGrid); srcGrid.warp(srcPixels, width, height, srcGrid, newGrid, outPixels); int[] destPixels2 = new int[width * height]; destGrid.warp(destPixels, width, height, destGrid, newGrid, destPixels2); crossDissolve(outPixels, destPixels2, width, height, t); }
/** * 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)); }
public BufferedImage filter( BufferedImage src, BufferedImage dst ) { setColorSource( LightFilter.COLORS_CONSTANT ); dst = super.filter( src, dst ); TransferFilter tf = new TransferFilter() { protected float transferFunction( float v ) { v += amount * (float)Math.sin( v * 2 * Math.PI ); return 1 - (float)Math.exp(-v * exposure); } }; return tf.filter( dst, dst ); }
public static int combinePixels(int rgb1, int rgb2, int op, int extraAlpha, int channelMask) { return (rgb2 & ~channelMask) | combinePixels(rgb1 & channelMask, rgb2, op, extraAlpha); }
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);