Java Code Examples for java.awt.image.IndexColorModel

The following are top voted examples for showing how to use java.awt.image.IndexColorModel. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: jdk8u-jdk   File: BMPSubsamplingTest.java   Source Code and License 7 votes vote down vote up
private BufferedImage createIndexImage(int bpp) {
    // calculate palette size
    int psize = (1 << bpp);

    // prepare palette;
    byte[] r = new byte[psize];
    byte[] g = new byte[psize];
    byte[] b = new byte[psize];

    for (int i = 0; i < colors.length; i++) {
        r[i] = (byte)(0xff & colors[i].getRed());
        g[i] = (byte)(0xff & colors[i].getGreen());
        b[i] = (byte)(0xff & colors[i].getBlue());
    }

    // now prepare appropriate index clor model
    IndexColorModel icm = new IndexColorModel(bpp, psize, r, g, b);

    return new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm);
}
 
Example 2
Project: jdk8u-jdk   File: JFIFMarkerSegment.java   Source Code and License 7 votes vote down vote up
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    super.write(ios, writer); // width and height
    // Write the palette (must be 768 bytes)
    byte [] palette = new byte[768];
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    byte [] reds = new byte [256];
    byte [] greens = new byte [256];
    byte [] blues = new byte [256];
    icm.getReds(reds);
    icm.getGreens(greens);
    icm.getBlues(blues);
    for (int i = 0; i < 256; i++) {
        palette[i*3] = reds[i];
        palette[i*3+1] = greens[i];
        palette[i*3+2] = blues[i];
    }
    ios.write(palette);
    writePixels(ios, writer);
}
 
Example 3
Project: openjdk-jdk10   File: ShortHistogramTest.java   Source Code and License 6 votes vote down vote up
private IIOMetadataNode gethISTNode(BufferedImage bi) {
    IndexColorModel icm = (IndexColorModel)bi.getColorModel();
    int mapSize = icm.getMapSize();

    int[] hist = new int[mapSize];
    Arrays.fill(hist, 0);

    Raster r = bi.getData();
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            int s = r.getSample(x, y, 0);
            hist[s] ++;
        }
    }

    IIOMetadataNode hIST = new IIOMetadataNode("hIST");
    for (int i = 0; i < hist.length; i++) {
        IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
        n.setAttribute("index", "" + i);
        n.setAttribute("value", "" + hist[i]);
        hIST.appendChild(n);
    }

    return hIST;
}
 
Example 4
Project: openjdk-jdk10   File: RleEncodingTest.java   Source Code and License 6 votes vote down vote up
private static void encodeRLE4Test() throws IOException {
    // create 4bpp image
    byte[] r = new byte[16];
    r[0] = (byte)0xff;
    byte[] g = new byte[16];
    g[1] = (byte)0xff;
    byte[] b = new byte[16];
    b[2] = (byte)0xff;
    IndexColorModel icm = new IndexColorModel(4, 16, r, g, b);

    BufferedImage bimg = new BufferedImage(100, 100,
                                           BufferedImage.TYPE_BYTE_BINARY,
                                           icm);

    Graphics gr = bimg.getGraphics();
    gr.setColor(Color.green);
    gr.fillRect(0, 0, 100, 100);

    doTest(bimg, "BI_RLE4", ImageWriteParam.MODE_EXPLICIT);
}
 
Example 5
Project: jtk   File: FloatColorMap.java   Source Code and License 6 votes vote down vote up
/**
 * Constructs a color map with more than one color components.
 * @param f arrays of floats, one array for each color component.
 * @param ic array index of the component for the index color model.
 * @param icm the index color model corresponding to one component.
 */
public FloatColorMap(float[][][] f, int ic, IndexColorModel icm) {
  super(icm);
  Check.argument(
    f.length==1 || f.length==3 || f.length==4,
    "number of arrays (color components) equals 1, 3, or 4");
  int nc = f.length;
  FloatByteMap[] fbm = new FloatByteMap[nc];
  for (int jc=0; jc<nc; ++jc)
    fbm[jc] = new FloatByteMap(f[jc]);
  _fbmi0 = fbm[0];
  _fbmi1 = (nc>1)?fbm[1]:fbm[0];
  _fbmi2 = (nc>1)?fbm[2]:fbm[0];
  _fbmi3 = (nc>3)?fbm[3]:null;
  _fbmic = fbm[ic];
}
 
Example 6
Project: openjdk-jdk10   File: BMPSubsamplingTest.java   Source Code and License 6 votes vote down vote up
private BufferedImage createIndexImage(int bpp) {
    // calculate palette size
    int psize = (1 << bpp);

    // prepare palette;
    byte[] r = new byte[psize];
    byte[] g = new byte[psize];
    byte[] b = new byte[psize];

    for (int i = 0; i < colors.length; i++) {
        r[i] = (byte)(0xff & colors[i].getRed());
        g[i] = (byte)(0xff & colors[i].getGreen());
        b[i] = (byte)(0xff & colors[i].getBlue());
    }

    // now prepare appropriate index clor model
    IndexColorModel icm = new IndexColorModel(bpp, psize, r, g, b);

    return new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm);
}
 
Example 7
Project: openjdk-jdk10   File: XYZApp.java   Source Code and License 6 votes vote down vote up
private void Setup() {
    balls = new Image[nBalls];
    byte red[] = new byte[256];
    red[0] = (byte) bgGrey;
    byte green[] = new byte[256];
    green[0] = (byte) bgGrey;
    byte blue[] = new byte[256];
    blue[0] = (byte) bgGrey;
    for (int r = 0; r < nBalls; r++) {
        float b = (float) (r + 1) / nBalls;
        for (int i = maxr; i >= 1; --i) {
            float d = (float) i / maxr;
            red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b);
            green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b);
            blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b);
        }
        IndexColorModel model = new IndexColorModel(8, maxr + 1,
                red, green, blue, 0);
        balls[r] = applet.createImage(
                new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2));
    }
}
 
