Java Code Examples for java.awt.image.ComponentColorModel

The following are top voted examples for showing how to use java.awt.image.ComponentColorModel. 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: openjdk-jdk10   File: IndexingTest.java   Source Code and License 7 votes vote down vote up
protected static BufferedImage createComponentImage(int w, int h,
                                                    ComponentColorModel cm)
{
    WritableRaster wr = cm.createCompatibleWritableRaster(w, h);

    BufferedImage img = new BufferedImage(cm, wr, false, null);
    Graphics2D g = img.createGraphics();
    int width = w / 8;
    Color[] colors = new Color[8];
    colors[0] = Color.red;
    colors[1] = Color.green;
    colors[2] = Color.blue;
    colors[3] = Color.white;
    colors[4] = Color.black;
    colors[5] = new Color(0x80, 0x80, 0x80, 0x00);
    colors[6] = Color.yellow;
    colors[7] = Color.cyan;

    for (int i = 0; i < 8; i++) {
        g.setColor(colors[i]);
        g.fillRect(i * width, 0, width, h);
    }
    return img;
}
 
Example 2
Project: OpenJSharp   File: ImageTypeSpecifier.java   Source Code and License 6 votes vote down vote up
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
Example 3
Project: DicomViewer   File: OpenCLWithJOCL.java   Source Code and License 6 votes vote down vote up
BufferedImage createFloatBufferedImage(int w, int h, int bands) {
    // Define dimensions and layout of the image
    //int bands = 4; // 4 bands for ARGB, 3 for RGB etc
    int[] bandOffsets = {0, 1, 2, 3}; // length == bands, 0 == R, 1 == G, 2 == B and 3 == A

    // Create a TYPE_FLOAT sample model (specifying how the pixels are stored)
    SampleModel sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_FLOAT, w, h, bands, w  * bands, bandOffsets);
    // ...and data buffer (where the pixels are stored)
    DataBuffer buffer = new DataBufferFloat(w * h * bands);

    // Wrap it in a writable raster
    WritableRaster raster = Raster.createWritableRaster(sampleModel, buffer, null);

    // Create a color model compatible with this sample model/raster (TYPE_FLOAT)
    // Note that the number of bands must equal the number of color components in the 
    // color space (3 for RGB) + 1 extra band if the color model contains alpha 
    ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel colorModel = new ComponentColorModel(colorSpace, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_FLOAT);

    // And finally create an image with this raster
    return new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
}
 
Example 4
Project: jdk8u-jdk   File: ImageTypeSpecifier.java   Source Code and License 6 votes vote down vote up
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
Example 5
Project: openjdk-jdk10   File: TIFFDecompressor.java   Source Code and License 6 votes vote down vote up
/**
 * Create a {@code ComponentColorModel} for use in creating
 * an {@code ImageTypeSpecifier}.
 */
// This code was inspired by the method of the same name in
// javax.imageio.ImageTypeSpecifier
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int[] bitsPerSample,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    return new ComponentColorModel(colorSpace,
                                   bitsPerSample,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
Example 6
Project: openjdk-jdk10   File: ImageTypeSpecifier.java   Source Code and License 6 votes vote down vote up
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
Example 7
Project: openjdk-jdk10   File: ComponentColorModelEqualsTest.java   Source Code and License 6 votes vote down vote up
private static void verifyEquals(ComponentColorModel m1,
                                 ComponentColorModel 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"
                + " ComponentColorModels");
    }
}
 
Example 8
Project: openjdk-jdk10   File: ComponentColorModelEqualsTest.java   Source Code and License 6 votes vote down vote up
private static void testConstructor1() {
    /*
     * verify equality with constructor
     * ComponentColorModel(ColorSpace colorSpace,
     *                  int[] bits,
     *                  boolean hasAlpha,
     *                  boolean isAlphaPremultiplied,
     *                  int transparency,
     *                  int transferType)
     */
    ComponentColorModel model1 =
        new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                new int[] {8, 8, 8},
                                false,
                                false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    ComponentColorModel model2 =
        new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                new int[] {8, 8, 8},
                                false,
                                false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    verifyEquals(model1, model2);
}
 
Example 9
Project: openjdk-jdk10   File: ComponentColorModelEqualsTest.java   Source Code and License 6 votes vote down vote up
private static void testConstructor2() {
    /*
     * verify equality with constructor
     * ComponentColorModel(ColorSpace colorSpace,
     *                  boolean hasAlpha,
     *                  boolean isAlphaPremultiplied,
     *                  int transparency,
     *                  int transferType)
     */
    ComponentColorModel model1 =
        new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                false,
                                false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    ComponentColorModel model2 =
        new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                false,
                                false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    verifyEquals(model1, model2);
}
 
Example 10
Project: openjdk9   File: TIFFDecompressor.java   Source Code and License 6 votes vote down vote up
/**
 * Create a {@code ComponentColorModel} for use in creating
 * an {@code ImageTypeSpecifier}.
 */
// This code was copied from javax.imageio.ImageTypeSpecifier.
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
Example 11
Project: openjdk9   File: ImageTypeSpecifier.java   Source Code and License 6 votes vote down vote up
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
Example 12
Project: Java8CN   File: ImageTypeSpecifier.java   Source Code and License 6 votes vote down vote up
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
Example 13
Project: PhET   File: TextureLoader.java   Source Code and License 6 votes vote down vote up
/**
 * Create a new texture loader based on the game panel
 */
