public BufferedImage filter(BufferedImage pSource, BufferedImage pDestination) { if (pSource == null) { throw new NullPointerException("source image is null"); } if (pSource == pDestination) { throw new IllegalArgumentException("source image cannot be the same as the destination image"); } int borderX = kernel.getWidth() / 2; int borderY = kernel.getHeight() / 2; BufferedImage original = addBorder(pSource, borderX, borderY); // Workaround for what seems to be a Java2D bug: // ConvolveOp needs explicit destination image type for some "uncommon" // image types. However, TYPE_3BYTE_BGR is what javax.imageio.ImageIO // normally returns for color JPEGs... :-/ BufferedImage destination = pDestination; if (original.getType() == BufferedImage.TYPE_3BYTE_BGR) { destination = ImageUtil.createBuffered( pSource.getWidth(), pSource.getHeight(), pSource.getType(), pSource.getColorModel().getTransparency(), null ); } // Do the filtering (if destination is null, a new image will be created) destination = convolve.filter(original, destination); if (pSource != original) { // Remove the border destination = destination.getSubimage(borderX, borderY, pSource.getWidth(), pSource.getHeight()); } return destination; }
Kernel vertical = new Kernel(horizontal.getHeight(), horizontal.getWidth(), horizontal.getKernelData(null)); BufferedImage temp = addBorder(pOriginal, horizontal.getWidth() / 2, vertical.getHeight() / 2, EDGE_REFLECT); horizontal.getWidth() / 2, vertical.getHeight() / 2, pOriginal.getWidth(), pOriginal.getHeight() );
public BufferedImage filter(BufferedImage pSource, BufferedImage pDestination) { if (pSource == null) { throw new NullPointerException("source image is null"); } if (pSource == pDestination) { throw new IllegalArgumentException("source image cannot be the same as the destination image"); } int borderX = mKernel.getWidth() / 2; int borderY = mKernel.getHeight() / 2; BufferedImage original = addBorder(pSource, borderX, borderY); // Workaround for what seems to be a Java2D bug: // ConvolveOp needs explicit destination image type for some "uncommon" // image types. However, TYPE_3BYTE_BGR is what javax.imageio.ImageIO // normally returns for color JPEGs... :-/ BufferedImage destination = pDestination; if (original.getType() == BufferedImage.TYPE_3BYTE_BGR) { destination = ImageUtil.createBuffered( pSource.getWidth(), pSource.getHeight(), pSource.getType(), pSource.getColorModel().getTransparency(), null ); } // Do the filtering (if destination is null, a new image will be created) destination = mConvolve.filter(original, destination); if (pSource != original) { // Remove the border destination = destination.getSubimage(borderX, borderY, pSource.getWidth(), pSource.getHeight()); } return destination; }
public BufferedImage filter(BufferedImage pSource, BufferedImage pDestination) { if (pSource == null) { throw new NullPointerException("source image is null"); } if (pSource == pDestination) { throw new IllegalArgumentException("source image cannot be the same as the destination image"); } int borderX = kernel.getWidth() / 2; int borderY = kernel.getHeight() / 2; BufferedImage original = addBorder(pSource, borderX, borderY); // Workaround for what seems to be a Java2D bug: // ConvolveOp needs explicit destination image type for some "uncommon" // image types. However, TYPE_3BYTE_BGR is what javax.imageio.ImageIO // normally returns for color JPEGs... :-/ BufferedImage destination = pDestination; if (original.getType() == BufferedImage.TYPE_3BYTE_BGR) { destination = ImageUtil.createBuffered( pSource.getWidth(), pSource.getHeight(), pSource.getType(), pSource.getColorModel().getTransparency(), null ); } // Do the filtering (if destination is null, a new image will be created) destination = convolve.filter(original, destination); if (pSource != original) { // Remove the border destination = destination.getSubimage(borderX, borderY, pSource.getWidth(), pSource.getHeight()); } return destination; }
int cols = kernel.getWidth(); int cols2 = cols / 2;
/** * Creates a convolve widget with a specified ColvolveOp. * @param scene the scene * @param convolveOp the convolve operation */ public ConvolveWidget (Scene scene, ConvolveOp convolveOp) { super (scene); this.convolveOp = convolveOp; Kernel kernel = convolveOp.getKernel (); setBorder (BorderFactory.createEmptyBorder (kernel.getWidth (), kernel.getHeight ())); }
/** * Creates a convolve widget with a specified ColvolveOp. * @param scene the scene * @param convolveOp the convolve operation */ public ConvolveWidget (Scene scene, ConvolveOp convolveOp) { super (scene); this.convolveOp = convolveOp; Kernel kernel = convolveOp.getKernel (); setBorder (BorderFactory.createEmptyBorder (kernel.getWidth (), kernel.getHeight ())); }
public static void convolve(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) { if (kernel.getHeight() == 1) convolveH(kernel, inPixels, outPixels, width, height, alpha, edgeAction); else if (kernel.getWidth() == 1) convolveV(kernel, inPixels, outPixels, width, height, alpha, edgeAction); else convolveHV(kernel, inPixels, outPixels, width, height, alpha, edgeAction); }
Kernel vertical = new Kernel(horizontal.getHeight(), horizontal.getWidth(), horizontal.getKernelData(null)); BufferedImage temp = addBorder(pOriginal, horizontal.getWidth() / 2, vertical.getHeight() / 2, EDGE_REFLECT); horizontal.getWidth() / 2, vertical.getHeight() / 2, pOriginal.getWidth(), pOriginal.getHeight() );
Kernel vertical = new Kernel(horizontal.getHeight(), horizontal.getWidth(), horizontal.getKernelData(null)); BufferedImage temp = addBorder(pOriginal, horizontal.getWidth() / 2, vertical.getHeight() / 2, EDGE_REFLECT); horizontal.getWidth() / 2, vertical.getHeight() / 2, pOriginal.getWidth(), pOriginal.getHeight() );
/** * Convolve a block of pixels. * @param kernel the kernel * @param inPixels the input pixels * @param outPixels the output pixels * @param width the width * @param height the height * @param alpha include alpha channel * @param edgeAction what to do at the edges */ public static void convolve(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) { if (kernel.getHeight() == 1) convolveH(kernel, inPixels, outPixels, width, height, alpha, edgeAction); else if (kernel.getWidth() == 1) convolveV(kernel, inPixels, outPixels, width, height, alpha, edgeAction); else convolveHV(kernel, inPixels, outPixels, width, height, alpha, edgeAction); }
/** * Convolve a block of pixels. * @param kernel the kernel * @param inPixels the input pixels * @param outPixels the output pixels * @param width the width * @param height the height * @param alpha include alpha channel * @param edgeAction what to do at the edges */ public static void convolve(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) { if (kernel.getHeight() == 1) convolveH(kernel, inPixels, outPixels, width, height, alpha, edgeAction); else if (kernel.getWidth() == 1) convolveV(kernel, inPixels, outPixels, width, height, alpha, edgeAction); else convolveHV(kernel, inPixels, outPixels, width, height, alpha, edgeAction); }
/** * Convolve a block of pixels. * @param kernel the kernel * @param inPixels the input pixels * @param outPixels the output pixels * @param width the width * @param height the height * @param alpha include alpha channel * @param edgeAction what to do at the edges */ public static void convolve(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) { if (kernel.getHeight() == 1) convolveH(kernel, inPixels, outPixels, width, height, alpha, edgeAction); else if (kernel.getWidth() == 1) convolveV(kernel, inPixels, outPixels, width, height, alpha, edgeAction); else convolveHV(kernel, inPixels, outPixels, width, height, alpha, edgeAction); }
/** * Convolve a block of pixels. * * @param kernel the kernel * @param inPixels the input pixels * @param outPixels the output pixels * @param width the width * @param height the height * @param alpha include alpha channel * @param edgeAction what to do at the edges */ public void convolve(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) { if (kernel.getHeight() == 1) { convolveH(kernel, inPixels, outPixels, width, height, alpha, edgeAction); } else if (kernel.getWidth() == 1) { convolveV(kernel, inPixels, outPixels, width, height, alpha, edgeAction); } else { convolveHV(kernel, inPixels, outPixels, width, height, alpha, edgeAction); } }
/** * Blur and transpose a block of ARGB pixels. * * @param kernel the blur kernel * @param inPixels the input pixels * @param outPixels the output pixels * @param width the width of the pixel array * @param height the height of the pixel array * @param alpha whether to blur the alpha channel * @param edgeAction what to do at the edges */ public static void convolveAndTranspose(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, boolean premultiply, boolean unpremultiply, int edgeAction, ProgressTracker pt) { float[] matrix = kernel.getKernelData(null); int cols = kernel.getWidth(); int cols2 = cols / 2; Future<?>[] resultLines = new Future[height]; for (int y = 0; y < height; y++) { int finalY = y; Runnable lineTask = () -> convolveAndTransposeLine(inPixels, outPixels, width, height, alpha, premultiply, unpremultiply, edgeAction, matrix, cols2, finalY); resultLines[y] = ThreadPool.submit(lineTask); } ThreadPool.waitToFinish(resultLines, pt); }
private void write(Kernel kernel) { imports.add("java.awt.image.Kernel"); out.print("new Kernel("); out.print(kernel.getWidth()); out.print(", "); out.print(kernel.getHeight()); out.print(", "); write(kernel.getKernelData(null)); out.print(")"); }
int index = 0; float[] matrix = kernel.getKernelData( null ); int cols = kernel.getWidth(); int cols2 = cols/2;
int index = 0; float[] matrix = kernel.getKernelData( null ); int cols = kernel.getWidth(); int cols2 = cols/2;