use of java.awt.image.ComponentColorModel in project jdk8u_jdk by JetBrains.
the class X11GraphicsConfig method createABGRCCM.
public static ComponentColorModel createABGRCCM() {
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
int[] nBits = { 8, 8, 8, 8 };
int[] bOffs = { 3, 2, 1, 0 };
return new ComponentColorModel(cs, nBits, true, true, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
}
use of java.awt.image.ComponentColorModel in project jdk8u_jdk by JetBrains.
the class HTMLCodec method imageToPlatformBytes.
@Override
protected byte[] imageToPlatformBytes(Image image, long format) throws IOException {
String mimeType = null;
if (format == CF_PNG) {
mimeType = "image/png";
} else if (format == CF_JFIF) {
mimeType = "image/jpeg";
}
if (mimeType != null) {
return imageToStandardBytes(image, mimeType);
}
int width = 0;
int height = 0;
if (image instanceof ToolkitImage) {
ImageRepresentation ir = ((ToolkitImage) image).getImageRep();
ir.reconstruct(ImageObserver.ALLBITS);
width = ir.getWidth();
height = ir.getHeight();
} else {
width = image.getWidth(null);
height = image.getHeight(null);
}
// Fix for 4919639.
// Some Windows native applications (e.g. clipbrd.exe) do not handle
// 32-bpp DIBs correctly.
// As a workaround we switched to 24-bpp DIBs.
// MSDN prescribes that the bitmap array for a 24-bpp should consist of
// 3-byte triplets representing blue, green and red components of a
// pixel respectively. Additionally each scan line must be padded with
// zeroes to end on a LONG data-type boundary. LONG is always 32-bit.
// We render the given Image to a BufferedImage of type TYPE_3BYTE_BGR
// with non-default scanline stride and pass the resulting data buffer
// to the native code to fill the BITMAPINFO structure.
int mod = (width * 3) % 4;
int pad = mod > 0 ? 4 - mod : 0;
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
int[] nBits = { 8, 8, 8 };
int[] bOffs = { 2, 1, 0 };
ColorModel colorModel = new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, width * 3 + pad, 3, bOffs, null);
BufferedImage bimage = new BufferedImage(colorModel, raster, false, null);
// Some Windows native applications (e.g. clipbrd.exe) do not understand
// top-down DIBs.
// So we flip the image vertically and create a bottom-up DIB.
AffineTransform imageFlipTransform = new AffineTransform(1, 0, 0, -1, 0, height);
Graphics2D g2d = bimage.createGraphics();
try {
g2d.drawImage(image, imageFlipTransform, null);
} finally {
g2d.dispose();
}
DataBufferByte buffer = (DataBufferByte) raster.getDataBuffer();
byte[] imageData = buffer.getData();
return imageDataToPlatformImageBytes(imageData, width, height, format);
}
use of java.awt.image.ComponentColorModel in project nutz by nutzam.
the class Images method createJPEG4.
/**
* Java's ImageIO can't process 4-component images and Java2D can't apply
* AffineTransformOp either, so convert raster data to RGB. Technique due to
* MArk Stephens. Free for any use.
*/
private static BufferedImage createJPEG4(Raster raster) {
int w = raster.getWidth();
int h = raster.getHeight();
byte[] rgb = new byte[w * h * 3];
float[] Y = raster.getSamples(0, 0, w, h, 0, (float[]) null);
float[] Cb = raster.getSamples(0, 0, w, h, 1, (float[]) null);
float[] Cr = raster.getSamples(0, 0, w, h, 2, (float[]) null);
float[] K = raster.getSamples(0, 0, w, h, 3, (float[]) null);
for (int i = 0, imax = Y.length, base = 0; i < imax; i++, base += 3) {
float k = 220 - K[i], y = 255 - Y[i], cb = 255 - Cb[i], cr = 255 - Cr[i];
double val = y + 1.402 * (cr - 128) - k;
val = (val - 128) * .65f + 128;
rgb[base] = val < 0.0 ? (byte) 0 : val > 255.0 ? (byte) 0xff : (byte) (val + 0.5);
val = y - 0.34414 * (cb - 128) - 0.71414 * (cr - 128) - k;
val = (val - 128) * .65f + 128;
rgb[base + 1] = val < 0.0 ? (byte) 0 : val > 255.0 ? (byte) 0xff : (byte) (val + 0.5);
val = y + 1.772 * (cb - 128) - k;
val = (val - 128) * .65f + 128;
rgb[base + 2] = val < 0.0 ? (byte) 0 : val > 255.0 ? (byte) 0xff : (byte) (val + 0.5);
}
raster = Raster.createInterleavedRaster(new DataBufferByte(rgb, rgb.length), w, h, w * 3, 3, new int[] { 0, 1, 2 }, null);
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorModel cm = new ComponentColorModel(cs, false, true, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
return new BufferedImage(cm, (WritableRaster) raster, true, null);
}
use of java.awt.image.ComponentColorModel in project scriptographer by scriptographer.
the class Raster method getColorModel.
/**
* The Java2D color model of the raster.
* @jshide
*/
public ColorModel getColorModel() {
ColorType type = getType();
ColorModel cm = null;
switch(type) {
case RGB:
case ARGB:
cm = new ComponentColorModel(RGBColor.getColorSpace(), type.alpha ? new int[] { 8, 8, 8, 8 } : new int[] { 8, 8, 8 }, type.alpha, false, type.alpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
break;
case CMYK:
case ACMYK:
cm = new ComponentColorModel(CMYKColor.getColorSpace(), type.alpha ? new int[] { 8, 8, 8, 8, 8 } : new int[] { 8, 8, 8, 8 }, type.alpha, false, type.alpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
break;
case GRAY:
case AGRAY:
cm = new ComponentColorModel(GrayColor.getColorSpace(), type.alpha ? new int[] { 8, 8 } : new int[] { 8 }, type.alpha, false, type.alpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
break;
case BITMAP:
case ABITMAP:
// create an IndexColorModel with two colors, black and white:
// black is the transparent color in case of an alpha image
cm = new IndexColorModel(2, 2, new byte[] { 0, (byte) 255 }, new byte[] { 0, (byte) 255 }, new byte[] { 0, (byte) 255 }, type.alpha ? 0 : -1);
break;
}
return cm;
}
use of java.awt.image.ComponentColorModel in project jdk8u_jdk by JetBrains.
the class LCMSImageLayout method createImageLayout.
/* This method creates a layout object for given image.
* Returns null if the image is not supported by current implementation.
*/
public static LCMSImageLayout createImageLayout(BufferedImage image) throws ImageLayoutException {
LCMSImageLayout l = new LCMSImageLayout();
switch(image.getType()) {
case BufferedImage.TYPE_INT_RGB:
l.pixelType = PT_ARGB_8;
l.isIntPacked = true;
break;
case BufferedImage.TYPE_INT_ARGB:
l.pixelType = PT_ARGB_8;
l.isIntPacked = true;
break;
case BufferedImage.TYPE_INT_BGR:
l.pixelType = PT_ABGR_8;
l.isIntPacked = true;
break;
case BufferedImage.TYPE_3BYTE_BGR:
l.pixelType = PT_BGR_8;
break;
case BufferedImage.TYPE_4BYTE_ABGR:
l.pixelType = PT_ABGR_8;
break;
case BufferedImage.TYPE_BYTE_GRAY:
l.pixelType = PT_GRAY_8;
break;
case BufferedImage.TYPE_USHORT_GRAY:
l.pixelType = PT_GRAY_16;
break;
default:
/* ColorConvertOp creates component images as
* default destination, so this kind of images
* has to be supported.
*/
ColorModel cm = image.getColorModel();
if (cm instanceof ComponentColorModel) {
ComponentColorModel ccm = (ComponentColorModel) cm;
// verify whether the component size is fine
int[] cs = ccm.getComponentSize();
for (int s : cs) {
if (s != 8) {
return null;
}
}
return createImageLayout(image.getRaster());
}
return null;
}
l.width = image.getWidth();
l.height = image.getHeight();
switch(image.getType()) {
case BufferedImage.TYPE_INT_RGB:
case BufferedImage.TYPE_INT_ARGB:
case BufferedImage.TYPE_INT_BGR:
do {
IntegerComponentRaster intRaster = (IntegerComponentRaster) image.getRaster();
l.nextRowOffset = safeMult(4, intRaster.getScanlineStride());
l.nextPixelOffset = safeMult(4, intRaster.getPixelStride());
l.offset = safeMult(4, intRaster.getDataOffset(0));
l.dataArray = intRaster.getDataStorage();
l.dataArrayLength = 4 * intRaster.getDataStorage().length;
l.dataType = DT_INT;
if (l.nextRowOffset == l.width * 4 * intRaster.getPixelStride()) {
l.imageAtOnce = true;
}
} while (false);
break;
case BufferedImage.TYPE_3BYTE_BGR:
case BufferedImage.TYPE_4BYTE_ABGR:
do {
ByteComponentRaster byteRaster = (ByteComponentRaster) image.getRaster();
l.nextRowOffset = byteRaster.getScanlineStride();
l.nextPixelOffset = byteRaster.getPixelStride();
int firstBand = image.getSampleModel().getNumBands() - 1;
l.offset = byteRaster.getDataOffset(firstBand);
l.dataArray = byteRaster.getDataStorage();
l.dataArrayLength = byteRaster.getDataStorage().length;
l.dataType = DT_BYTE;
if (l.nextRowOffset == l.width * byteRaster.getPixelStride()) {
l.imageAtOnce = true;
}
} while (false);
break;
case BufferedImage.TYPE_BYTE_GRAY:
do {
ByteComponentRaster byteRaster = (ByteComponentRaster) image.getRaster();
l.nextRowOffset = byteRaster.getScanlineStride();
l.nextPixelOffset = byteRaster.getPixelStride();
l.dataArrayLength = byteRaster.getDataStorage().length;
l.offset = byteRaster.getDataOffset(0);
l.dataArray = byteRaster.getDataStorage();
l.dataType = DT_BYTE;
if (l.nextRowOffset == l.width * byteRaster.getPixelStride()) {
l.imageAtOnce = true;
}
} while (false);
break;
case BufferedImage.TYPE_USHORT_GRAY:
do {
ShortComponentRaster shortRaster = (ShortComponentRaster) image.getRaster();
l.nextRowOffset = safeMult(2, shortRaster.getScanlineStride());
l.nextPixelOffset = safeMult(2, shortRaster.getPixelStride());
l.offset = safeMult(2, shortRaster.getDataOffset(0));
l.dataArray = shortRaster.getDataStorage();
l.dataArrayLength = 2 * shortRaster.getDataStorage().length;
l.dataType = DT_SHORT;
if (l.nextRowOffset == l.width * 2 * shortRaster.getPixelStride()) {
l.imageAtOnce = true;
}
} while (false);
break;
default:
return null;
}
l.verify();
return l;
}
Aggregations