public TextureLoader() {
    glAlphaColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,8},
                                        true,
                                        false,
                                        ComponentColorModel.TRANSLUCENT,
                                        DataBuffer.TYPE_BYTE);

    glColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,0},
                                        false,
                                        false,
                                        ComponentColorModel.OPAQUE,
                                        DataBuffer.TYPE_BYTE);
}
 
Example 14
Project: Push2Display   File: FilterAsAlphaRed.java   Source Code and License 6 votes vote down vote up
/**
 * Construct an alpah channel from the given src, according to
 * the SVG masking rules.
 *
 * @param src The image to convert to an alpha channel (mask image)
 */
public FilterAsAlphaRed(CachableRed src) {
    super(new Any2LumRed(src),src.getBounds(), 
          new ComponentColorModel
              (ColorSpace.getInstance(ColorSpace.CS_GRAY),
               new int [] {8}, false, false,
               Transparency.OPAQUE, 
               DataBuffer.TYPE_BYTE),
          new PixelInterleavedSampleModel
              (DataBuffer.TYPE_BYTE, 
               src.getSampleModel().getWidth(),
               src.getSampleModel().getHeight(),
               1, src.getSampleModel().getWidth(),
               new int [] { 0 }),
          src.getTileGridXOffset(),
          src.getTileGridYOffset(),
          null);

    props.put(ColorSpaceHintKey.PROPERTY_COLORSPACE,
              ColorSpaceHintKey.VALUE_COLORSPACE_ALPHA);
}
 
Example 15
Project: Push2Display   File: FormatRed.java   Source Code and License 6 votes vote down vote up
public static CachableRed construct(CachableRed src, ColorModel cm) {
    ColorModel srcCM = src.getColorModel();
    if ((cm.hasAlpha() != srcCM.hasAlpha()) ||
        (cm.isAlphaPremultiplied() != srcCM.isAlphaPremultiplied()))
        return new FormatRed(src, cm);

    if (cm.getNumComponents() != srcCM.getNumComponents())
        throw new IllegalArgumentException
            ("Incompatible ColorModel given");


    if ((srcCM instanceof ComponentColorModel) &&
        (cm    instanceof ComponentColorModel))
        return src;

    if ((srcCM instanceof DirectColorModel) &&
        (cm    instanceof DirectColorModel))
        return src;

    return new FormatRed(src, cm);
}
 
Example 16
Project: Push2Display   File: MultiplyAlphaRed.java   Source Code and License 6 votes vote down vote up
public static ColorModel fixColorModel(CachableRed src) {
    ColorModel  cm = src.getColorModel();

    if (cm.hasAlpha())
        return cm;

    int b = src.getSampleModel().getNumBands()+1;
    int [] bits = new int[b];
    for (int i=0; i < b; i++)
        bits[i] = 8;

    ColorSpace cs = cm.getColorSpace();

    return new ComponentColorModel(cs, bits, true, false,
                                   Transparency.TRANSLUCENT,
                                   DataBuffer.TYPE_BYTE);
}
 
Example 17
Project: jdk8u_jdk   File: ImageTypeSpecifier.java   Source Code and License 6 votes vote down vote up
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
Example 18
Project: jdk8u_jdk   File: IndexingTest.java   Source Code and License 6 votes vote down vote up
protected static BufferedImage createComponentImage(int w, int h,
                                                    ComponentColorModel cm)
{
    WritableRaster wr = cm.createCompatibleWritableRaster(w, h);

    BufferedImage img = new BufferedImage(cm, wr, false, null);
    Graphics2D g = img.createGraphics();
    int width = w / 8;
    Color[] colors = new Color[8];
    colors[0] = Color.red;
    colors[1] = Color.green;
    colors[2] = Color.blue;
    colors[3] = Color.white;
    colors[4] = Color.black;
    colors[5] = new Color(0x80, 0x80, 0x80, 0x00);
    colors[6] = Color.yellow;
    colors[7] = Color.cyan;

    for (int i = 0; i < 8; i++) {
        g.setColor(colors[i]);
        g.fillRect(i * width, 0, width, h);
    }
    return img;
}
 
Example 19
Project: lookaside_java-1.8.0-openjdk   File: ImageTypeSpecifier.java   Source Code and License 6 votes vote down vote up
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
Example 20
Project: javify   File: PixmapVolatileImage.java   Source Code and License 6 votes vote down vote up
@Override
public BufferedImage getSnapshot()
{
  // TODO: Support non-24-bit resolutions.
  int w = pixmap.width;
  int h = pixmap.height;
  ZPixmap zpixmap = (ZPixmap) pixmap.image(0, 0, w, h, 0xffffffff,
                                           Image.Format.ZPIXMAP);
  DataBuffer buffer = new ZPixmapDataBuffer(zpixmap);
  SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, w, h, 4,
                                            w * 4,
                                            new int[]{0, 1, 2, 3 });
  ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
  ColorModel cm = new ComponentColorModel(cs, true, false,
                                          Transparency.OPAQUE,
                                          DataBuffer.TYPE_BYTE);
  WritableRaster raster = Raster.createWritableRaster(sm, buffer,
                                                      new Point(0, 0));
  return new BufferedImage(cm, raster, false, null);
}
 