Example 8
Project: openjdk-jdk10   File: TransparencyTest.java   Source Code and License 6 votes vote down vote up
protected  static IndexColorModel createIndexedBitmaskColorModel() {
    int paletteSize = 8;
    byte[] red = new byte[paletteSize];
    byte[] green = new byte[paletteSize];
    byte[] blue = new byte[paletteSize];

    red[0] = (byte)0xff; green[0] = (byte)0x00; blue[0] = (byte)0x00;
    red[1] = (byte)0x00; green[1] = (byte)0xff; blue[1] = (byte)0x00;
    red[2] = (byte)0x00; green[2] = (byte)0x00; blue[2] = (byte)0xff;
    red[3] = (byte)0xff; green[3] = (byte)0xff; blue[3] = (byte)0xff;
    red[4] = (byte)0x00; green[4] = (byte)0x00; blue[4] = (byte)0x00;
    red[5] = (byte)0x80; green[5] = (byte)0x80; blue[5] = (byte)0x80;
    red[6] = (byte)0xff; green[6] = (byte)0xff; blue[6] = (byte)0x00;
    red[7] = (byte)0x00; green[7] = (byte)0xff; blue[7] = (byte)0xff;

    int numBits = 3;

    IndexColorModel icm = new IndexColorModel(numBits, paletteSize,
                                              red, green, blue, 5);

    return icm;
}
 
Example 9
Project: jtk   File: ColorMap.java   Source Code and License 6 votes vote down vote up
/**
 * Returns an index color model with specified opacity (alpha).
 * @param icm an index color model from which to copy RGBs.
 * @param alpha opacity in the range [0.0,1.0].
 * @return the index color model with alpha.
 */
public static IndexColorModel setAlpha(IndexColorModel icm, double alpha) {
  int bits = icm.getPixelSize();
  int size = icm.getMapSize();
  byte[] r = new byte[size];
  byte[] g = new byte[size];
  byte[] b = new byte[size];
  byte[] a = new byte[size];
  icm.getReds(r);
  icm.getGreens(g);
  icm.getBlues(b);
  byte ia = (byte)(255.0*alpha+0.5);
  for (int i=0; i<size; ++i)
    a[i] = ia;
  return new IndexColorModel(bits,size,r,g,b,a);
}
 
Example 10
Project: jtk   File: ColorMap.java   Source Code and License 6 votes vote down vote up
/**
 * Returns an index color model with specified opacities (alphas).
 * @param icm an index color model from which to copy RGBs.
 * @param alpha array of opacities in the range [0.0,1.0].
 * @return the index color model with alphas.
 */
public static IndexColorModel setAlpha(IndexColorModel icm, float[] alpha) {
  int bits = icm.getPixelSize();
  int size = icm.getMapSize();
  byte[] r = new byte[size];
  byte[] g = new byte[size];
  byte[] b = new byte[size];
  byte[] a = new byte[size];
  icm.getReds(r);
  icm.getGreens(g);
  icm.getBlues(b);
  int n = min(size,alpha.length);
  for (int i=0; i<n; ++i)
    a[i] = (byte)(255.0f*alpha[i]+0.5f);
  return new IndexColorModel(bits,size,r,g,b,a);
}
 
Example 11
Project: openjdk-jdk10   File: IndexColorModelEqualsTest.java   Source Code and License 6 votes vote down vote up
private static void verifyEquals(IndexColorModel m1,
                                 IndexColorModel m2) {
    if (m1.equals(null)) {
        throw new RuntimeException("equals(null) returns true");
    }
    if (!(m1.equals(m2))) {
        throw new RuntimeException("equals() method is not working"
                + " properly");
    }
    if (!(m2.equals(m1))) {
        throw new RuntimeException("equals() method is not working"
                + " properly");
    }
    if (m1.hashCode() != m2.hashCode()) {
        throw new RuntimeException("HashCode is not same for same"
                + " IndexColorModels");
    }
}
 
