java.awt.image.DirectColorModel Java Examples

The following examples show how to use java.awt.image.DirectColorModel. 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: BufferedImageGraphicsConfig.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the color model associated with this configuration that
 * supports the specified transparency.
 */
public ColorModel getColorModel(int transparency) {

    if (model.getTransparency() == transparency) {
        return model;
    }
    switch (transparency) {
    case Transparency.OPAQUE:
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        return ColorModel.getRGBdefault();
    default:
        return null;
    }
}
 
Example #2
Source File: GLXGraphicsConfig.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
 
Example #3
Source File: CGLGraphicsConfig.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
 
Example #4
Source File: AbstractVideoCodec.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
/** Gets 24-bit RGB pixels from a buffer. Returns null if conversion failed. */
protected int[] getRGB24(Buffer buf) {
    if (buf.data instanceof int[]) {
        return (int[]) buf.data;
    }
    if (buf.data instanceof BufferedImage) {
        BufferedImage image = (BufferedImage) buf.data;
        if (image.getColorModel() instanceof DirectColorModel) {
            DirectColorModel dcm = (DirectColorModel) image.getColorModel();
            if (dcm.getBlueMask() == 0xff && dcm.getGreenMask() == 0xff00 && dcm.getRedMask() == 0xff0000) {
                if (image.getRaster().getDataBuffer() instanceof DataBufferInt) {
                    return ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
                }
            }
        }
        return image.getRGB(0, 0, //
                outputFormat.get(WidthKey), outputFormat.get(HeightKey), //
                null, 0, outputFormat.get(WidthKey));
    }
    return null;
}
 
Example #5
Source File: GLXGraphicsConfig.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
 
Example #6
Source File: WebP.java    From webp-imageio with Apache License 2.0 6 votes vote down vote up
private static byte[] extractDirectRGBInt( int aWidth, int aHeight, DirectColorModel aColorModel, SinglePixelPackedSampleModel aSampleModel, DataBufferInt aDataBuffer ) {
  byte[] out = new byte[ aWidth * aHeight * 3 ];

  int rMask = aColorModel.getRedMask();
  int gMask = aColorModel.getGreenMask();
  int bMask = aColorModel.getBlueMask();
  int rShift = getShift( rMask );
  int gShift = getShift( gMask );
  int bShift = getShift( bMask );
  int[] bank = aDataBuffer.getBankData()[ 0 ];
  int scanlineStride = aSampleModel.getScanlineStride();
  int scanIx = 0;
  for ( int b = 0, y = 0; y < aHeight; y++ ) {
    int pixIx = scanIx;
    for ( int x = 0; x < aWidth; x++, b += 3 ) {
      int pixel = bank[ pixIx++ ];
      out[ b ] = ( byte ) ( ( pixel & rMask ) >>> rShift );
      out[ b + 1 ] = ( byte ) ( ( pixel & gMask ) >>> gShift );
      out[ b + 2 ] = ( byte ) ( ( pixel & bMask ) >>> bShift );
    }
    scanIx += scanlineStride;
  }
  return out;
}
 
Example #7
Source File: WGLGraphicsConfig.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
 
Example #8
Source File: GLXGraphicsConfig.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
 
Example #9
Source File: D3DGraphicsConfig.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
 
Example #10
Source File: ImageLoader.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * This checks to see if two DirectColorModels are identical. Apparently the
 * "equals" method in DirectColorModel doesn't really work.
 */
private static boolean equals(DirectColorModel d1, DirectColorModel d2) {
	if (d1.getAlphaMask() != d2.getAlphaMask())
		return false;
	if (d1.getGreenMask() != d2.getGreenMask())
		return false;
	if (d1.getRedMask() != d2.getRedMask())
		return false;
	if (d1.getBlueMask() != d2.getBlueMask())
		return false;
	if (d1.getColorSpace() != d2.getColorSpace())
		return false;
	if (d1.isAlphaPremultiplied() != d2.isAlphaPremultiplied())
		return false;
	if (d1.getTransferType() != d2.getTransferType())
		return false;
	if (d1.getTransparency() != d2.getTransparency())
		return false;
	return true;
}
 