Example 21
Project: project-bianca   File: Convert.java   Source Code and License 6 votes vote down vote up
public static BufferedImage toImage(int w, int h, byte[] data) {
	DataBuffer buffer = new DataBufferByte(data, w * h);

	int pixelStride = 3; // assuming r, g, b, r, g, b,...
	int scanlineStride = 3 * w; // no extra padding
	int[] bandOffsets = { 0, 1, 2 }; // r, g, b
	WritableRaster raster = Raster.createInterleavedRaster(buffer, w, h, scanlineStride, pixelStride, bandOffsets, null);

	ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
	boolean hasAlpha = false;
	boolean isAlphaPremultiplied = false;
	int transparency = Transparency.OPAQUE;
	int transferType = DataBuffer.TYPE_BYTE;
	ColorModel colorModel = new ComponentColorModel(colorSpace, hasAlpha, isAlphaPremultiplied, transparency, transferType);

	return new BufferedImage(colorModel, raster, isAlphaPremultiplied, null);
}
 
Example 22
Project: cmoct-sourcecode   File: ImageOperations.java   Source Code and License 6 votes vote down vote up
public static BufferedImage pixelsToImage(byte[] data, int w, int h) {
	DataBuffer buffer = new DataBufferByte(data, w * h);

	int pixelStride = 1; // assuming r, g, b,
							// skip, r, g, b,
							// skip...
	int scanlineStride = w; // no extra
							// padding
	int[] bandOffsets = { 0 }; // r, g, b
	WritableRaster raster = Raster.createInterleavedRaster(buffer, w, h,
			scanlineStride, pixelStride, bandOffsets, null);

	ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);
	boolean hasAlpha = false;
	boolean isAlphaPremultiplied = false;
	int transparency = Transparency.OPAQUE;
	int transferType = DataBuffer.TYPE_BYTE;
	ColorModel colorModel = new ComponentColorModel(colorSpace, hasAlpha,
			isAlphaPremultiplied, transparency, transferType);

	return new BufferedImage(colorModel, raster, isAlphaPremultiplied, null);
}
 
Example 23
Project: synergynet3.1   File: TrackerPanel.java   Source Code and License 6 votes vote down vote up
/**
 * Draw user depths.
 *
 * @param g2d
 *            the g2d
 */
private void drawUserDepths(Graphics2D g2d)
{ // Create BufferedImage using
	// the depth image bytes and
	// a colour model, then draw
	// it
	// define an 8-bit RGB channel colour model
	ColorModel colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[]
	{ 8, 8, 8 }, false, false, ComponentColorModel.OPAQUE, DataBuffer.TYPE_BYTE);

	// fill the raster with the depth image bytes
	DataBufferByte dataBuffer = new DataBufferByte(imgbytes, imWidth * imHeight * 3);

	WritableRaster raster = Raster.createInterleavedRaster(dataBuffer, imWidth, imHeight, imWidth * 3, 3, new int[]
	{ 0, 1, 2 }, null);

	// combine colour model and raster to create a BufferedImage
	BufferedImage image = new BufferedImage(colorModel, raster, false, null);

	g2d.drawImage(image, 0, 0, null);
}
 
Example 24
Project: jvm-stm   File: PixmapVolatileImage.java   Source Code and License 6 votes vote down vote up
@Override
public BufferedImage getSnapshot()
{
  // TODO: Support non-24-bit resolutions.
  int w = pixmap.width;
  int h = pixmap.height;
  ZPixmap zpixmap = (ZPixmap) pixmap.image(0, 0, w, h, 0xffffffff,
                                           Image.Format.ZPIXMAP);
  DataBuffer buffer = new ZPixmapDataBuffer(zpixmap);
  SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, w, h, 4,
                                            w * 4,
                                            new int[]{0, 1, 2, 3 });
  ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
  ColorModel cm = new ComponentColorModel(cs, true, false,
                                          Transparency.OPAQUE,
                                          DataBuffer.TYPE_BYTE);
  WritableRaster raster = Raster.createWritableRaster(sm, buffer,
                                                      new Point(0, 0));
  return new BufferedImage(cm, raster, false, null);
}
 
Example 25
Project: Push2Display   File: FilterAsAlphaRed.java   Source Code and License 6 votes vote down vote up
/**
 * Construct an alpah channel from the given src, according to
 * the SVG masking rules.
 *
 * @param src The image to convert to an alpha channel (mask image)
 */
public FilterAsAlphaRed(CachableRed src) {
    super(new Any2LumRed(src),src.getBounds(), 
          new ComponentColorModel
              (ColorSpace.getInstance(ColorSpace.CS_GRAY),
               new int [] {8}, false, false,
               Transparency.OPAQUE, 
               DataBuffer.TYPE_BYTE),
          new PixelInterleavedSampleModel
              (DataBuffer.TYPE_BYTE, 
               src.getSampleModel().getWidth(),
               src.getSampleModel().getHeight(),
               1, src.getSampleModel().getWidth(),
               new int [] { 0 }),
          src.getTileGridXOffset(),
          src.getTileGridYOffset(),
          null);

    props.put(ColorSpaceHintKey.PROPERTY_COLORSPACE,
              ColorSpaceHintKey.VALUE_COLORSPACE_ALPHA);
}
 