Example 12
Project: openjdk-jdk10   File: BufImgSurfaceData.java   Source Code and License 6 votes vote down vote up
public static SurfaceData createDataBC(BufferedImage bImg,
                                       SurfaceType sType,
                                       int primaryBank,
                                       double scaleX, double scaleY)
{
    ByteComponentRaster bcRaster =
        (ByteComponentRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(bcRaster.getDataBuffer(), bImg, sType,
                              scaleX, scaleY);
    ColorModel cm = bImg.getColorModel();
    IndexColorModel icm = ((cm instanceof IndexColorModel)
                           ? (IndexColorModel) cm
                           : null);
    bisd.initRaster(bcRaster.getDataStorage(),
                    bcRaster.getDataOffset(primaryBank), 0,
                    bcRaster.getWidth(),
                    bcRaster.getHeight(),
                    bcRaster.getPixelStride(),
                    bcRaster.getScanlineStride(),
                    icm);
    return bisd;
}
 
Example 13
Project: openjdk-jdk10   File: GIFImageReader.java   Source Code and License 6 votes vote down vote up
private static synchronized byte[] getDefaultPalette() {
    if (defaultPalette == null) {
        BufferedImage img = new BufferedImage(1, 1,
                BufferedImage.TYPE_BYTE_INDEXED);
        IndexColorModel icm = (IndexColorModel) img.getColorModel();

        final int size = icm.getMapSize();
        byte[] r = new byte[size];
        byte[] g = new byte[size];
        byte[] b = new byte[size];
        icm.getReds(r);
        icm.getGreens(g);
        icm.getBlues(b);

        defaultPalette = new byte[size * 3];

        for (int i = 0; i < size; i++) {
            defaultPalette[3 * i + 0] = r[i];
            defaultPalette[3 * i + 1] = g[i];
            defaultPalette[3 * i + 2] = b[i];
        }
    }
    return defaultPalette;
}
 
Example 14
Project: ramus   File: IDLColorModelFactory.java   Source Code and License 6 votes vote down vote up
public static IndexColorModel createColorModel() {
    // Create a 6x6x6 color cube
    int[] cmap = new int[256];
    int i = 0;
    for (int r = 0; r < 256; r += 51) {
        for (int g = 0; g < 256; g += 51) {
            for (int b = 0; b < 256; b += 51) {
                cmap[i++] = (r << 16) | (g << 8) | b;
            }
        }
    }
    // And populate the rest of the cmap with gray values
    int grayIncr = 256 / (256 - i);

    // The gray ramp will be between 18 and 252
    int gray = grayIncr * 3;
    for (; i < 256; i++) {
        cmap[i] = (gray << 16) | (gray << 8) | gray;
        gray += grayIncr;
    }

    return new IndexColorModel(8, 256, cmap, 0, false, -1,
            DataBuffer.TYPE_BYTE);
}
 
Example 15
Project: OpenJSharp   File: XYZApp.java   Source Code and License 6 votes vote down vote up
private void Setup() {
    balls = new Image[nBalls];
    byte red[] = new byte[256];
    red[0] = (byte) bgGrey;
    byte green[] = new byte[256];
    green[0] = (byte) bgGrey;
    byte blue[] = new byte[256];
    blue[0] = (byte) bgGrey;
    for (int r = 0; r < nBalls; r++) {
        float b = (float) (r + 1) / nBalls;
        for (int i = maxr; i >= 1; --i) {
            float d = (float) i / maxr;
            red[i] = (byte) blend(blend(Rl, 255, d), bgGrey, b);
            green[i] = (byte) blend(blend(Gl, 255, d), bgGrey, b);
            blue[i] = (byte) blend(blend(Bl, 255, d), bgGrey, b);
        }
        IndexColorModel model = new IndexColorModel(8, maxr + 1,
                red, green, blue, 0);
        balls[r] = applet.createImage(
                new MemoryImageSource(R * 2, R * 2, model, data, 0, R * 2));
    }
}
 
Example 16
Project: OpenJSharp   File: BufImgSurfaceData.java   Source Code and License 6 votes vote down vote up
public static SurfaceData createDataSC(BufferedImage bImg,
                                       SurfaceType sType,
                                       IndexColorModel icm) {
    ShortComponentRaster scRaster =
        (ShortComponentRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(scRaster.getDataBuffer(), bImg, sType);
    bisd.initRaster(scRaster.getDataStorage(),
                    scRaster.getDataOffset(0) * 2, 0,
                    scRaster.getWidth(),
                    scRaster.getHeight(),
                    scRaster.getPixelStride() * 2,
                    scRaster.getScanlineStride() * 2,
                    icm);
    return bisd;
}
 
Example 17
Project: OpenJSharp   File: BufImgSurfaceData.java   Source Code and License 6 votes vote down vote up
public static SurfaceData createDataBC(BufferedImage bImg,
                                       SurfaceType sType,
                                       int primaryBank) {
    ByteComponentRaster bcRaster =
        (ByteComponentRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(bcRaster.getDataBuffer(), bImg, sType);
    ColorModel cm = bImg.getColorModel();
    IndexColorModel icm = ((cm instanceof IndexColorModel)
                           ? (IndexColorModel) cm
                           : null);
    bisd.initRaster(bcRaster.getDataStorage(),
                    bcRaster.getDataOffset(primaryBank), 0,
                    bcRaster.getWidth(),
                    bcRaster.getHeight(),
                    bcRaster.getPixelStride(),
                    bcRaster.getScanlineStride(),
                    icm);
    return bisd;
}
 
Example 18
Project: OpenJSharp   File: BufImgSurfaceData.java   Source Code and License 6 votes vote down vote up
public static SurfaceData createDataBP(BufferedImage bImg,
                                       SurfaceType sType) {
    BytePackedRaster bpRaster =
        (BytePackedRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(bpRaster.getDataBuffer(), bImg, sType);
    ColorModel cm = bImg.getColorModel();
    IndexColorModel icm = ((cm instanceof IndexColorModel)
                           ? (IndexColorModel) cm
                           : null);
    bisd.initRaster(bpRaster.getDataStorage(),
                    bpRaster.getDataBitOffset() / 8,
                    bpRaster.getDataBitOffset() & 7,
                    bpRaster.getWidth(),
                    bpRaster.getHeight(),
                    0,
                    bpRaster.getScanlineStride(),
                    icm);
    return bisd;
}
 
Example 19
Project: OpenJSharp   File: JFIFMarkerSegment.java   Source Code and License 6 votes vote down vote up
JFIFExtensionMarkerSegment(BufferedImage thumbnail)
    throws IllegalThumbException {

    super(JPEG.APP0);
    ColorModel cm = thumbnail.getColorModel();
    int csType = cm.getColorSpace().getType();
    if (cm.hasAlpha()) {
        throw new IllegalThumbException();
    }
    if (cm instanceof IndexColorModel) {
        code = THUMB_PALETTE;
        thumb = new JFIFThumbPalette(thumbnail);
    } else if (csType == ColorSpace.TYPE_RGB) {
        code = THUMB_RGB;
        thumb = new JFIFThumbRGB(thumbnail);
    } else if (csType == ColorSpace.TYPE_GRAY) {
        code = THUMB_JPEG;
        thumb = new JFIFThumbJPEG(thumbnail);
    } else {
        throw new IllegalThumbException();
    }
}
 
Example 20
Project: openjdk-jdk10   File: JFIFMarkerSegment.java   Source Code and License 6 votes vote down vote up
JFIFExtensionMarkerSegment(BufferedImage thumbnail)
    throws IllegalThumbException {

    super(JPEG.APP0);
    ColorModel cm = thumbnail.getColorModel();
    int csType = cm.getColorSpace().getType();
    if (cm.hasAlpha()) {
        throw new IllegalThumbException();
    }
    if (cm instanceof IndexColorModel) {
        code = THUMB_PALETTE;
        thumb = new JFIFThumbPalette(thumbnail);
    } else if (csType == ColorSpace.TYPE_RGB) {
        code = THUMB_RGB;
        thumb = new JFIFThumbRGB(thumbnail);
    } else if (csType == ColorSpace.TYPE_GRAY) {
        code = THUMB_JPEG;
        thumb = new JFIFThumbJPEG(thumbnail);
    } else {
        throw new IllegalThumbException();
    }
}
 
Example 21
Project: OpenJSharp   File: JFIFMarkerSegment.java   Source Code and License 6 votes vote down vote up
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    super.write(ios, writer); // width and height
    // Write the palette (must be 768 bytes)
    byte [] palette = new byte[768];
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    byte [] reds = new byte [256];
    byte [] greens = new byte [256];
    byte [] blues = new byte [256];
    icm.getReds(reds);
    icm.getGreens(greens);
    icm.getBlues(blues);
    for (int i = 0; i < 256; i++) {
        palette[i*3] = reds[i];
        palette[i*3+1] = greens[i];
        palette[i*3+2] = blues[i];
    }
    ios.write(palette);
    writePixels(ios, writer);
}
 
Example 22
Project: OpenJSharp   File: GIFImageReader.java   Source Code and License 6 votes vote down vote up
private static synchronized byte[] getDefaultPalette() {
    if (defaultPalette == null) {
        BufferedImage img = new BufferedImage(1, 1,
                BufferedImage.TYPE_BYTE_INDEXED);
        IndexColorModel icm = (IndexColorModel) img.getColorModel();

        final int size = icm.getMapSize();
        byte[] r = new byte[size];
        byte[] g = new byte[size];
        byte[] b = new byte[size];
        icm.getReds(r);
        icm.getGreens(g);
        icm.getBlues(b);

        defaultPalette = new byte[size * 3];

        for (int i = 0; i < size; i++) {
            defaultPalette[3 * i + 0] = r[i];
            defaultPalette[3 * i + 1] = g[i];
            defaultPalette[3 * i + 2] = b[i];
        }
    }
    return defaultPalette;
}
 
Example 23
Project: openjdk-jdk10   File: IndexColorModelEqualsTest.java   Source Code and License 6 votes vote down vote up
private static void testConstructor7() {
    /*
     * verify equality with constructor
     * IndexColorModel(int bits, int size, int[] cmap, int start,
     * int transferType, BigInteger validBits)
     */
    /*
     * In setRGBs() function of IndexColorModel we override
     * transparent_index value to map to pixel value if alpha is 0x00
     * so we should have atleast minimum alpha value to keep
     * both model1 and model2 same.
     */
    int color = 16777216;
    IndexColorModel model1 = new IndexColorModel(8, 3, new int[] {color,
            color, color}, 0, DataBuffer.TYPE_BYTE, new BigInteger("1"));
    IndexColorModel model2 = new IndexColorModel(8, 3, new int[] {color,
            color, color}, 0, DataBuffer.TYPE_BYTE, new BigInteger("1"));
    verifyEquals(model1, model2);
}
 
Example 24
Project: openjdk-jdk10   File: TransparencyTest.java   Source Code and License 6 votes vote down vote up
protected static BufferedImage createIndexedImage(int w, int h,
                                                  IndexColorModel icm)
{
    BufferedImage img = new BufferedImage(w, h,
                                          BufferedImage.TYPE_BYTE_INDEXED,
                                          icm);

    int mapSize = icm.getMapSize();
    int width = w / mapSize;

    WritableRaster wr = img.getRaster();
    for (int i = 0; i < mapSize; i++) {
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < width; x++) {
                wr.setSample(i * width + x, y, 0, i);
            }
        }
    }
    return img;
}
 
Example 25
Project: imagingbook-common   File: LookupTables.java   Source Code and License 6 votes vote down vote up
/**
 * Modifies the lookup table to display a bright image with gray values
 * in the range minGray ... 255. Does nothing if ip is of type
 * ColorProcessor.
 * 
 * @param ip The target image.
 * @param minGray Minimum gray value.
 */
public static void brightLut(ImageProcessor ip, int minGray) {
	if (minGray < 0 || minGray >= 255)
		return;
	ColorModel cm = ip.getColorModel();
	if (!(cm instanceof IndexColorModel))
		return;
	IndexColorModel icm = (IndexColorModel) cm;
	int mapSize = icm.getMapSize();
	byte[] reds = new byte[mapSize];
	byte[] grns = new byte[mapSize];
	byte[] blus = new byte[mapSize];
	float scale = (255 - minGray) / 255f;
	for (int i = 0; i < mapSize; i++) {
		byte g = (byte) (Math.round(minGray + scale * i) & 0xFF);
		reds[i] = g;
		grns[i] = g;
		blus[i] = g;
	}
	ip.setColorModel(new IndexColorModel(8, mapSize, reds, grns, blus));
}
 
Example 26
Project: Tarski   File: mxPngEncodeParam.java   Source Code and License 6 votes vote down vote up
/**
 * Returns an instance of <code>PNGEncodeParam.Palette</code>,
 * <code>PNGEncodeParam.Gray</code>, or
 * <code>PNGEncodeParam.RGB</code> appropriate for encoding
 * the given image.
 *
 * <p> If the image has an <code>IndexColorModel</code>, an
 * instance of <code>PNGEncodeParam.Palette</code> is returned.
 * Otherwise, if the image has 1 or 2 bands an instance of
 * <code>PNGEncodeParam.Gray</code> is returned.  In all other
 * cases an instance of <code>PNGEncodeParam.RGB</code> is
 * returned.
 *
 * <p> Note that this method does not provide any guarantee that
 * the given image will be successfully encoded by the PNG
 * encoder, as it only performs a very superficial analysis of
 * the image structure.
 */
public static mxPngEncodeParam getDefaultEncodeParam(RenderedImage im)
{
	ColorModel colorModel = im.getColorModel();
	if (colorModel instanceof IndexColorModel)
	{
		return new mxPngEncodeParam.Palette();
	}

	SampleModel sampleModel = im.getSampleModel();
	int numBands = sampleModel.getNumBands();

	if (numBands == 1 || numBands == 2)
	{
		return new mxPngEncodeParam.Gray();
	}
	else
	{
		return new mxPngEncodeParam.RGB();
	}
}
 
Example 27
Project: openjdk-jdk10   File: ShortHistogramTest.java   Source Code and License 6 votes vote down vote up
protected BufferedImage createTestImage(int numColors) {

        IndexColorModel icm = createTestICM(numColors);
        int w = numColors * 10;
        int h = 20;

        BufferedImage img = new BufferedImage(w, h,
                BufferedImage.TYPE_BYTE_INDEXED, icm);

        Graphics2D g = img.createGraphics();
        for (int i = 0; i < numColors; i++) {
            int rgb = icm.getRGB(i);
            //System.out.printf("pixel %d, rgb %x\n", i, rgb);
            g.setColor(new Color(rgb));
            g.fillRect(i * 10, 0, w - i * 10, h);
        }
        g.dispose();

       return img;
    }
 
Example 28
Project: jdk8u-jdk   File: JFIFMarkerSegment.java   Source Code and License 6 votes vote down vote up
JFIFExtensionMarkerSegment(BufferedImage thumbnail)
    throws IllegalThumbException {

    super(JPEG.APP0);
    ColorModel cm = thumbnail.getColorModel();
    int csType = cm.getColorSpace().getType();
    if (cm.hasAlpha()) {
        throw new IllegalThumbException();
    }
    if (cm instanceof IndexColorModel) {
        code = THUMB_PALETTE;
        thumb = new JFIFThumbPalette(thumbnail);
    } else if (csType == ColorSpace.TYPE_RGB) {
        code = THUMB_RGB;
        thumb = new JFIFThumbRGB(thumbnail);
    } else if (csType == ColorSpace.TYPE_GRAY) {
        code = THUMB_JPEG;
        thumb = new JFIFThumbJPEG(thumbnail);
    } else {
        throw new IllegalThumbException();
    }
}
 
Example 29
Project: jdk8u-jdk   File: GIFImageReader.java   Source Code and License 6 votes vote down vote up
private static synchronized byte[] getDefaultPalette() {
    if (defaultPalette == null) {
        BufferedImage img = new BufferedImage(1, 1,
                BufferedImage.TYPE_BYTE_INDEXED);
        IndexColorModel icm = (IndexColorModel) img.getColorModel();

        final int size = icm.getMapSize();
        byte[] r = new byte[size];
        byte[] g = new byte[size];
        byte[] b = new byte[size];
        icm.getReds(r);
        icm.getGreens(g);
        icm.getBlues(b);

        defaultPalette = new byte[size * 3];

        for (int i = 0; i < size; i++) {
            defaultPalette[3 * i + 0] = r[i];
            defaultPalette[3 * i + 1] = g[i];
            defaultPalette[3 * i + 2] = b[i];
        }
    }
    return defaultPalette;
}
 
Example 30
Project: jdk8u-jdk   File: PaletteBuilder.java   Source Code and License 6 votes vote down vote up
protected RenderedImage getIndexedImage() {
    IndexColorModel icm = getIndexColorModel();

    BufferedImage dst =
        new BufferedImage(src.getWidth(), src.getHeight(),
                          BufferedImage.TYPE_BYTE_INDEXED, icm);

    WritableRaster wr = dst.getRaster();
    for (int y =0; y < dst.getHeight(); y++) {
        for (int x = 0; x < dst.getWidth(); x++) {
            Color aColor = getSrcColor(x,y);
            wr.setSample(x, y, 0, findColorIndex(root, aColor));
        }
    }

    return dst;
}
 
Example 31
Project: jdk8u-jdk   File: WPrinterJob.java   Source Code and License 5 votes vote down vote up
protected void drawDIBImage(byte[] image,
                            float destX, float destY,
                            float destWidth, float destHeight,
                            float srcX, float srcY,
                            float srcWidth, float srcHeight,
                            int sampleBitsPerPixel,
                            IndexColorModel icm) {
    int bitCount = 24;
    byte[] bmiColors = null;

    if (icm != null) {
        bitCount = sampleBitsPerPixel;
        bmiColors = new byte[(1<<icm.getPixelSize())*4];
        for (int i=0;i<icm.getMapSize(); i++) {
            bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
            bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
            bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
        }
    }

    drawDIBImage(getPrintDC(), image,
                 destX, destY,
                 destWidth, destHeight,
                 srcX, srcY,
                 srcWidth, srcHeight,
                 bitCount, bmiColors);
}
 
Example 32
Project: rapidminer   File: ToolbarHandlerBuffer.java   Source Code and License 5 votes vote down vote up
private void createImage() {
	if (this.gc != null) {
		this.image = this.gc.createCompatibleImage(IMAGE_SIZE, IMAGE_SIZE, Transparency.BITMASK);
	} else {
		int cmap[] = { this.topColor.getRGB(), this.shadowColor.getRGB() };
		IndexColorModel icm = new IndexColorModel(8, 3, cmap, 0, false, -1, DataBuffer.TYPE_BYTE);
		this.image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_BYTE_INDEXED, icm);
	}
}
 
