java.awt.image.IndexColorModel Java Examples

The following examples show how to use java.awt.image.IndexColorModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XYZApp.java    From jdk8u-dev-jdk with GNU General Public License v2.0 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 #2
Source File: ShortHistogramTest.java    From hottub with GNU General Public License v2.0 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 #3
Source File: BufImgSurfaceData.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static SurfaceData createDataBP(BufferedImage bImg,
                                       SurfaceType sType,
                                       double scaleX, double scaleY)
{
    BytePackedRaster bpRaster =
        (BytePackedRaster)bImg.getRaster();
    BufImgSurfaceData bisd =
        new BufImgSurfaceData(bpRaster.getDataBuffer(), bImg, sType,
                              scaleX, scaleY);
    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 #4
Source File: BMPSubsamplingTest.java    From jdk8u60 with GNU General Public License v2.0 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 #5
Source File: ShortHistogramTest.java    From openjdk-8 with GNU General Public License v2.0 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 #6
Source File: GIFImageReader.java    From jdk1.8-source-analysis with Apache License 2.0 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 #7
Source File: XYZApp.java    From openjdk-8-source with GNU General Public License v2.0 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
Source File: ShortHistogramTest.java    From jdk8u-jdk with GNU General Public License v2.0 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 #9
Source File: QuicklookOlciOpImage.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * This method takes in input the list of all the sources and calculates the
 * total number of bands of the destination image.
 * 
 * @param sources List of the source images
 * @return the total number of the destination bands
 */
private static int totalNumBands(List sources)
{
   // Initialization
   int total = 0;
   // Cycle on all the sources
   for (int i = 0; i < sources.size(); i++)
   {
      RenderedImage image = (RenderedImage) sources.get(i);

      // If the source ColorModel is IndexColorModel, then the bands are
      // defined by its components
      if (image.getColorModel() instanceof IndexColorModel)
      {
         total += image.getColorModel().getNumComponents();
         // Else the bands are defined from the SampleModel
      }
      else
      {
         total += image.getSampleModel().getNumBands();
      }
   }
   // Total bands number
   return total;
}
 
Example #10
Source File: JFIFMarkerSegment.java    From JDKSourceCode1.8 with MIT 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 #11
Source File: BufImgSurfaceData.java    From TencentKona-8 with GNU General Public License v2.0 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 #12
Source File: BufImgSurfaceData.java    From jdk8u-jdk with GNU General Public License v2.0 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 #13
Source File: JFIFMarkerSegment.java    From openjdk-8 with GNU General Public License v2.0 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 #14
Source File: MyImageUtils.java    From spring-boot with Apache License 2.0 6 votes vote down vote up
static IndexColorModel createIndexColorModel() {
    BufferedImage ex = new BufferedImage(1, 1,
            BufferedImage.TYPE_BYTE_INDEXED);
    IndexColorModel icm = (IndexColorModel) ex.getColorModel();
    int SIZE = 256;
    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);
    java.util.Arrays.fill(a, (byte) 255);
    r[0] = g[0] = b[0] = a[0] = 0; // transparent
    return new IndexColorModel(8, SIZE, r, g, b, a);
}
 
Example #15
Source File: ShortHistogramTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 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 #16
Source File: BufImgSurfaceData.java    From jdk8u-jdk with GNU General Public License v2.0 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 #17
Source File: ICMColorDataTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void makeImage() {
    int scanLineBytes = WIDTH / PIXELS_IN_BYTE;
    if ((WIDTH & (PIXELS_IN_BYTE - 1)) != 0) {
        // Make sure all the pixels in a scan line fit
        scanLineBytes += 1;
    }

    byte[]     bits    = new byte[scanLineBytes * HEIGHT];
    DataBuffer dataBuf = new DataBufferByte(bits, bits.length, 0);
    SampleModel sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                              WIDTH, HEIGHT, BITS_PER_PIXEL);
    WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuf, null);
    IndexColorModel indexModel = new IndexColorModel(2, 2, RED, GREEN, BLUE);
    BufferedImage bufImage = new BufferedImage(indexModel, raster,
                                               indexModel.isAlphaPremultiplied(), null);

    Graphics g = bufImage.getGraphics();
    g.drawRect(0, 0, WIDTH - 1, HEIGHT - 1);
    g.dispose();
}
 
Example #18
Source File: JFIFMarkerSegment.java    From hottub with GNU General Public License v2.0 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 #19
Source File: GIFImageReader.java    From JDKSourceCode1.8 with MIT 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 #20
Source File: GIFImageReader.java    From jdk8u_jdk with GNU General Public License v2.0 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 #21
Source File: GIFImageReader.java    From openjdk-jdk9 with GNU General Public License v2.0 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 #22
Source File: PaletteBuilder.java    From jdk8u_jdk with GNU General Public License v2.0 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 #23
Source File: ShortHistogramTest.java    From openjdk-jdk8u with GNU General Public License v2.0 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 #24
Source File: BMPSubsamplingTest.java    From jdk8u-jdk with GNU General Public License v2.0 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 #25
Source File: BufImgSurfaceData.java    From dragonwell8_jdk with GNU General Public License v2.0 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 #26
Source File: XYZApp.java    From jdk8u_jdk with GNU General Public License v2.0 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 #27
Source File: ImageBuilder.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ColorModel convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
    int bits = fa.getInt(instance, "pixel_bits"); // NOI18N
    int[] cmap = fa.getIntArray(instance, "rgb", false);// NOI18N
    int size = fa.getInt(instance, "map_size"); // NOI18N
    int trans = fa.getInt(instance, "transparent_index"); // NOI18N
    int transferType = fa.getInt(instance, "transferType"); // NOI18N
    return new IndexColorModel(bits, size, cmap, 0, true, trans, transferType);
}
 
Example #28
Source File: GDIWindowSurfaceData.java    From jdk8u_jdk with GNU General Public License v2.0 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 #29
Source File: BufferedBufImgOps.java    From hottub with GNU General Public License v2.0 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 #30
Source File: TexturePaintContext.java    From openjdk-8 with GNU General Public License v2.0 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;
}