Example 26
Project: Push2Display   File: FormatRed.java   Source Code and License 6 votes vote down vote up
public static CachableRed construct(CachableRed src, ColorModel cm) {
    ColorModel srcCM = src.getColorModel();
    if ((cm.hasAlpha() != srcCM.hasAlpha()) ||
        (cm.isAlphaPremultiplied() != srcCM.isAlphaPremultiplied()))
        return new FormatRed(src, cm);

    if (cm.getNumComponents() != srcCM.getNumComponents())
        throw new IllegalArgumentException
            ("Incompatible ColorModel given");


    if ((srcCM instanceof ComponentColorModel) &&
        (cm    instanceof ComponentColorModel))
        return src;

    if ((srcCM instanceof DirectColorModel) &&
        (cm    instanceof DirectColorModel))
        return src;

    return new FormatRed(src, cm);
}
 
Example 27
Project: Push2Display   File: MultiplyAlphaRed.java   Source Code and License 6 votes vote down vote up
public static ColorModel fixColorModel(CachableRed src) {
    ColorModel  cm = src.getColorModel();

    if (cm.hasAlpha())
        return cm;

    int b = src.getSampleModel().getNumBands()+1;
    int [] bits = new int[b];
    for (int i=0; i < b; i++)
        bits[i] = 8;

    ColorSpace cs = cm.getColorSpace();

    return new ComponentColorModel(cs, bits, true, false,
                                   Transparency.TRANSLUCENT,
                                   DataBuffer.TYPE_BYTE);
}
 
Example 28
Project: infobip-open-jdk-8   File: ImageTypeSpecifier.java   Source Code and License 6 votes vote down vote up
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
Example 29
Project: sambox   File: PageDrawer.java   Source Code and License 6 votes vote down vote up
private BufferedImage create2ByteGrayAlphaImage(int width, int height)
{
    /**
     * gray + alpha
     */
    int[] bandOffsets = new int[] { 1, 0 };
    int bands = bandOffsets.length;

    /**
     * Color Model usesd for raw GRAY + ALPHA
     */
    final ColorModel CM_GRAY_ALPHA = new ComponentColorModel(
            ColorSpace.getInstance(ColorSpace.CS_GRAY), true, false,
            Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);

    // Init data buffer of type byte
    DataBuffer buffer = new DataBufferByte(width * height * bands);

    // Wrap the data buffer in a raster
    WritableRaster raster = Raster.createInterleavedRaster(buffer, width, height,
            width * bands, bands, bandOffsets, new Point(0, 0));

    // Create a custom BufferedImage with the raster and a suitable color model
    return new BufferedImage(CM_GRAY_ALPHA, raster, false, null);
}
 
Example 30
Project: sambox   File: ShadingContext.java   Source Code and License 6 votes vote down vote up
/**
 * Constructor.
 *
 * @param shading the shading type to be used
 * @param cm the color model to be used
 * @param xform transformation for user to device space
 * @param matrix the pattern matrix concatenated with that of the parent content stream
 * @throws java.io.IOException if there is an error getting the color space
 * or doing background color conversion.
 */
public ShadingContext(PDShading shading, ColorModel cm, AffineTransform xform,
                      Matrix matrix) throws IOException
{
    this.shading = shading;
    shadingColorSpace = shading.getColorSpace();

    // create the output color model using RGB+alpha as color space
    ColorSpace outputCS = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    outputColorModel = new ComponentColorModel(outputCS, true, false, Transparency.TRANSLUCENT,
            DataBuffer.TYPE_BYTE);

    // get background values if available
    COSArray bg = shading.getBackground();
    if (bg != null)
    {
        background = bg.toFloatArray();
        rgbBackground = convertToRGB(background);
    }
}
 
Example 31
Project: sambox   File: PDColorSpace.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the (A)RGB equivalent of the given raster, using the given AWT color space to perform the conversion.
 * 
 * @param raster the source raster
 * @param colorSpace the AWT
 * @return an (A)RGB buffered image
 */
