use of java.awt.image.DirectColorModel in project jdk8u_jdk by JetBrains.
the class ImageFactory method createDCMImage.
public static BufferedImage createDCMImage(int type, int cs) {
if (type == BufferedImage.TYPE_INT_RGB && cs == ColorSpace.CS_sRGB) {
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
DataBuffer data = image.getData().getDataBuffer();
fill(image);
return image;
}
ColorSpace cSpace = ColorSpace.getInstance(cs);
DirectColorModel dcm = null;
switch(type) {
case BufferedImage.TYPE_INT_ARGB:
dcm = new DirectColorModel(cSpace, 32, rMask, gMask, bMask, aMask, false, DataBuffer.TYPE_INT);
break;
case BufferedImage.TYPE_INT_RGB:
dcm = new DirectColorModel(cSpace, 24, rMask, gMask, bMask, 0, false, DataBuffer.TYPE_INT);
break;
case BufferedImage.TYPE_INT_BGR:
dcm = new DirectColorModel(cSpace, 24, rMask, gMask, bMask, 0, false, DataBuffer.TYPE_INT);
break;
case BufferedImage.TYPE_USHORT_555_RGB:
dcm = new DirectColorModel(cSpace, 15, r555Mask, g555Mask, b555Mask, 0, false, DataBuffer.TYPE_USHORT);
break;
case BufferedImage.TYPE_USHORT_565_RGB:
dcm = new DirectColorModel(cSpace, 16, r565Mask, g565Mask, b565Mask, 0, false, DataBuffer.TYPE_USHORT);
break;
}
SampleModel sm = dcm.createCompatibleSampleModel(WIDTH, HEIGHT);
WritableRaster raster = dcm.createCompatibleWritableRaster(WIDTH, HEIGHT);
switch(type) {
case BufferedImage.TYPE_INT_ARGB:
fillDCM(raster.getDataBuffer(), sm, cSpace.getType());
break;
case BufferedImage.TYPE_INT_RGB:
fillDCM(raster.getDataBuffer(), sm, cSpace.getType());
break;
case BufferedImage.TYPE_INT_BGR:
fillDCM(raster.getDataBuffer(), sm, cSpace.getType());
break;
case BufferedImage.TYPE_USHORT_555_RGB:
fillDCM(raster.getDataBuffer(), sm, cSpace.getType(), 5, 5, 5);
break;
case BufferedImage.TYPE_USHORT_565_RGB:
fillDCM(raster.getDataBuffer(), sm, cSpace.getType(), 5, 6, 5);
break;
}
return new BufferedImage(dcm, raster, false, null);
}
use of java.awt.image.DirectColorModel in project jdk8u_jdk by JetBrains.
the class NoExtraBytesTest method createTestImage.
private static BufferedImage createTestImage(int type) {
BufferedImage dst = null;
ColorModel colorModel = null;
WritableRaster raster = null;
ColorSpace cs = null;
System.out.println("Create image for " + getImageTypeName(type));
switch(type) {
case TYPE_INT_GRB:
colorModel = new DirectColorModel(24, 0x0000ff00, 0x00ff0000, 0x000000ff);
break;
case TYPE_INT_GBR:
colorModel = new DirectColorModel(24, 0x000000ff, 0x00ff0000, 0x0000ff00);
break;
case TYPE_INT_RBG:
colorModel = new DirectColorModel(24, 0x00ff0000, 0x000000ff, 0x0000ff00);
break;
case TYPE_INT_BRG:
colorModel = new DirectColorModel(24, 0x0000ff00, 0x000000ff, 0x00ff0000);
break;
case TYPE_INT_555_GRB:
colorModel = new DirectColorModel(24, 0x0000001F, 0x000003e0, 0x00007c00);
break;
case TYPE_3BYTE_RGB:
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
int[] nBits = { 8, 8, 8 };
int[] bOffs = { 0, 1, 2 };
colorModel = new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, w, h, w * 3, 3, bOffs, null);
break;
case TYPE_3BYTE_GRB:
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
//nBits = {8, 8, 8};
//bOffs = {0, 1, 2};
colorModel = new ComponentColorModel(cs, new int[] { 8, 8, 8 }, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, w, h, w * 3, 3, new int[] { 1, 0, 2 }, null);
break;
default:
dst = new BufferedImage(w, h, type);
}
if (dst == null) {
if (raster == null) {
raster = colorModel.createCompatibleWritableRaster(w, h);
}
dst = new BufferedImage(colorModel, raster, false, null);
}
Graphics g = dst.createGraphics();
for (int i = 0; i < usedColors.length; i++) {
g.setColor(usedColors[i]);
g.fillRect(i * dx, 0, dx, h);
}
g.dispose();
return dst;
}
use of java.awt.image.DirectColorModel in project jdk8u_jdk by JetBrains.
the class BMPSubsamplingTest method getTestImage.
private BufferedImage getTestImage(int type) {
BufferedImage dst = null;
ColorModel colorModel = null;
WritableRaster raster = null;
switch(type) {
case TYPE_INT_GRB:
colorModel = new DirectColorModel(24, 0x0000ff00, 0x00ff0000, 0x000000ff);
break;
case TYPE_INT_GBR:
colorModel = new DirectColorModel(24, 0x000000ff, 0x00ff0000, 0x0000ff00);
break;
case TYPE_INT_RBG:
colorModel = new DirectColorModel(24, 0x00ff0000, 0x000000ff, 0x0000ff00);
break;
case TYPE_INT_BRG:
colorModel = new DirectColorModel(24, 0x0000ff00, 0x000000ff, 0x00ff0000);
break;
case TYPE_3BYTE_RGB:
dst = create3ByteImage(new int[] { 8, 8, 8 }, new int[] { 0, 1, 2 });
break;
case TYPE_3BYTE_GRB:
dst = create3ByteImage(new int[] { 8, 8, 8 }, new int[] { 1, 0, 2 });
break;
case TYPE_USHORT_555_GRB:
colorModel = new DirectColorModel(16, 0x03E0, 0x7C00, 0x001F);
break;
case TYPE_USHORT_555_BGR:
colorModel = new DirectColorModel(16, 0x001F, 0x03E0, 0x7C00);
break;
case TYPE_USHORT_565_BGR:
colorModel = new DirectColorModel(16, 0x001F, 0x07E0, 0xf800);
break;
case TYPE_4BPP_INDEXED:
dst = createIndexImage(4);
break;
default:
dst = new BufferedImage(w, h, type);
}
if (dst == null) {
raster = colorModel.createCompatibleWritableRaster(w, h);
dst = new BufferedImage(colorModel, raster, false, null);
}
Graphics2D g = dst.createGraphics();
for (int i = 0; i < colors.length; i++) {
g.setColor(colors[i]);
g.fillRect(i * dx, 0, dx, h);
}
g.dispose();
return dst;
}
use of java.awt.image.DirectColorModel in project jdk8u_jdk by JetBrains.
the class BufImgSurfaceData method createData.
public static SurfaceData createData(BufferedImage bufImg, double scaleX, double scaleY) {
if (bufImg == null) {
throw new NullPointerException("BufferedImage cannot be null");
}
SurfaceData sData;
ColorModel cm = bufImg.getColorModel();
int type = bufImg.getType();
// REMIND: Check the image type and pick an appropriate subclass
switch(type) {
case BufferedImage.TYPE_INT_BGR:
sData = createDataIC(bufImg, SurfaceType.IntBgr, scaleX, scaleY);
break;
case BufferedImage.TYPE_INT_RGB:
sData = createDataIC(bufImg, SurfaceType.IntRgb, scaleX, scaleY);
break;
case BufferedImage.TYPE_INT_ARGB:
sData = createDataIC(bufImg, SurfaceType.IntArgb, scaleX, scaleY);
break;
case BufferedImage.TYPE_INT_ARGB_PRE:
sData = createDataIC(bufImg, SurfaceType.IntArgbPre, scaleX, scaleY);
break;
case BufferedImage.TYPE_3BYTE_BGR:
sData = createDataBC(bufImg, SurfaceType.ThreeByteBgr, 2, scaleX, scaleY);
break;
case BufferedImage.TYPE_4BYTE_ABGR:
sData = createDataBC(bufImg, SurfaceType.FourByteAbgr, 3, scaleX, scaleY);
break;
case BufferedImage.TYPE_4BYTE_ABGR_PRE:
sData = createDataBC(bufImg, SurfaceType.FourByteAbgrPre, 3, scaleX, scaleY);
break;
case BufferedImage.TYPE_USHORT_565_RGB:
sData = createDataSC(bufImg, SurfaceType.Ushort565Rgb, null, scaleX, scaleY);
break;
case BufferedImage.TYPE_USHORT_555_RGB:
sData = createDataSC(bufImg, SurfaceType.Ushort555Rgb, null, scaleX, scaleY);
break;
case BufferedImage.TYPE_BYTE_INDEXED:
{
SurfaceType sType;
switch(cm.getTransparency()) {
case OPAQUE:
if (isOpaqueGray((IndexColorModel) cm)) {
sType = SurfaceType.Index8Gray;
} else {
sType = SurfaceType.ByteIndexedOpaque;
}
break;
case BITMASK:
sType = SurfaceType.ByteIndexedBm;
break;
case TRANSLUCENT:
sType = SurfaceType.ByteIndexed;
break;
default:
throw new InternalError("Unrecognized transparency");
}
sData = createDataBC(bufImg, sType, 0, scaleX, scaleY);
}
break;
case BufferedImage.TYPE_BYTE_GRAY:
sData = createDataBC(bufImg, SurfaceType.ByteGray, 0, scaleX, scaleY);
break;
case BufferedImage.TYPE_USHORT_GRAY:
sData = createDataSC(bufImg, SurfaceType.UshortGray, null, scaleX, scaleY);
break;
case BufferedImage.TYPE_BYTE_BINARY:
{
SurfaceType sType;
SampleModel sm = bufImg.getRaster().getSampleModel();
switch(sm.getSampleSize(0)) {
case 1:
sType = SurfaceType.ByteBinary1Bit;
break;
case 2:
sType = SurfaceType.ByteBinary2Bit;
break;
case 4:
sType = SurfaceType.ByteBinary4Bit;
break;
default:
throw new InternalError("Unrecognized pixel size");
}
sData = createDataBP(bufImg, sType, scaleX, scaleY);
}
break;
case BufferedImage.TYPE_CUSTOM:
default:
{
Raster raster = bufImg.getRaster();
int numBands = raster.getNumBands();
if (raster instanceof IntegerComponentRaster && raster.getNumDataElements() == 1 && ((IntegerComponentRaster) raster).getPixelStride() == 1) {
SurfaceType sType = SurfaceType.AnyInt;
if (cm instanceof DirectColorModel) {
DirectColorModel dcm = (DirectColorModel) cm;
int aMask = dcm.getAlphaMask();
int rMask = dcm.getRedMask();
int gMask = dcm.getGreenMask();
int bMask = dcm.getBlueMask();
if (numBands == 3 && aMask == 0 && rMask == DCM_RGBX_RED_MASK && gMask == DCM_RGBX_GREEN_MASK && bMask == DCM_RGBX_BLUE_MASK) {
sType = SurfaceType.IntRgbx;
} else if (numBands == 4 && aMask == DCM_ARGBBM_ALPHA_MASK && rMask == DCM_ARGBBM_RED_MASK && gMask == DCM_ARGBBM_GREEN_MASK && bMask == DCM_ARGBBM_BLUE_MASK) {
sType = SurfaceType.IntArgbBm;
} else {
sType = SurfaceType.AnyDcm;
}
}
sData = createDataIC(bufImg, sType, scaleX, scaleY);
break;
} else if (raster instanceof ShortComponentRaster && raster.getNumDataElements() == 1 && ((ShortComponentRaster) raster).getPixelStride() == 1) {
SurfaceType sType = SurfaceType.AnyShort;
IndexColorModel icm = null;
if (cm instanceof DirectColorModel) {
DirectColorModel dcm = (DirectColorModel) cm;
int aMask = dcm.getAlphaMask();
int rMask = dcm.getRedMask();
int gMask = dcm.getGreenMask();
int bMask = dcm.getBlueMask();
if (numBands == 3 && aMask == 0 && rMask == DCM_555X_RED_MASK && gMask == DCM_555X_GREEN_MASK && bMask == DCM_555X_BLUE_MASK) {
sType = SurfaceType.Ushort555Rgbx;
} else if (numBands == 4 && aMask == DCM_4444_ALPHA_MASK && rMask == DCM_4444_RED_MASK && gMask == DCM_4444_GREEN_MASK && bMask == DCM_4444_BLUE_MASK) {
sType = SurfaceType.Ushort4444Argb;
}
} else if (cm instanceof IndexColorModel) {
icm = (IndexColorModel) cm;
if (icm.getPixelSize() == 12) {
if (isOpaqueGray(icm)) {
sType = SurfaceType.Index12Gray;
} else {
sType = SurfaceType.UshortIndexed;
}
} else {
icm = null;
}
}
sData = createDataSC(bufImg, sType, icm, scaleX, scaleY);
break;
}
sData = new BufImgSurfaceData(raster.getDataBuffer(), bufImg, SurfaceType.Custom, scaleX, scaleY);
}
break;
}
((BufImgSurfaceData) sData).initSolidLoops();
return sData;
}
use of java.awt.image.DirectColorModel in project jdk8u_jdk by JetBrains.
the class ImageRepresentation method setColorModel.
public void setColorModel(ColorModel model) {
if (src != null) {
src.checkSecurity(null, false);
}
srcModel = model;
// Check to see if model is INT_RGB
if (model instanceof IndexColorModel) {
if (model.getTransparency() == model.TRANSLUCENT) {
// REMIND:
// Probably need to composite anyway so force ARGB
cmodel = ColorModel.getRGBdefault();
srcLUT = null;
} else {
IndexColorModel icm = (IndexColorModel) model;
numSrcLUT = icm.getMapSize();
srcLUT = new int[Math.max(numSrcLUT, 256)];
icm.getRGBs(srcLUT);
srcLUTtransIndex = icm.getTransparentPixel();
cmodel = model;
}
} else {
if (cmodel == null) {
cmodel = model;
srcLUT = null;
} else if (model instanceof DirectColorModel) {
// If it is INT_RGB or INT_ARGB, use the model
DirectColorModel dcm = (DirectColorModel) model;
if ((dcm.getRedMask() == 0xff0000) && (dcm.getGreenMask() == 0xff00) && (dcm.getBlueMask() == 0x00ff)) {
cmodel = model;
srcLUT = null;
}
}
}
isSameCM = (cmodel == model);
}
Aggregations