Example 33
Project: jtk   File: ColorBar.java   Source Code and License 5 votes vote down vote up
public void colorMapChanged(ColorMap cm) {
  float vmin = (float)cm.getMinValue();
  float vmax = (float)cm.getMaxValue();
  if (vmin==vmax) {
    vmin -= Math.ulp(vmin);
    vmax += Math.ulp(vmax);
  }
  int nv = 256;
  double dv = (vmax-vmin)/(nv-1);
  double fv = vmin;
  Sampling vs = new Sampling(nv,dv,fv);
  float[][] va = new float[nv][1];
  Color[] ca = new Color[nv];
  for (int iv=0; iv<nv; ++iv) {
    float vi = (float)vs.getValue(iv);
    va[iv][0] = vi;
    ca[iv] = cm.getColor(vi);
  }
  if (_pixels==null) {
    _pixels = new PixelsView(va);
    _pixels.setOrientation(PixelsView.Orientation.X1RIGHT_X2UP);
    _pixels.setInterpolation(PixelsView.Interpolation.LINEAR);
    _tile.addTiledView(_pixels);
  }
  IndexColorModel icm = ColorMap.makeIndexColorModel(ca);
  _pixels.setClips(vmin,vmax);
  _pixels.setColorModel(icm);
  Sampling s1 = new Sampling(1);
  Sampling s2 = vs;
  _pixels.set(s1,s2,va);
}
 