protected BufferedImage toRGBImageAWT(WritableRaster raster, ColorSpace colorSpace)
{
    //
    // WARNING: this method is performance sensitive, modify with care!
    //

    // ICC Profile color transforms are only fast when performed using ColorConvertOp
    ColorModel colorModel = new ComponentColorModel(colorSpace, false, false,
            Transparency.OPAQUE, raster.getDataBuffer().getDataType());

    BufferedImage src = new BufferedImage(colorModel, raster, false, null);
    BufferedImage dest = new BufferedImage(raster.getWidth(), raster.getHeight(),
            BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(src, dest);
    return dest;
}
 
Example 32
Project: jdk8u-dev-jdk   File: ImageTypeSpecifier.java   Source Code and License 6 votes vote down vote up
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
Example 33
Project: vectorgraphics2d   File: GraphicsUtilsTest.java   Source Code and License 6 votes vote down vote up
@Test
public void getAlphaImageReturnsWhiteImageForOpaqueInputWithBitmaskAlpha() {
	ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
	ColorModel colorModel = new ComponentColorModel(
			colorSpace, true, false, Transparency.BITMASK, DataBuffer.TYPE_BYTE);
	WritableRaster raster = Raster.createInterleavedRaster(
			DataBuffer.TYPE_BYTE, TEST_IMAGE_WIDTH, TEST_IMAGE_WIDTH, 4, null);
	BufferedImage image = new BufferedImage(
			colorModel, raster, colorModel.isAlphaPremultiplied(), null);
	Graphics g = image.getGraphics();
	g.setColor(Color.RED);
	g.fillRect(0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);

	BufferedImage result = GraphicsUtils.getAlphaImage(image);

	assertBufferedImageContentEquals(whiteGrayscaleImage, result);
}
 
Example 34
Project: pixymeta   File: ThumbnailResource.java   Source Code and License 6 votes vote down vote up
private void setThumbnailImage(ImageResourceID id, int dataType, int width, int height, int totalSize, byte[] thumbnailData) {
	// JFIF data in RGB format. For resource ID 1033 (0x0409) the data is in BGR format.
	if(dataType == Thumbnail.DATA_TYPE_KJpegRGB) {
		thumbnail.setImage(width, height, dataType, thumbnailData);
	} else if(dataType == Thumbnail.DATA_TYPE_KRawRGB) {
		// kRawRGB - NOT tested yet!
		//Create a BufferedImage
		DataBuffer db = new DataBufferByte(thumbnailData, totalSize);
		int[] off = {0, 1, 2};//RGB band offset, we have 3 bands
		if(id == ImageResourceID.THUMBNAIL_RESOURCE_PS4)
			off = new int[]{2, 1, 0}; // RGB band offset for BGR for photoshop4.0 BGR format
		int numOfBands = 3;
		int trans = Transparency.OPAQUE;
			
		WritableRaster raster = Raster.createInterleavedRaster(db, width, height, paddedRowBytes, numOfBands, off, null);
		ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, trans, DataBuffer.TYPE_BYTE);
   		
		thumbnail.setImage(new BufferedImage(cm, raster, false, null));
	} else
		throw new UnsupportedOperationException("Unsupported IRB thumbnail data type: " + dataType);
}
 
Example 35
Project: feathers-sdk   File: FilterAsAlphaRed.java   Source Code and License 6 votes vote down vote up
/**
 * Construct an alpah channel from the given src, according to
 * the SVG masking rules.
 *
 * @param src The image to convert to an alpha channel (mask image)
 */
public FilterAsAlphaRed(CachableRed src) {
    super(new Any2LumRed(src),src.getBounds(), 
          new ComponentColorModel
              (ColorSpace.getInstance(ColorSpace.CS_GRAY),
               new int [] {8}, false, false,
               Transparency.OPAQUE, 
               DataBuffer.TYPE_BYTE),
          new PixelInterleavedSampleModel
              (DataBuffer.TYPE_BYTE, 
               src.getSampleModel().getWidth(),
               src.getSampleModel().getHeight(),
               1, src.getSampleModel().getWidth(),
               new int [] { 0 }),
          src.getTileGridXOffset(),
          src.getTileGridYOffset(),
          null);

    props.put(ColorSpaceHintKey.PROPERTY_COLORSPACE,
              ColorSpaceHintKey.VALUE_COLORSPACE_ALPHA);
}
 
Example 36
Project: feathers-sdk   File: FormatRed.java   Source Code and License 6 votes vote down vote up
public static CachableRed construct(CachableRed src, ColorModel cm) {
    ColorModel srcCM = src.getColorModel();
    if ((cm.hasAlpha() != srcCM.hasAlpha()) ||
        (cm.isAlphaPremultiplied() != srcCM.isAlphaPremultiplied()))
        return new FormatRed(src, cm);

    if (cm.getNumComponents() != srcCM.getNumComponents())
        throw new IllegalArgumentException
            ("Incompatible ColorModel given");


    if ((srcCM instanceof ComponentColorModel) &&
        (cm    instanceof ComponentColorModel))
        return src;

    if ((srcCM instanceof DirectColorModel) &&
        (cm    instanceof DirectColorModel))
        return src;

    return new FormatRed(src, cm);
}
 
Example 37
Project: feathers-sdk   File: MultiplyAlphaRed.java   Source Code and License 6 votes vote down vote up
public static ColorModel fixColorModel(CachableRed src) {
    ColorModel  cm = src.getColorModel();

    if (cm.hasAlpha())
        return cm;

    int b = src.getSampleModel().getNumBands()+1;
    int [] bits = new int[b];
    for (int i=0; i < b; i++)
        bits[i] = 8;

    ColorSpace cs = cm.getColorSpace();

    return new ComponentColorModel(cs, bits, true, false,
                                   Transparency.TRANSLUCENT,
                                   DataBuffer.TYPE_BYTE);
}
 
Example 38
Project: icafe   File: ThumbnailResource.java   Source Code and License 6 votes vote down vote up
private void setThumbnailImage(ImageResourceID id, int dataType, int width, int height, int totalSize, byte[] thumbnailData) {
	// JFIF data in RGB format. For resource ID 1033 (0x0409) the data is in BGR format.
	if(dataType == Thumbnail.DATA_TYPE_KJpegRGB) {
		thumbnail.setImage(width, height, dataType, thumbnailData);
	} else if(dataType == Thumbnail.DATA_TYPE_KRawRGB) {
		// kRawRGB - NOT tested yet!
		//Create a BufferedImage
		DataBuffer db = new DataBufferByte(thumbnailData, totalSize);
		int[] off = {0, 1, 2};//RGB band offset, we have 3 bands
		if(id == ImageResourceID.THUMBNAIL_RESOURCE_PS4)
			off = new int[]{2, 1, 0}; // RGB band offset for BGR for photoshop4.0 BGR format
		int numOfBands = 3;
		int trans = Transparency.OPAQUE;
			
		WritableRaster raster = Raster.createInterleavedRaster(db, width, height, paddedRowBytes, numOfBands, off, null);
		ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, trans, DataBuffer.TYPE_BYTE);
   		
		thumbnail.setImage(new BufferedImage(cm, raster, false, null));
	} else
		throw new UnsupportedOperationException("Unsupported IRB thumbnail data type: " + dataType);
}
 