Example #11
Source File: DeviceSocketClient.java    From AndroidRobot with Apache License 2.0 6 votes vote down vote up
private static ImageData getImageData2(BufferedImage bufferedImage){
    DirectColorModel colorModel = (DirectColorModel) bufferedImage.getColorModel();
    //System.out.println("robot:" +colorModel.getRedMask() + " "+colorModel.getGreenMask() + " "+colorModel.getBlueMask());   
    PaletteData palette = new PaletteData(colorModel.getRedMask(), colorModel.getGreenMask(), colorModel
            .getBlueMask());
    ImageData data = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(), colorModel
            .getPixelSize(), palette);
    WritableRaster raster = bufferedImage.getRaster();
    int[] pixelArray = new int[3];
    for (int y = 0; y < data.height; y++) {
        for (int x = 0; x < data.width; x++) {
            raster.getPixel(x, y, pixelArray);
            int pixel = palette.getPixel(new RGB(pixelArray[0], pixelArray[1], pixelArray[2]));
            data.setPixel(x, y, pixel);
        }
    }
    return data;
}
 
Example #12
Source File: CGLGraphicsConfig.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
 
Example #13
Source File: BufferedImageGraphicsConfig.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the color model associated with this configuration that
 * supports the specified transparency.
 */
public ColorModel getColorModel(int transparency) {

    if (model.getTransparency() == transparency) {
        return model;
    }
    switch (transparency) {
    case Transparency.OPAQUE:
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        return ColorModel.getRGBdefault();
    default:
        return null;
    }
}
 
Example #14
Source File: PackedColorModelEqualsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void testConstructor2() {
    /*
     * verify equality with constructor
     * DirectColorModel(ColorSpace space, int bits, int rmask, int gmask,
     * int bmask, int amask, boolean isAlphaPremultiplied, int transferType)
     */
    DirectColorModel model1 =
        new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF,
                false, DataBuffer.TYPE_BYTE);
    DirectColorModel model2 =
        new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF,
                false, DataBuffer.TYPE_BYTE);
    verifyEquals(model1, model2);
}
 
Example #15
Source File: CGLGraphicsConfig.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
 
Example #16
Source File: BiomeExporter.java    From amidst with GNU General Public License v3.0 6 votes vote down vote up
public CustomRenderedImage(
		int worldX,
		int worldY,
		int width,
		int height,
		BiomeProfileSelection biomeProfileSelection,
		BiomeDataOracle biomeDataOracle,
		boolean useQuarterResolution,
		ProgressReporter<Entry<ProgressEntryType, Integer>> progressReporter) {
	this.useQuarterResolution = useQuarterResolution;
	this.resolutionFactor = useQuarterResolution ? 4 : 1;
	this.worldX = worldX;
	this.worldY = worldY;
	this.width = width;
	this.height = height;
	this.colorModel = new DirectColorModel(24, BITMASKS[0], BITMASKS[1], BITMASKS[2]);
	this.sampleModel = new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT, width, height, BITMASKS);
	this.biomeProfileSelection = biomeProfileSelection;
	this.biomeDataOracle = biomeDataOracle;
	this.progressReporter = progressReporter;
}
 
Example #17
Source File: PackedColorModelEqualsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void testMaskArrayEquality() {
    /*
     * Test with different maskArray values, since PackedColorModel
     * is abstract we use subclass DirectColorModel.
     */
    DirectColorModel model1 =
        new DirectColorModel(24, 0x00FF0000, 0x0000FF00, 0x000000FF);
    DirectColorModel model2 =
        new DirectColorModel(24, 0x000000FF, 0x0000FF00, 0x00FF0000);
    if (model1.equals(model2)) {
        throw new RuntimeException("equals() method is determining"
                + " ColorMap equality improperly");
    }
    if (model2.equals(model1)) {
        throw new RuntimeException("equals() method is determining"
                + " ColorMap equality improperly");
    }
}
 
Example #18
Source File: Win32GraphicsConfig.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the color model associated with this configuration that
 * supports the specified transparency.
 */
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        return getColorModel();
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        return ColorModel.getRGBdefault();
    default:
        return null;
    }
}
 