Example 34
Project: jtk   File: PlotPanel.java   Source Code and License 5 votes vote down vote up
/**
 * Determines if a specified color map has more than one color.
 * Note that we ignore any variation in alpha.
 */
private static boolean isMultiColor(ColorMapped cm) {
  ColorMap cmap = cm.getColorMap();
  IndexColorModel icm = cmap.getColorModel();
  int n = icm.getMapSize();
  int rgb = icm.getRGB(0)&0x00ffffff;
  for (int i=1; i<n; ++i) 
    if (rgb!=(icm.getRGB(i)&0x00ffffff))
      return true;
  return false;
}
 
Example 35
Project: jdk8u-jdk   File: ShortHistogramTest.java   Source Code and License 5 votes vote down vote up
protected IndexColorModel createTestICM(int numColors) {
    int[] palette = createTestPalette(numColors);

    int numBits = getNumBits(numColors);

    IndexColorModel icm = new IndexColorModel(numBits, numColors,
            palette, 0, false, -1,
            DataBuffer.TYPE_BYTE);
    return icm;
}
 
Example 36
Project: jtk   File: ColorMap.java   Source Code and License 5 votes vote down vote up
/**
 * Constructs a color map for specified values.
 * The integers 0 and 255 must be valid pixels for the color model.
 * @param vmin the minimum value.
 * @param vmax the maximum value.
 * @param colorModel the index color model.
 */
public ColorMap(double vmin, double vmax, IndexColorModel colorModel) {
  Check.argument(colorModel.isValid(0),"0 is valid for color model");
  Check.argument(colorModel.isValid(255),"255 is valid for color model");
  _vmin = vmin;
  _vmax = vmax;
  _colorModel = colorModel;
  cacheColors();
}
 
Example 37
Project: openjdk-jdk10   File: TexturePaintContext.java   Source Code and License 5 votes vote down vote up
public ByteFilter(ByteInterleavedRaster srcRas, ColorModel cm,
                  AffineTransform xform, int maxw)
{
    super((cm.getTransparency() == Transparency.OPAQUE
           ? xrgbmodel : argbmodel),
          xform, srcRas.getWidth(), srcRas.getHeight(), maxw);
    this.inPalette = new int[256];
    ((IndexColorModel) cm).getRGBs(this.inPalette);
    this.srcRas = srcRas;
    this.inData = srcRas.getDataStorage();
    this.inSpan = srcRas.getScanlineStride();
    this.inOff = srcRas.getDataOffset(0);
}
 
