use of sun.awt.image.ShortComponentRaster 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