Example #19
Source File: ImageRepresentation.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
void createBufferedImage() {
    // REMIND:  Be careful!  Is this called everytime there is a
    // startProduction?  We only want to call it if it is new or
    // there is an error
    isDefaultBI = false;
    try {
        biRaster = cmodel.createCompatibleWritableRaster(width, height);
        bimage = createImage(cmodel, biRaster,
                             cmodel.isAlphaPremultiplied(), null);
    } catch (Exception e) {
        // Create a default image
        cmodel = ColorModel.getRGBdefault();
        biRaster = cmodel.createCompatibleWritableRaster(width, height);
        bimage = createImage(cmodel, biRaster, false, null);
    }
    int type = bimage.getType();

    if ((cmodel == ColorModel.getRGBdefault()) ||
           (type == BufferedImage.TYPE_INT_RGB) ||
           (type == BufferedImage.TYPE_INT_ARGB_PRE)) {
        isDefaultBI = true;
    }
    else if (cmodel instanceof DirectColorModel) {
        DirectColorModel dcm = (DirectColorModel) cmodel;
        if (dcm.getRedMask() == 0xff0000 &&
            dcm.getGreenMask() == 0xff00 &&
            dcm.getBlueMask()  == 0xff) {
            isDefaultBI = true;
        }
    }
}
 
Example #20
Source File: GDIWindowSurfaceData.java    From jdk8u60 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 #21
Source File: X11GraphicsConfig.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the color model associated with this configuration that
 * supports the specified transparency.
 */
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        return getColorModel();
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        return ColorModel.getRGBdefault();
    default:
        return null;
    }
}
 
Example #22
Source File: BMPReader.java    From icafe with Eclipse Public License 1.0 5 votes vote down vote up
private BufferedImage read32bitTrueColorBitmap(InputStream is) throws Exception { 
  	LOGGER.info("32 bits bitmap color image!");
	
	byte brgb[] = new byte[bytePerScanLine];
	int pix[] = new int[width*height];
      IOUtils.skipFully(is, bitmapHeader.dataOffSet - 54);
      
      if(alignment == BMPOptions.ALIGN_BOTTOM_UP) {
      	for(int i = 1, index = 0; i <= height; i++)	{
			IOUtils.readFully(is, brgb, 0, bytePerScanLine);
			index = width*(height-i);
			for(int j = 0, nindex = 0; j < width; j++) {
				pix[index++] = ((brgb[nindex++]&0xff)|((brgb[nindex++]&0xff)<<8)|((brgb[nindex++]&0xff)<<16)|(0xff<<24));
				nindex++;
			}
      	}
} else {
	for(int i = 0, index = 0; i < height; i++) {
			IOUtils.readFully(is, brgb, 0, bytePerScanLine);
			for(int j = 0, nindex = 0; j < width; j++) {
				pix[index++] = ((brgb[nindex++]&0xff)|((brgb[nindex++]&0xff)<<8)|((brgb[nindex++]&0xff)<<16)|(0xff<<24));
				nindex++;
			}
      	}
} 		
	
	is.close();

	//Create a BufferedImage
	DataBuffer db = new DataBufferInt(pix, pix.length);
	WritableRaster raster = Raster.createPackedRaster(db, width, height, width,  new int[] {0x00ff0000, 0x0000ff00, 0x000000ff}, null);
	ColorModel cm = new DirectColorModel(24, 0x00FF0000, 0x0000ff00, 0x000000ff);
		
	return new BufferedImage(cm, raster, false, null);
  }
 
Example #23
Source File: GLXGraphicsConfig.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public BufferedImage createCompatibleImage(int width, int height) {
    ColorModel model = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    WritableRaster
        raster = model.createCompatibleWritableRaster(width, height);
    return new BufferedImage(model, raster, model.isAlphaPremultiplied(),
                             null);
}
 
Example #24
Source File: ImageRepresentation.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public BufferedImage getOpaqueRGBImage() {
    if (bimage.getType() == BufferedImage.TYPE_INT_ARGB) {
        int w = bimage.getWidth();
        int h = bimage.getHeight();
        int size = w * h;

        // Note that we steal the data array here, but only for reading...
        DataBufferInt db = (DataBufferInt)biRaster.getDataBuffer();
        int[] pixels = SunWritableRaster.stealData(db, 0);

        for (int i = 0; i < size; i++) {
            if ((pixels[i] >>> 24) != 0xff) {
                return bimage;
            }
        }

        ColorModel opModel = new DirectColorModel(24,
                                                  0x00ff0000,
                                                  0x0000ff00,
                                                  0x000000ff);

        int bandmasks[] = {0x00ff0000, 0x0000ff00, 0x000000ff};
        WritableRaster opRaster = Raster.createPackedRaster(db, w, h, w,
                                                            bandmasks,
                                                            null);

        try {
            BufferedImage opImage = createImage(opModel, opRaster,
                                                false, null);
            return opImage;
        } catch (Exception e) {
            return bimage;
        }
    }
    return bimage;
}
 