Example 38
Project: openjdk-jdk10   File: OddPaletteTest.java   Source Code and License 5 votes vote down vote up
private static BufferedImage createTestImage(int paletteSize) {
    byte[] r = new byte[paletteSize];
    byte[] g = new byte[paletteSize];
    byte[] b = new byte[paletteSize];

    int shift = 256 / paletteSize;
    for (int i = 0; i < paletteSize; i++) {
        r[i] = g[i] = b[i] = (byte)(shift * i);
    }

    int numBits = getNumBits(paletteSize);

    System.out.println("num of bits " + numBits);

    IndexColorModel icm =
        new IndexColorModel(numBits, paletteSize,  r, g, b);

    BufferedImage img = new BufferedImage(w, h,
                                          BufferedImage.TYPE_BYTE_INDEXED,
                                          icm);
    Graphics2D  g2d = img.createGraphics();
    g2d.setColor(Color.white);
    g2d.fillRect(0, 0, w, h);
    g2d.setColor(Color.black);
    g2d.drawLine(0, 0, w, h);
    g2d.drawLine(0, h, w, 0);

    return img;
}
 
Example 39
Project: openjdk-jdk10   File: BufferedBufImgOps.java   Source Code and License 5 votes vote down vote up
/**************************** RescaleOp support *****************************/

    public static boolean isRescaleOpValid(RescaleOp rop,
                                           BufferedImage srcImg)
    {
        int numFactors = rop.getNumFactors();
        ColorModel srcCM = srcImg.getColorModel();

        if (srcCM instanceof IndexColorModel) {
            throw new
                IllegalArgumentException("Rescaling cannot be "+
                                         "performed on an indexed image");
        }
        if (numFactors != 1 &&
            numFactors != srcCM.getNumColorComponents() &&
            numFactors != srcCM.getNumComponents())
        {
            throw new IllegalArgumentException("Number of scaling constants "+
                                               "does not equal the number of"+
                                               " of color or color/alpha "+
                                               " components");
        }

        int csType = srcCM.getColorSpace().getType();
        if (csType != ColorSpace.TYPE_RGB &&
            csType != ColorSpace.TYPE_GRAY)
        {
            // Not prepared to deal with other color spaces
            return false;
        }

        if (numFactors == 2 || numFactors > 4) {
            // Not really prepared to handle this at the native level, so...
            return false;
        }

        return true;
    }
 
Example 40
Project: openjdk-jdk10   File: DrawBitmaskToSurfaceTest.java   Source Code and License 5 votes vote down vote up
private static Image createTestImage() {
    byte[] r = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0xff};
    byte[] g = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0x00};
    byte[] b = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0x00};

    IndexColorModel icm = new IndexColorModel(2, 4, r, g, b, 3);

    BufferedImage img = new BufferedImage(100, 100,
                                          BufferedImage.TYPE_BYTE_INDEXED,
                                          icm);
    return img;
}
 
Example 41
Project: jtk   File: ColorMap.java   Source Code and License 5 votes vote down vote up
/**
 * Gets a linear hue color model for the specified hues and alpha.
 * Hues equal to 0.00, 0.33, and 0.67, and 1.00 correspond
 * approximately to the colors red, green, blue, and red, respectively.
 * @param h0 the hue corresponding to index value 0.
 * @param h255 the hue corresponding to index value 255.
 * @param alpha the opacity for all colors in this color model.
 * @return the color model.
 */
public static IndexColorModel getHue(double h0, double h255, double alpha) {
  Color[] c = new Color[256];
  int a = (int)(0.5+max(0.0,min(1.0,alpha))*255);
  for (int i=0; i<256; ++i) {
    float h = (float)(h0+i*(h255-h0)/255.0);
    Color rgb = Color.getHSBColor(h,1.0f,1.0f);
    c[i] = new Color(rgb.getRed(),rgb.getGreen(),rgb.getBlue(),a);
  }
  return makeIndexColorModel(c);
}
 
Example 42
Project: jtk   File: ColorMap.java   Source Code and License 5 votes vote down vote up
/**
 * Returns an index color model for the specified array of 256 colors.
 * @param c array[256] of colors.
 * @return the index color model.
 */
public static IndexColorModel makeIndexColorModel(Color[] c) {
  if (hasAlpha(c)) {
    return new IndexColorModel(8,256,
      getReds(c),getGreens(c),getBlues(c),getAlphas(c));
  } else {
    return new IndexColorModel(8,256,
      getReds(c),getGreens(c),getBlues(c));
  }
}
 
Example 43
Project: imagingbook-common   File: LookupTables.java   Source Code and License 5 votes vote down vote up
/**
 * Lists the contents of the lookup-table currently associated
 * with the specified image.
 * 
 * @param ip The image.
 */
public static void listCurrentLut(ImageProcessor ip) {
	ColorModel cm = ip.getCurrentColorModel();
	IndexColorModel icm = (IndexColorModel) cm;
	int mapSize = icm.getMapSize();
	byte[] reds = new byte[mapSize];
	byte[] grns = new byte[mapSize];
	byte[] blus = new byte[mapSize];
	icm.getReds(reds);
	icm.getGreens(grns);
	icm.getBlues(blus);
	for (int i = 0; i < mapSize; i++) {
		IJ.log(String.format("%3d: %3d %3d %3d", i, reds[i] & 0xFF, grns[i] & 0xFF, blus[i] & 0xFF));
	}
}
 
Example 44
Project: jdk8u-jdk   File: X11PMBlitLoops.java   Source Code and License 5 votes vote down vote up
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy, int w, int h)
{
    Blit blit = Blit.getFromCache(src.getSurfaceType(),
                                  CompositeType.SrcNoEa,
                                  dstType);
    blit.Blit(src, dst, comp, clip, sx, sy, dx, dy, w, h);
    updateBitmask(src, dst,
                  src.getColorModel() instanceof IndexColorModel);
}
 
