icm = getIndexColorModel(createSolid(pImage, pMatte), pNumberOfColors, pHints); icm = getIndexColorModel(pImage, pNumberOfColors, pHints); pHints = (pHints & ~DITHER_MASK) | DITHER_NONE; return getIndexedImage(pImage, icm, pMatte, pHints);
return getIndexedImage(pImage, getIndexColorModel(pPalette, 256, pHints), pMatte, pHints);
/** * 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
private IndexColorModel getICM(BufferedImage pSource) { return (indexColorModel != null ? indexColorModel : IndexImage.getIndexColorModel(pSource, 256, IndexImage.TRANSPARENCY_BITMASK)); } private IndexColorModel getICM(Raster pSource) {
/** * Converts the input image (must be {@code TYPE_INT_RGB} or * {@code TYPE_INT_ARGB}) to an indexed image. Generating an adaptive * palette (8 bit) from the color data in the image, and uses default * dither. * <p/> * The image returned is a new image, the input image is not modified. * * @param pImage the BufferedImage to index and get color information from. * @return the indexed BufferedImage. The image will be of type * {@code BufferedImage.TYPE_BYTE_INDEXED}, and use an * {@code IndexColorModel}. * @see BufferedImage#TYPE_BYTE_INDEXED * @see IndexColorModel */ public static BufferedImage getIndexedImage(BufferedImage pImage) { return getIndexedImage(pImage, 256, DITHER_DEFAULT); }
boolean useTransparency = isTransparent(pHints); if (isFast(pHints)) { step += (width * height / 16384);// 128x128px
icm = createIndexColorModel(ImageUtil.toBuffered(image), pNumberOfColors, pHints);
/** * 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
/** * Creates an indexed version of the given image (a {@code BufferedImage} * with an {@code IndexColorModel}. * * @param pImage the image to convert * @param pColors an {@code Image} used to get colors from. If the image is * has an {@code IndexColorModel}, it will be uesd, otherwise an * {@code IndexColorModel} is created from the image. * @param pMatte color to replace transparent parts of the original. * @param pHints hints controlling dither, transparency and color selection * * @return an indexed version of the given image * * @see #COLOR_SELECTION_DEFAULT * @see #COLOR_SELECTION_FAST * @see #COLOR_SELECTION_QUALITY * @see #DITHER_NONE * @see #DITHER_DEFAULT * @see #DITHER_DIFFUSION * @see #DITHER_DIFFUSION_ALTSCANS * @see #TRANSPARENCY_DEFAULT * @see #TRANSPARENCY_OPAQUE * @see #TRANSPARENCY_BITMASK * @see #TRANSPARENCY_TRANSLUCENT */ public static BufferedImage createIndexed(Image pImage, Image pColors, Color pMatte, int pHints) { return IndexImage.getIndexedImage(toBuffered(pImage), IndexImage.getIndexColorModel(pColors, 255, pHints), pMatte, pHints); }
/** * @param pImage the image to get {@code IndexColorModel} from * @param pNumberOfColors the number of colors for the {@code IndexColorModel} * @param pFast {@code true} if fast * @return an {@code IndexColorModel} * @see #getIndexColorModel(Image,int,int) * * @deprecated Use {@link #getIndexColorModel(Image,int,int)} instead! * This version will be removed in a later version of the API. */ public static IndexColorModel getIndexColorModel(Image pImage, int pNumberOfColors, boolean pFast) { return getIndexColorModel(pImage, pNumberOfColors, pFast ? COLOR_SELECTION_FAST : COLOR_SELECTION_QUALITY); }
/** * Converts the input image (must be {@code TYPE_INT_RGB} or * {@code TYPE_INT_ARGB}) to an indexed image. Generating an adaptive * palette with the given number of colors. * Dithering, transparency and color selection is controlled with the * {@code pHints}parameter. * <p/> * The image returned is a new image, the input image is not modified. * * @param pImage the BufferedImage to index * @param pNumberOfColors the number of colors for the image * @param pHints hints that control output quality and speed. * @return the indexed BufferedImage. The image will be of type * {@code BufferedImage.TYPE_BYTE_INDEXED} or * {@code BufferedImage.TYPE_BYTE_BINARY}, and use an * {@code IndexColorModel}. * @see #DITHER_DIFFUSION * @see #DITHER_NONE * @see #COLOR_SELECTION_FAST * @see #COLOR_SELECTION_QUALITY * @see #TRANSPARENCY_OPAQUE * @see #TRANSPARENCY_BITMASK * @see BufferedImage#TYPE_BYTE_INDEXED * @see BufferedImage#TYPE_BYTE_BINARY * @see IndexColorModel */ public static BufferedImage getIndexedImage(BufferedImage pImage, int pNumberOfColors, int pHints) { return getIndexedImage(pImage, pNumberOfColors, null, pHints); }
boolean useTransparency = isTransparent(pHints); if (isFast(pHints)) { step += (width * height / 16384);// 128x128px
icm = createIndexColorModel(ImageUtil.toBuffered(image), pNumberOfColors, pHints);
paletteImg = createSolid(image, background); indexed = getIndexedImage(image, MonochromeColorModel.getInstance(), background, hints); colors = MonochromeColorModel.getInstance(); indexed = getIndexedImage(image, colors = getIndexColorModel(image, numColors, hints), background, hints); colors = getIndexColorModel(indexed, numColors, hints); indexed = getIndexedImage(ImageUtil.toBuffered(image, BufferedImage.TYPE_INT_ARGB), colors = getIndexColorModel(paletteImg, numColors, hints), background, hints); indexed = getIndexedImage(image, colors = getIndexColorModel(image, numColors, hints), background, hints); getIndexedImage(image, colors, background, hints); getIndexedImage(image, colors, background, hints); time += (System.currentTimeMillis() - start); System.out.print('.');
/** * 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 */
return getIndexedImage(pImage, getIndexColorModel(pPalette, 256, pHints), pMatte, pHints);
private IndexColorModel getICM(BufferedImage pSource) { return (indexColorModel != null ? indexColorModel : IndexImage.getIndexColorModel(pSource, 256, IndexImage.TRANSPARENCY_BITMASK | IndexImage.COLOR_SELECTION_QUALITY)); }
/** * Converts the input image (must be {@code TYPE_INT_RGB} or * {@code TYPE_INT_ARGB}) to an indexed image. Using the supplied * {@code IndexColorModel}'s palette. * Dithering, transparency and color selection is controlled with the * {@code pHints}parameter. * <p/> * The image returned is a new image, the input image is not modified. * * @param pImage the BufferedImage to index * @param pColors an {@code IndexColorModel} containing the color information * @param pHints RenderingHints that control output quality and speed. * @return the indexed BufferedImage. The image will be of type * {@code BufferedImage.TYPE_BYTE_INDEXED} or * {@code BufferedImage.TYPE_BYTE_BINARY}, and use an * {@code IndexColorModel}. * @see #DITHER_DIFFUSION * @see #DITHER_NONE * @see #COLOR_SELECTION_FAST * @see #COLOR_SELECTION_QUALITY * @see #TRANSPARENCY_OPAQUE * @see #TRANSPARENCY_BITMASK * @see BufferedImage#TYPE_BYTE_INDEXED * @see BufferedImage#TYPE_BYTE_BINARY * @see IndexColorModel */ public static BufferedImage getIndexedImage(BufferedImage pImage, IndexColorModel pColors, int pHints) { return getIndexedImage(pImage, pColors, null, pHints); }
boolean useTransparency = isTransparent(pHints); if (isFast(pHints)) { step += (width * height / 16384);// 128x128px
icm = createIndexColorModel(ImageUtil.toBuffered(image), pNumberOfColors, pHints);