/** * Performs a single-input/single-output dither operation, applying basic * Floyd-Steinberg error-diffusion to the image. * * @param pSource the source image * @param pDest the destination image * * @return the destination image, or a new image, if {@code pDest} was * {@code null}. */ public final BufferedImage filter(BufferedImage pSource, BufferedImage pDest) { // Create destination image, if none provided if (pDest == null) { pDest = createCompatibleDestImage(pSource, getICM(pSource)); } else if (!(pDest.getColorModel() instanceof IndexColorModel)) { throw new ImageFilterException("Only IndexColorModel allowed."); } // Filter rasters filter(pSource.getRaster(), pDest.getRaster(), (IndexColorModel) pDest.getColorModel()); return pDest; }
/** * Creates a compatible {@code Raster} to dither into. * Only {@code IndexColorModel} allowed. * * @param pSrc the source raster * * @return a {@code WritableRaster} */ public final WritableRaster createCompatibleDestRaster(Raster pSrc) { return createCompatibleDestRaster(pSrc, getICM(pSrc)); }
private IndexColorModel getICM(Raster pSource) { return (indexColorModel != null ? indexColorModel : createIndexColorModel(pSource)); }
/** * Performs a single-input/single-output dither operation, applying basic * Floyd-Steinberg error-diffusion to the image. * * @param pSource the source raster, assumed to be in sRGB * @param pDest the destination raster, may be {@code null} * * @return the destination raster, or a new raster, if {@code pDest} was * {@code null}. */ public final WritableRaster filter(final Raster pSource, WritableRaster pDest) { return filter(pSource, pDest, getICM(pSource)); }
pDest = createCompatibleDestRaster(pSource, pColorModel); pixel = pColorModel.getDataElements(toIntARGB(inRGB), pixel); toRGBArray(pColorModel.getRGB(outRGB[0]), outRGB);
/** * Used to define a cube of the color space. The cube can be split * approximately in half to generate two cubes. */ private static class Cube { int[] min = {0, 0, 0}; int[] max = {255, 255, 255}; boolean done = false; List<Counter>[] colors = null; int count = 0; static final int RED = 0; static final int GRN = 1; static final int BLU = 2; /** * Define a new cube. * * @param colors contains the 3D color histogram to be subdivided * @param count the total number of pixels in the 3D histogram. */ public Cube(List<Counter>[] colors, int count) { this.colors = colors; this.count = count; } /** * If this returns true then the cube can not be subdivided any * further * * @return true if cube can not be subdivided any further
new DiffusionDither((IndexColorModel) cm).filter(scaled, temp);
/** * Returns the bounding box of the filtered destination image. Since * this is not a geometric operation, the bounding box does not * change. * @param pSrc the {@code BufferedImage} to be filtered * @return the bounds of the filtered definition image. */ public final Rectangle2D getBounds2D(BufferedImage pSrc) { return getBounds2D(pSrc.getRaster()); }
/** * Creates a compatible {@code BufferedImage} to dither into. * Only {@code IndexColorModel} allowed. * * @return a compatible {@code BufferedImage} * * @throws ImageFilterException if {@code pDestCM} is not {@code null} or * an instance of {@code IndexColorModel}. */ public final BufferedImage createCompatibleDestImage(BufferedImage pSource, ColorModel pDestCM) { if (pDestCM == null) { return new BufferedImage(pSource.getWidth(), pSource.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, getICM(pSource)); } else if (pDestCM instanceof IndexColorModel) { return new BufferedImage(pSource.getWidth(), pSource.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, (IndexColorModel) pDestCM); } else { throw new ImageFilterException("Only IndexColorModel allowed."); } }
pDest = createCompatibleDestRaster(pSource, pColorModel); pixel = pColorModel.getDataElements(toIntARGB(inRGB), pixel); toRGBArray(pColorModel.getRGB(outRGB[0]), outRGB);
/** * Used to define a cube of the color space. The cube can be split * approximately in half to generate two cubes. */ private static class Cube { int[] min = {0, 0, 0}; int[] max = {255, 255, 255}; boolean done = false; List<Counter>[] colors = null; int count = 0; static final int RED = 0; static final int GRN = 1; static final int BLU = 2; /** * Define a new cube. * * @param colors contains the 3D color histogram to be subdivided * @param count the total number of pixels in the 3D histogram. */ public Cube(List<Counter>[] colors, int count) { this.colors = colors; this.count = count; } /** * If this returns true then the cube can not be subdivided any * further * * @return true if cube can not be subdivided any further
/** * Performs a single-input/single-output dither operation, applying basic * Floyd-Steinberg error-diffusion to the image. * * @param pSource the source raster, assumed to be in sRGB * @param pDest the destination raster, may be {@code null} * * @return the destination raster, or a new raster, if {@code pDest} was * {@code null}. */ public final WritableRaster filter(final Raster pSource, WritableRaster pDest) { return filter(pSource, pDest, getICM(pSource)); }
new DiffusionDither((IndexColorModel) cm).filter(scaled, temp);
/** * Returns the bounding box of the filtered destination image. Since * this is not a geometric operation, the bounding box does not * change. * @param pSrc the {@code BufferedImage} to be filtered * @return the bounds of the filtered definition image. */ public final Rectangle2D getBounds2D(BufferedImage pSrc) { return getBounds2D(pSrc.getRaster()); }
/** * Creates a compatible {@code BufferedImage} to dither into. * Only {@code IndexColorModel} allowed. * * @return a compatible {@code BufferedImage} * * @throws ImageFilterException if {@code pDestCM} is not {@code null} or * an instance of {@code IndexColorModel}. */ public final BufferedImage createCompatibleDestImage(BufferedImage pSource, ColorModel pDestCM) { if (pDestCM == null) { return new BufferedImage(pSource.getWidth(), pSource.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, getICM(pSource)); } else if (pDestCM instanceof IndexColorModel) { return new BufferedImage(pSource.getWidth(), pSource.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, (IndexColorModel) pDestCM); } else { throw new ImageFilterException("Only IndexColorModel allowed."); } }
/** * Performs a single-input/single-output dither operation, applying basic * Floyd-Steinberg error-diffusion to the image. * * @param pSource the source image * @param pDest the destiantion image * * @return the destination image, or a new image, if {@code pDest} was * {@code null}. */ public final BufferedImage filter(BufferedImage pSource, BufferedImage pDest) { // Create destination image, if none provided if (pDest == null) { pDest = createCompatibleDestImage(pSource, getICM(pSource)); } else if (!(pDest.getColorModel() instanceof IndexColorModel)) { throw new ImageFilterException("Only IndexColorModel allowed."); } // Filter rasters filter(pSource.getRaster(), pDest.getRaster(), (IndexColorModel) pDest.getColorModel()); return pDest; }
pDest = createCompatibleDestRaster(pSource, pColorModel); pixel = pColorModel.getDataElements(toIntARGB(inRGB), pixel); toRGBArray(pColorModel.getRGB(outRGB[0]), outRGB);
/** * Used to define a cube of the colorspace. The cube can be split * approximagely in half to generate two cubes. */ private static class Cube { int[] min = {0, 0, 0}, max = {255, 255, 255}; boolean done = false; List[] colors = null; int count = 0; static final int RED = 0; static final int GRN = 1; static final int BLU = 2; /** * Define a new cube. * * @param colors contains the 3D color histogram to be subdivided * @param count the total number of pixels in the 3D histogram. */ public Cube(List[] colors, int count) { this.colors = colors; this.count = count; } /** * If this returns true then the cube can not be subdivided any * further * * @return true if cube can not be subdivided any further */
/** * Creates a compatible {@code Raster} to dither into. * Only {@code IndexColorModel} allowed. * * @param pSrc * * @return a {@code WritableRaster} */ public final WritableRaster createCompatibleDestRaster(Raster pSrc) { return createCompatibleDestRaster(pSrc, getICM(pSrc)); }
/** * Performs a single-input/single-output dither operation, applying basic * Floyd-Steinberg error-diffusion to the image. * * @param pSource * @param pDest * * @return the destination raster, or a new raster, if {@code pDest} was * {@code null}. */ public final WritableRaster filter(final Raster pSource, WritableRaster pDest) { return filter(pSource, pDest, getICM(pSource)); }