Example 45
Project: jtk   File: ImagePanel.java   Source Code and License 5 votes vote down vote up
private void loadTexture(int js, int jt) {
  int ks = js*(_ls-1);
  int kt = jt*(_lt-1);
  int ls = min(_ls,_ns-ks);
  int lt = min(_lt,_nt-kt);
  if (_axis==Axis.X) {
    _f.get12(lt,ls,kt,ks,_kxmin,_floats);
  } else if (_axis==Axis.Y) {
    _f.get13(lt,ls,kt,_kymin,ks,_floats);
  } else if (_axis==Axis.Z) {
    _f.get23(lt,ls,_kzmin,kt,ks,_floats);
  }
  float fscale = 255.0f/(_clipMax-_clipMin);
  float fshift = _clipMin;
  IndexColorModel icm = _colorMap.getColorModel();
  for (int is=0; is<ls; ++is) {
    for (int it=0; it<lt; ++it) {
      float fi = (_floats[is][it]-fshift)*fscale;
      if (fi<0.0f)
        fi = 0.0f;
      if (fi>255.0f)
        fi = 255.0f;
      int i = (int)(fi+0.5f);
      int r = icm.getRed(i);
      int g = icm.getGreen(i);
      int b = icm.getBlue(i);
      int a = icm.getAlpha(i);
      int p = (r&0xff)|((g&0xff)<<8)|((b&0xff)<<16)|((a&0xff)<<24);
      _pixels.put(is+it*_ls,p);
    }
  }
  glPixelStorei(GL_UNPACK_ALIGNMENT,1);
  GlTextureName tn = _tn[jt][js];
  glBindTexture(GL_TEXTURE_2D,tn.name());
  glTexSubImage2D(
    GL_TEXTURE_2D,0,0,0,_ls,_lt,GL_RGBA,GL_UNSIGNED_BYTE,_pixels);
  glBindTexture(GL_TEXTURE_2D,0);
}
 
Example 46
Project: jdk8u-jdk   File: LUTCompareTest.java   Source Code and License 5 votes vote down vote up
private static BufferedImage createFrame(int[] palette) {
    IndexColorModel icm = new IndexColorModel(getNumBits(palette.length),
        palette.length, palette, 0, false, -1, DataBuffer.TYPE_BYTE);
    WritableRaster wr = icm.createCompatibleWritableRaster(w, h);
    int[] samples = new int[w * h];
    Arrays.fill(samples, 0);
    wr.setSamples(0, 0, w, h, 0, samples);

    BufferedImage img = new BufferedImage(icm, wr, false, null);
    return img;
}
 
Example 47
Project: Image-Stegano   File: ImageStegano.java   Source Code and License 5 votes vote down vote up
private void showThresholdFrame() {
    if (originalImage != null) {
        currentImage = imageUtility.copyImage(originalImage);
        ColorModel colorModel = currentImage.getColorModel();
        if (colorModel instanceof IndexColorModel) {
            nameLabel.setText("Not applicable for indexed image");
            return;
        }
        thresholdFrame.setBounds(0, 0, 400, 148);
        thresholdFrame.setVisible(true);
        currentImage = imageUtility.thresholdImage(currentImage, 50);
        imageLabel.setIcon(new ImageIcon(currentImage));
    }
}
 
Example 48
Project: Image-Stegano   File: ColourMap.java   Source Code and License 5 votes vote down vote up
public BufferedImage changeColourMap(BufferedImage userSpaceImage, 
        IndexColorModel customIndexColorModel) {
    ColorModel originalCM = userSpaceImage.getColorModel();
    if (originalCM instanceof IndexColorModel) {
        boolean isAlphaPremultiplied = userSpaceImage.isAlphaPremultiplied();
        WritableRaster raster = userSpaceImage.copyData(null);
        BufferedImage newImage = new BufferedImage(customIndexColorModel, 
                raster, isAlphaPremultiplied, null);
        return newImage;
    } else {
        return null;
    }
}
 
Example 49
Project: OpenJSharp   File: TexturePaintContext.java   Source Code and License 5 votes vote down vote up
public static boolean isFilterableICM(ColorModel cm) {
    if (cm instanceof IndexColorModel) {
        IndexColorModel icm = (IndexColorModel) cm;
        if (icm.getMapSize() <= 256) {
            return true;
        }
    }
    return false;
}
 
Example 50
Project: OpenJSharp   File: TexturePaintContext.java   Source Code and License 5 votes vote down vote up
public ByteFilter(ByteInterleavedRaster srcRas, ColorModel cm,
                  AffineTransform xform, int maxw)
{
    super((cm.getTransparency() == Transparency.OPAQUE
           ? xrgbmodel : argbmodel),
          xform, srcRas.getWidth(), srcRas.getHeight(), maxw);
    this.inPalette = new int[256];
    ((IndexColorModel) cm).getRGBs(this.inPalette);
    this.srcRas = srcRas;
    this.inData = srcRas.getDataStorage();
    this.inSpan = srcRas.getScanlineStride();
    this.inOff = srcRas.getDataOffset(0);
}
 
Example 51
Project: OpenJSharp   File: BufImgSurfaceData.java   Source Code and License 5 votes vote down vote up
/**
 * Initializes the native Ops pointer.
 */
protected native void initRaster(Object theArray,
                                 int offset,
                                 int bitoffset,
                                 int width,
                                 int height,
                                 int pixStr,
                                 int scanStr,
                                 IndexColorModel icm);
 
Example 52
Project: OpenJSharp   File: JFIFMarkerSegment.java   Source Code and License 5 votes vote down vote up
BufferedImage getThumbnail(ImageInputStream iis,
                           JPEGImageReader reader)
    throws IOException {
    iis.mark();
    iis.seek(streamPos);
    // read the palette
    byte [] palette = new byte [PALETTE_SIZE];
    float palettePart = ((float) PALETTE_SIZE) / getLength();
    readByteBuffer(iis,
                   palette,
                   reader,
                   palettePart,
                   0.0F);
    DataBufferByte buffer = new DataBufferByte(thumbWidth*thumbHeight);
    readByteBuffer(iis,
                   buffer.getData(),
                   reader,
                   1.0F-palettePart,
                   palettePart);
    iis.read();
    iis.reset();

    IndexColorModel cm = new IndexColorModel(8,
                                             256,
                                             palette,
                                             0,
                                             false);
    SampleModel sm = cm.createCompatibleSampleModel(thumbWidth,
                                                    thumbHeight);
    WritableRaster raster =
        Raster.createWritableRaster(sm, buffer, null);
    return new BufferedImage(cm,
                             raster,
                             false,
                             null);
}
 