Example 39
Project: icafe   File: PCXReader.java   Source Code and License 6 votes vote down vote up
private BufferedImage readTrueColorPcx(InputStream is) throws Exception {
  	byte brgb[] = IOUtils.readFully(is, 4096);
	byte pixels[] = new byte[bytesPerLine*NPlanes*height];

	/**
	 * A BufferedInputStream could have been constructed from the InputStream,
	 * but for maximum decoding speed, one time reading of the image data 
	 * into memory is ideal though this is memory consuming.
	 */
   	LOGGER.info("true color pcx image!");
		
	readScanLines(brgb, brgb.length, pixels);
	is.close();
	
 DataBuffer db = new DataBufferByte(pixels, pixels.length);
 int trans = Transparency.OPAQUE;
 int[] nBits = {8, 8, 8};						
 WritableRaster raster = Raster.createBandedRaster(db, width, height, bytesPerLine*3,
            new int[]{0, 0, 0}, new int[] {0, bytesPerLine, bytesPerLine*2}, null);
 ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), nBits, false, false,
            trans, DataBuffer.TYPE_BYTE);
 
 return new BufferedImage(cm, raster, false, null);
}
 
Example 40
Project: jdk7-jdk   File: ImageTypeSpecifier.java   Source Code and License 6 votes vote down vote up
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
Example 41
Project: OpenTeufel   File: Textures.java   Source Code and License 6 votes vote down vote up
private void dumpTextures(int no) {
    ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[]{8, 8, 8, 8}, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
    WritableRaster raster = cm.createCompatibleWritableRaster(MAP_TEXTURE_SIZE, MAP_TEXTURE_SIZE);
    ByteBuffer bb = ByteBuffer.allocate(MAP_TEXTURE_SIZE * MAP_TEXTURE_SIZE * 4);
    raster.setDataElements(0, 0, MAP_TEXTURE_SIZE, MAP_TEXTURE_SIZE, getBuffer(false).array());
    BufferedImage image = new BufferedImage(cm, raster, false, null);

    File imageFile = new File("texturemap-" + no + ".png");
    try {
        ImageIO.write(image, "png", imageFile);
    } catch (IOException ex) {
        Logger.getLogger(Textures.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (this.nextMap != null) {
        nextMap.dumpTextures(no + 1);
    }
}
 
Example 42
Project: s2tbx   File: S2ResamplerUtils.java   Source Code and License 6 votes vote down vote up
public static PlanarImage createFloatPlanarImage(float[] src, int width, int height){
    int[] bandOffsets = {0};

    SampleModel sampleModel = new PixelInterleavedSampleModel(TYPE_FLOAT, width, height, 1, width, bandOffsets);
    ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    ColorModel colorModel = new ComponentColorModel(colorSpace, false, false, Transparency.TRANSLUCENT, TYPE_FLOAT);
    PlanarImage opImage;
    DataBuffer buffer = new DataBufferFloat(width * height);

    // Wrap it in a writable raster
    WritableRaster raster = Raster.createWritableRaster(sampleModel, buffer, null);
    raster.setPixels(0, 0, width, height, src);

    // Create an image with this raster
    BufferedImage image = new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
    opImage = PlanarImage.wrapRenderedImage(image);
    return opImage;
}
 
Example 43
Project: pdf-renderer-noawt   File: ShaderType2.java   Source Code and License 6 votes vote down vote up
/** create a paint context */
public PaintContext createContext(ColorModel cm, 
                                  Rectangle deviceBounds, 
                                  Rectangle2D userBounds,
                                  AffineTransform xform,
                                  RenderingHints hints) 
{
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel model = new ComponentColorModel(cs, 
                                               true, 
                                               false, 
                                               Transparency.TRANSLUCENT,
                                               DataBuffer.TYPE_BYTE);
    
    Point2D devStart = xform.transform(getAxisStart(), null);
    Point2D devEnd = xform.transform(getAxisEnd(), null);
  
    return new Type2PaintContext(model, devStart, devEnd);
}
 
Example 44
Project: Wolf_game   File: TextureLoader.java   Source Code and License 6 votes vote down vote up
/**
 * Create a new texture loader based on the game panel
 */
public TextureLoader() {
    glAlphaColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,8},
                                        true,
                                        false,
                                        ComponentColorModel.TRANSLUCENT,
                                        DataBuffer.TYPE_BYTE);

    glColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,0},
                                        false,
                                        false,
                                        ComponentColorModel.OPAQUE,
                                        DataBuffer.TYPE_BYTE);
}
 