Example #25
Source File: BlendComposite.java    From amodeus with GNU General Public License v2.0 5 votes vote down vote up
private static boolean checkComponentsOrder(ColorModel cm) {
    if (cm instanceof DirectColorModel && cm.getTransferType() == DataBuffer.TYPE_INT) {
        DirectColorModel directCM = (DirectColorModel) cm;
        return directCM.getRedMask() == 0x00FF0000 && directCM.getGreenMask() == 0x0000FF00 && directCM.getBlueMask() == 0x000000FF
                && (directCM.getNumComponents() != 4 || directCM.getAlphaMask() == 0xFF000000);
    }
    return false;
}
 
Example #26
Source File: X11GraphicsConfig.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the color model associated with this configuration that
 * supports the specified transparency.
 */
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        return getColorModel();
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        return ColorModel.getRGBdefault();
    default:
        return null;
    }
}
 
Example #27
Source File: ImageRepresentation.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public BufferedImage getOpaqueRGBImage() {
    if (bimage.getType() == BufferedImage.TYPE_INT_ARGB) {
        int w = bimage.getWidth();
        int h = bimage.getHeight();
        int size = w * h;

        // Note that we steal the data array here, but only for reading...
        DataBufferInt db = (DataBufferInt)biRaster.getDataBuffer();
        int[] pixels = SunWritableRaster.stealData(db, 0);

        for (int i = 0; i < size; i++) {
            if ((pixels[i] >>> 24) != 0xff) {
                return bimage;
            }
        }

        ColorModel opModel = new DirectColorModel(24,
                                                  0x00ff0000,
                                                  0x0000ff00,
                                                  0x000000ff);

        int bandmasks[] = {0x00ff0000, 0x0000ff00, 0x000000ff};
        WritableRaster opRaster = Raster.createPackedRaster(db, w, h, w,
                                                            bandmasks,
                                                            null);

        try {
            BufferedImage opImage = createImage(opModel, opRaster,
                                                false, null);
            return opImage;
        } catch (Exception e) {
            return bimage;
        }
    }
    return bimage;
}
 
Example #28
Source File: PrinterGraphicsConfig.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the color model associated with this configuration that
 * supports the specified transparency.
 */
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        return getColorModel();
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        return ColorModel.getRGBdefault();
    default:
        return null;
    }
}
 
Example #29
Source File: TexturePaintContext.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isFilterableDCM(ColorModel cm) {
    if (cm instanceof DirectColorModel) {
        DirectColorModel dcm = (DirectColorModel) cm;
        return (isMaskOK(dcm.getAlphaMask(), true) &&
                isMaskOK(dcm.getRedMask(), false) &&
                isMaskOK(dcm.getGreenMask(), false) &&
                isMaskOK(dcm.getBlueMask(), false));
    }
    return false;
}
 
Example #30
Source File: GDIWindowSurfaceData.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private GDIWindowSurfaceData(WComponentPeer peer, SurfaceType sType) {
    super(sType, peer.getDeviceColorModel());
    ColorModel cm = peer.getDeviceColorModel();
    this.peer = peer;
    int rMask = 0, gMask = 0, bMask = 0;
    int depth;
    switch (cm.getPixelSize()) {
    case 32:
    case 24:
        if (cm instanceof DirectColorModel) {
            depth = 32;
        } else {
            depth = 24;
        }
        break;
    default:
        depth = cm.getPixelSize();
    }
    if (cm instanceof DirectColorModel) {
        DirectColorModel dcm = (DirectColorModel)cm;
        rMask = dcm.getRedMask();
        gMask = dcm.getGreenMask();
        bMask = dcm.getBlueMask();
    }
    this.graphicsConfig =
        (Win32GraphicsConfig) peer.getGraphicsConfiguration();
    this.solidloops = graphicsConfig.getSolidLoops(sType);

    Win32GraphicsDevice gd =
        (Win32GraphicsDevice)graphicsConfig.getDevice();
    initOps(peer, depth, rMask, gMask, bMask, gd.getScreen());
    setBlitProxyKey(graphicsConfig.getProxyKey());
}