Example 53
Project: openjdk-jdk10   File: GDIWindowSurfaceData.java   Source Code and License 5 votes vote down vote up
public static SurfaceType getSurfaceType(ColorModel cm) {
    switch (cm.getPixelSize()) {
    case 32:
    case 24:
        if (cm instanceof DirectColorModel) {
            if (((DirectColorModel)cm).getRedMask() == 0xff0000) {
                return IntRgbGdi;
            } else {
                return SurfaceType.IntRgbx;
            }
        } else {
            return ThreeByteBgrGdi;
        }
    case 15:
        return Ushort555RgbGdi;
    case 16:
        if ((cm instanceof DirectColorModel) &&
            (((DirectColorModel)cm).getBlueMask() == 0x3e))
        {
            return SurfaceType.Ushort555Rgbx;
        } else {
            return Ushort565RgbGdi;
        }
    case 8:
        if (cm.getColorSpace().getType() == ColorSpace.TYPE_GRAY &&
            cm instanceof ComponentColorModel) {
            return SurfaceType.ByteGray;
        } else if (cm instanceof IndexColorModel &&
                   isOpaqueGray((IndexColorModel)cm)) {
            return SurfaceType.Index8Gray;
        } else {
            return SurfaceType.ByteIndexedOpaque;
        }
    default:
        throw new sun.java2d.InvalidPipeException("Unsupported bit " +
                                                  "depth: " +
                                                  cm.getPixelSize());
    }
}
 
Example 54
Project: openjdk-jdk10   File: TexturePaintContext.java   Source Code and License 5 votes vote down vote up
public static boolean isFilterableICM(ColorModel cm) {
    if (cm instanceof IndexColorModel) {
        IndexColorModel icm = (IndexColorModel) cm;
        if (icm.getMapSize() <= 256) {
            return true;
        }
    }
    return false;
}
 
Example 55
Project: OpenJSharp   File: GDIWindowSurfaceData.java   Source Code and License 5 votes vote down vote up
public static SurfaceType getSurfaceType(ColorModel cm) {
    switch (cm.getPixelSize()) {
    case 32:
    case 24:
        if (cm instanceof DirectColorModel) {
            if (((DirectColorModel)cm).getRedMask() == 0xff0000) {
                return IntRgbGdi;
            } else {
                return SurfaceType.IntRgbx;
            }
        } else {
            return ThreeByteBgrGdi;
        }
    case 15:
        return Ushort555RgbGdi;
    case 16:
        if ((cm instanceof DirectColorModel) &&
            (((DirectColorModel)cm).getBlueMask() == 0x3e))
        {
            return SurfaceType.Ushort555Rgbx;
        } else {
            return Ushort565RgbGdi;
        }
    case 8:
        if (cm.getColorSpace().getType() == ColorSpace.TYPE_GRAY &&
            cm instanceof ComponentColorModel) {
            return SurfaceType.ByteGray;
        } else if (cm instanceof IndexColorModel &&
                   isOpaqueGray((IndexColorModel)cm)) {
            return SurfaceType.Index8Gray;
        } else {
            return SurfaceType.ByteIndexedOpaque;
        }
    default:
        throw new sun.java2d.InvalidPipeException("Unsupported bit " +
                                                  "depth: " +
                                                  cm.getPixelSize());
    }
}
 
Example 56
Project: OpenJSharp   File: X11PMBlitLoops.java   Source Code and License 5 votes vote down vote up
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy, int w, int h)
{
    Blit blit = Blit.getFromCache(src.getSurfaceType(),
                                  CompositeType.SrcNoEa,
                                  dstType);
    blit.Blit(src, dst, comp, clip, sx, sy, dx, dy, w, h);
    updateBitmask(src, dst,
                  src.getColorModel() instanceof IndexColorModel);
}
 
Example 57
Project: jdk8u-jdk   File: TexturePaintContext.java   Source Code and License 5 votes vote down vote up
public static boolean isFilterableICM(ColorModel cm) {
    if (cm instanceof IndexColorModel) {
        IndexColorModel icm = (IndexColorModel) cm;
        if (icm.getMapSize() <= 256) {
            return true;
        }
    }
    return false;
}
 
Example 58
Project: jdk8u-jdk   File: TexturePaintContext.java   Source Code and License 5 votes vote down vote up
public ByteFilter(ByteInterleavedRaster srcRas, ColorModel cm,
                  AffineTransform xform, int maxw)
{
    super((cm.getTransparency() == Transparency.OPAQUE
           ? xrgbmodel : argbmodel),
          xform, srcRas.getWidth(), srcRas.getHeight(), maxw);
    this.inPalette = new int[256];
    ((IndexColorModel) cm).getRGBs(this.inPalette);
    this.srcRas = srcRas;
    this.inData = srcRas.getDataStorage();
    this.inSpan = srcRas.getScanlineStride();
    this.inOff = srcRas.getDataOffset(0);
}
 
Example 59
Project: jdk8u-jdk   File: BufferedBufImgOps.java   Source Code and License 5 votes vote down vote up
/**************************** RescaleOp support *****************************/

    public static boolean isRescaleOpValid(RescaleOp rop,
                                           BufferedImage srcImg)
    {
        int numFactors = rop.getNumFactors();
        ColorModel srcCM = srcImg.getColorModel();

        if (srcCM instanceof IndexColorModel) {
            throw new
                IllegalArgumentException("Rescaling cannot be "+
                                         "performed on an indexed image");
        }
        if (numFactors != 1 &&
            numFactors != srcCM.getNumColorComponents() &&
            numFactors != srcCM.getNumComponents())
        {
            throw new IllegalArgumentException("Number of scaling constants "+
                                               "does not equal the number of"+
                                               " of color or color/alpha "+
                                               " components");
        }

        int csType = srcCM.getColorSpace().getType();
        if (csType != ColorSpace.TYPE_RGB &&
            csType != ColorSpace.TYPE_GRAY)
        {
            // Not prepared to deal with other color spaces
            return false;
        }

        if (numFactors == 2 || numFactors > 4) {
            // Not really prepared to handle this at the native level, so...
            return false;
        }

        return true;
    }
 
Example 60
Project: openjdk-jdk10   File: WPrinterJob.java   Source Code and License 5 votes vote down vote up
protected void drawDIBImage(byte[] image,
                            float destX, float destY,
                            float destWidth, float destHeight,
                            float srcX, float srcY,
                            float srcWidth, float srcHeight,
                            int sampleBitsPerPixel,
                            IndexColorModel icm) {
    int bitCount = 24;
    byte[] bmiColors = null;

    if (icm != null) {
        bitCount = sampleBitsPerPixel;
        bmiColors = new byte[(1<<icm.getPixelSize())*4];
        for (int i=0;i<icm.getMapSize(); i++) {
            bmiColors[i*4+0]=(byte)(icm.getBlue(i)&0xff);
            bmiColors[i*4+1]=(byte)(icm.getGreen(i)&0xff);
            bmiColors[i*4+2]=(byte)(icm.getRed(i)&0xff);
        }
    }

    drawDIBImage(getPrintDC(), image,
                 destX, destY,
                 destWidth, destHeight,
                 srcX, srcY,
                 srcWidth, srcHeight,
                 bitCount, bmiColors);
}