Example 45
Project: openjdk-source-code-learn   File: ImageTypeSpecifier.java   Source Code and License 6 votes vote down vote up
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
Example 46
Project: myrobotlab   File: Convert.java   Source Code and License 6 votes vote down vote up
public static BufferedImage toImage(int w, int h, byte[] data) {
  DataBuffer buffer = new DataBufferByte(data, w * h);

  int pixelStride = 3; // assuming r, g, b, r, g, b,...
  int scanlineStride = 3 * w; // no extra padding
  int[] bandOffsets = { 0, 1, 2 }; // r, g, b
  WritableRaster raster = Raster.createInterleavedRaster(buffer, w, h, scanlineStride, pixelStride, bandOffsets, null);

  ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
  boolean hasAlpha = false;
  boolean isAlphaPremultiplied = false;
  int transparency = Transparency.OPAQUE;
  int transferType = DataBuffer.TYPE_BYTE;
  ColorModel colorModel = new ComponentColorModel(colorSpace, hasAlpha, isAlphaPremultiplied, transparency, transferType);

  return new BufferedImage(colorModel, raster, isAlphaPremultiplied, null);
}
 
Example 47
Project: OLD-OpenJDK8   File: ImageTypeSpecifier.java   Source Code and License 6 votes vote down vote up
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
Example 48
Project: silvie   File: SmackerDecoder.java   Source Code and License 6 votes vote down vote up
/**
 * Encapsulates the video data from the last decoded frame in a
 * BufferedImage
 * 
 * @return A BufferedImage
 */
public BufferedImage getVideoDataBitmap() {
	int width = this.file.getHeader().width;
	int height = this.file.getHeader().height;
	byte[] iArray = new byte[width * height * 3];
	int j = 0;
	for (byte i : this.lastFrameData) {
		iArray[j] = (byte) this.currentPalette[i & 0xFF].getRed();
		iArray[j + 1] = (byte) this.currentPalette[i & 0xFF].getGreen();
		iArray[j + 2] = (byte) this.currentPalette[i & 0xFF].getBlue();
		j += 3;
	}
	DataBufferByte dbb = new DataBufferByte(iArray, iArray.length);
	ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] { 8, 8, 8 }, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
	return new BufferedImage(cm, Raster.createInterleavedRaster(dbb, width, height, width * 3, 3, new int[] { 0, 1, 2 }, null), false, null);
}
 
Example 49
Project: jLibuvc   File: Utils.java   Source Code and License 6 votes vote down vote up
public static BufferedImage getImage(UVCController.UVCFrame frame) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);

    // raster in "BGR" order like OpenCV..
    int[] offsets = new int[]{2, 1, 0};

    ColorModel cm = new ComponentColorModel(cs, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
    ComponentSampleModel csm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, frame.width(), frame.height(), 3, frame.width() * 3, offsets);
    WritableRaster wr = Raster.createWritableRaster(csm, null);

    BufferedImage bImage = new BufferedImage(cm, wr, false, null);
    DataBufferByte out = (DataBufferByte) bImage.getRaster().getDataBuffer();
    ByteBuffer buff = frame.data().capacity(frame.data_bytes()).asByteBuffer();

    copyByteBuffer(buff, frame.width() * 3, ByteBuffer.wrap(out.getData()), frame.width() * 3);
    return bImage;
}
 
Example 50
Project: cn1   File: ImageTypeSpecifier.java   Source Code and License 6 votes vote down vote up
private static ImageTypeSpecifier createGrayscale(int bits,
         int dataType,
         boolean isSigned,
         boolean hasAlpha,
         boolean isAlphaPremultiplied) {

    if ((bits != 1) && (bits != 2) && (bits != 4) && (bits != 8) && (bits != 16)) {
        throw new IllegalArgumentException();
    }

    ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);

    int numComponent = hasAlpha ? 2 : 1;
    int numBits[] = new int[numComponent];
    numBits[0] = bits;
    if (numComponent ==2) {
        numBits[1] = bits;
    }
    int transparency = hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;
    ColorModel model = new ComponentColorModel(colorSpace, numBits, hasAlpha, isAlphaPremultiplied, transparency, dataType);

    return new ImageTypeSpecifier(model, model.createCompatibleSampleModel(1, 1));
}
 
Example 51
Project: cn1   File: JavaBlitterTest.java   Source Code and License 6 votes vote down vote up
public final void test_from_BuffImg_to_FloatDataBuffer(){
    src = createImage(BufferedImage.TYPE_INT_RGB);

    DataBufferFloat dbf = new DataBufferFloat(w * h * 3);
    int offsets[] = new int[]{0,1,2};
    ComponentSampleModel csm = new ComponentSampleModel(DataBuffer.TYPE_FLOAT,
            w, h, 3, 3 * w, offsets);
    WritableRaster wr = new OrdinaryWritableRaster(csm, dbf, new Point(0, 0));
    ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, Transparency.OPAQUE, DataBuffer.TYPE_FLOAT);
    BufferedImage dst = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    Graphics2D g2d = dst.createGraphics();
    g2d.drawImage(src, 0, 0, null);

    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
        }
    }
}
 
Example 52
Project: JamVM-PH   File: PixmapVolatileImage.java   Source Code and License 6 votes vote down vote up
@Override
public BufferedImage getSnapshot()
{
  // TODO: Support non-24-bit resolutions.
  int w = pixmap.width;
  int h = pixmap.height;
  ZPixmap zpixmap = (ZPixmap) pixmap.image(0, 0, w, h, 0xffffffff,
                                           Image.Format.ZPIXMAP);
  DataBuffer buffer = new ZPixmapDataBuffer(zpixmap);
  SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, w, h, 4,
                                            w * 4,
                                            new int[]{0, 1, 2, 3 });
  ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
  ColorModel cm = new ComponentColorModel(cs, true, false,
                                          Transparency.OPAQUE,
                                          DataBuffer.TYPE_BYTE);
  WritableRaster raster = Raster.createWritableRaster(sm, buffer,
                                                      new Point(0, 0));
  return new BufferedImage(cm, raster, false, null);
}
 
Example 53
Project: example-jovr-lwjgl3-rift   File: TextureLoader.java   Source Code and License 6 votes vote down vote up
/** 
 * Create a new texture loader based on the game panel
 *
 * @param gl The GL content in which the textures should be loaded
 */
public TextureLoader() {
    glAlphaColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,8},
                                        true,
                                        false,
                                        ComponentColorModel.TRANSLUCENT,
                                        DataBuffer.TYPE_BYTE);
                                        
    glColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,0},
                                        false,
                                        false,
                                        ComponentColorModel.OPAQUE,
                                        DataBuffer.TYPE_BYTE);
}
 
Example 54
Project: openjdk-jdk7u-jdk   File: ImageTypeSpecifier.java   Source Code and License 6 votes vote down vote up
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
Example 55
Project: GPVM   File: TextureLoader.java   Source Code and License 6 votes vote down vote up
/**
 * Create a new texture loader based on the game panel
 */
public TextureLoader() {
    glAlphaColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,8},
                                        true,
                                        false,
                                        ComponentColorModel.TRANSLUCENT,
                                        DataBuffer.TYPE_BYTE);

    glColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,0},
                                        false,
                                        false,
                                        ComponentColorModel.OPAQUE,
                                        DataBuffer.TYPE_BYTE);
}
 
Example 56
Project: GPVM   File: TextureLoader.java   Source Code and License 6 votes vote down vote up
/**
 * Create a new texture loader based on the game panel
 */
public TextureLoader() {
    glAlphaColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,8},
                                        true,
                                        false,
                                        ComponentColorModel.TRANSLUCENT,
                                        DataBuffer.TYPE_BYTE);

    glColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,0},
                                        false,
                                        false,
                                        ComponentColorModel.OPAQUE,
                                        DataBuffer.TYPE_BYTE);
}
 
Example 57
Project: SpaceStationAlpha   File: TextureLoader.java   Source Code and License 6 votes vote down vote up
/**
 * Create a new texture loader based on the game panel
 */
public TextureLoader() {
    glAlphaColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,8},
                                        true,
                                        false,
                                        ComponentColorModel.TRANSLUCENT,
                                        DataBuffer.TYPE_BYTE);

    glColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,0},
                                        false,
                                        false,
                                        ComponentColorModel.OPAQUE,
                                        DataBuffer.TYPE_BYTE);
}
 
Example 58
Project: TeacherSmash   File: TextureLoader.java   Source Code and License 6 votes vote down vote up
/**
 * Create a new texture loader based on the game panel
 */
public TextureLoader() {
    glAlphaColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,8},
                                        true,
                                        false,
                                        ComponentColorModel.TRANSLUCENT,
                                        DataBuffer.TYPE_BYTE);

    glColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,0},
                                        false,
                                        false,
                                        ComponentColorModel.OPAQUE,
                                        DataBuffer.TYPE_BYTE);
}
 
Example 59
Project: classpath   File: PixmapVolatileImage.java   Source Code and License 6 votes vote down vote up
@Override
public BufferedImage getSnapshot()
{
  // TODO: Support non-24-bit resolutions.
  int w = pixmap.width;
  int h = pixmap.height;
  ZPixmap zpixmap = (ZPixmap) pixmap.image(0, 0, w, h, 0xffffffff,
                                           Image.Format.ZPIXMAP);
  DataBuffer buffer = new ZPixmapDataBuffer(zpixmap);
  SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, w, h, 4,
                                            w * 4,
                                            new int[]{0, 1, 2, 3 });
  ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
  ColorModel cm = new ComponentColorModel(cs, true, false,
                                          Transparency.OPAQUE,
                                          DataBuffer.TYPE_BYTE);
  WritableRaster raster = Raster.createWritableRaster(sm, buffer,
                                                      new Point(0, 0));
  return new BufferedImage(cm, raster, false, null);
}
 
Example 60
Project: freeVM   File: JavaBlitterTest.java   Source Code and License 6 votes vote down vote up
public final void test_from_BuffImg_to_FloatDataBuffer(){
    src = createImage(BufferedImage.TYPE_INT_RGB);

    DataBufferFloat dbf = new DataBufferFloat(w * h * 3);
    int offsets[] = new int[]{0,1,2};
    ComponentSampleModel csm = new ComponentSampleModel(DataBuffer.TYPE_FLOAT,
            w, h, 3, 3 * w, offsets);
    WritableRaster wr = new OrdinaryWritableRaster(csm, dbf, new Point(0, 0));
    ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), false, false, Transparency.OPAQUE, DataBuffer.TYPE_FLOAT);
    BufferedImage dst = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    Graphics2D g2d = dst.createGraphics();
    g2d.drawImage(src, 0, 0, null);

    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            assertEquals(src.getRGB(x, y), dst.getRGB(x, y));
        }
    }
}