use of java.awt.image.ColorModel in project jdk8u_jdk by JetBrains.
the class GeneralCompositePipe method renderPathTile.
/**
* GeneralCompositePipe.renderPathTile works with custom composite operator
* provided by an application
*/
public void renderPathTile(Object ctx, byte[] atile, int offset, int tilesize, int x, int y, int w, int h) {
TileContext context = (TileContext) ctx;
PaintContext paintCtxt = context.paintCtxt;
CompositeContext compCtxt = context.compCtxt;
SunGraphics2D sg = context.sunG2D;
Raster srcRaster = paintCtxt.getRaster(x, y, w, h);
ColorModel paintModel = paintCtxt.getColorModel();
Raster dstRaster;
Raster dstIn;
WritableRaster dstOut;
SurfaceData sd = sg.getSurfaceData();
dstRaster = sd.getRaster(x, y, w, h);
if (dstRaster instanceof WritableRaster && atile == null) {
dstOut = (WritableRaster) dstRaster;
dstOut = dstOut.createWritableChild(x, y, w, h, 0, 0, null);
dstIn = dstOut;
} else {
dstIn = dstRaster.createChild(x, y, w, h, 0, 0, null);
dstOut = dstIn.createCompatibleWritableRaster();
}
compCtxt.compose(srcRaster, dstIn, dstOut);
if (dstRaster != dstOut && dstOut.getParent() != dstRaster) {
if (dstRaster instanceof WritableRaster && atile == null) {
((WritableRaster) dstRaster).setDataElements(x, y, dstOut);
} else {
ColorModel cm = sg.getDeviceColorModel();
BufferedImage resImg = new BufferedImage(cm, dstOut, cm.isAlphaPremultiplied(), null);
SurfaceData resData = BufImgSurfaceData.createData(resImg);
if (atile == null) {
Blit blit = Blit.getFromCache(resData.getSurfaceType(), CompositeType.SrcNoEa, sd.getSurfaceType());
blit.Blit(resData, sd, AlphaComposite.Src, null, 0, 0, x, y, w, h);
} else {
MaskBlit blit = MaskBlit.getFromCache(resData.getSurfaceType(), CompositeType.SrcNoEa, sd.getSurfaceType());
blit.MaskBlit(resData, sd, AlphaComposite.Src, null, 0, 0, x, y, w, h, atile, offset, tilesize);
}
}
}
}
use of java.awt.image.ColorModel in project jdk8u_jdk by JetBrains.
the class PathGraphics method hasTransparentPixels.
/**
* Return true if the BufferedImage argument has non-opaque
* bits in it and therefore can not be directly rendered by
* GDI. Return false if the image is opaque. If this function
* can not tell for sure whether the image has transparent
* pixels then it assumes that it does.
*/
protected boolean hasTransparentPixels(BufferedImage bufferedImage) {
ColorModel colorModel = bufferedImage.getColorModel();
boolean hasTransparency = colorModel == null ? true : colorModel.getTransparency() != ColorModel.OPAQUE;
/*
* For the default INT ARGB check the image to see if any pixels are
* really transparent. If there are no transparent pixels then the
* transparency of the color model can be ignored.
* We assume that IndexColorModel images have already been
* checked for transparency and will be OPAQUE unless they actually
* have transparent pixels present.
*/
if (hasTransparency && bufferedImage != null) {
if (bufferedImage.getType() == BufferedImage.TYPE_INT_ARGB || bufferedImage.getType() == BufferedImage.TYPE_INT_ARGB_PRE) {
DataBuffer db = bufferedImage.getRaster().getDataBuffer();
SampleModel sm = bufferedImage.getRaster().getSampleModel();
if (db instanceof DataBufferInt && sm instanceof SinglePixelPackedSampleModel) {
SinglePixelPackedSampleModel psm = (SinglePixelPackedSampleModel) sm;
// Stealing the data array for reading only...
int[] int_data = SunWritableRaster.stealData((DataBufferInt) db, 0);
int x = bufferedImage.getMinX();
int y = bufferedImage.getMinY();
int w = bufferedImage.getWidth();
int h = bufferedImage.getHeight();
int stride = psm.getScanlineStride();
boolean hastranspixel = false;
for (int j = y; j < y + h; j++) {
int yoff = j * stride;
for (int i = x; i < x + w; i++) {
if ((int_data[yoff + i] & 0xff000000) != 0xff000000) {
hastranspixel = true;
break;
}
}
if (hastranspixel) {
break;
}
}
if (hastranspixel == false) {
hasTransparency = false;
}
}
}
}
return hasTransparency;
}
use of java.awt.image.ColorModel 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.ColorModel in project jdk8u_jdk by JetBrains.
the class BufImgSurfaceData method createDataBC.
public static SurfaceData createDataBC(BufferedImage bImg, SurfaceType sType, int primaryBank, double scaleX, double scaleY) {
ByteComponentRaster bcRaster = (ByteComponentRaster) bImg.getRaster();
BufImgSurfaceData bisd = new BufImgSurfaceData(bcRaster.getDataBuffer(), bImg, sType, scaleX, scaleY);
ColorModel cm = bImg.getColorModel();
IndexColorModel icm = ((cm instanceof IndexColorModel) ? (IndexColorModel) cm : null);
bisd.initRaster(bcRaster.getDataStorage(), bcRaster.getDataOffset(primaryBank), 0, bcRaster.getWidth(), bcRaster.getHeight(), bcRaster.getPixelStride(), bcRaster.getScanlineStride(), icm);
return bisd;
}
use of java.awt.image.ColorModel in project jdk8u_jdk by JetBrains.
the class SunGraphics2D method drawRenderedImage.
/**
* Draws an image, applying a transform from image space into user space
* before drawing.
* The transformation from user space into device space is done with
* the current transform in the Graphics2D.
* The given transformation is applied to the image before the
* transform attribute in the Graphics2D state is applied.
* The rendering attributes applied include the clip, transform,
* and composite attributes. Note that the result is
* undefined, if the given transform is noninvertible.
* @param img The image to be drawn. Does nothing if img is null.
* @param xform The transformation from image space into user space.
* @see #transform
* @see #setTransform
* @see #setComposite
* @see #clip
* @see #setClip
*/
public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
if (img == null) {
return;
}
// BufferedImage case: use a simple drawImage call
if (img instanceof BufferedImage) {
BufferedImage bufImg = (BufferedImage) img;
drawImage(bufImg, xform, null);
return;
}
// transformState tracks the state of transform and
// transX, transY contain the integer casts of the
// translation factors
boolean isIntegerTranslate = (transformState <= TRANSFORM_INT_TRANSLATE) && isIntegerTranslation(xform);
// Include padding for interpolation/antialiasing if necessary
int pad = isIntegerTranslate ? 0 : 3;
Region clip;
try {
clip = getCompClip();
} catch (InvalidPipeException e) {
return;
}
// Determine the region of the image that may contribute to
// the clipped drawing area
Rectangle region = getImageRegion(img, clip, transform, xform, pad, pad);
if (region.width <= 0 || region.height <= 0) {
return;
}
// where both are integer translations.
if (isIntegerTranslate) {
// Use optimized code
// Note that drawTranslatedRenderedImage calls copyImage
// which takes the user space to device space transform into
// account, but we need to provide the image space to user space
// translations.
drawTranslatedRenderedImage(img, region, (int) xform.getTranslateX(), (int) xform.getTranslateY());
return;
}
// General case: cobble the necessary region into a single Raster
Raster raster = img.getData(region);
// Make a new Raster with the same contents as raster
// but starting at (0, 0). This raster is thus in the same
// coordinate system as the SampleModel of the original raster.
WritableRaster wRaster = Raster.createWritableRaster(raster.getSampleModel(), raster.getDataBuffer(), null);
// If the original raster was in a different coordinate
// system than its SampleModel, we need to perform an
// additional translation in order to get the (minX, minY)
// pixel of raster to be pixel (0, 0) of wRaster. We also
// have to have the correct width and height.
int minX = raster.getMinX();
int minY = raster.getMinY();
int width = raster.getWidth();
int height = raster.getHeight();
int px = minX - raster.getSampleModelTranslateX();
int py = minY - raster.getSampleModelTranslateY();
if (px != 0 || py != 0 || width != wRaster.getWidth() || height != wRaster.getHeight()) {
wRaster = wRaster.createWritableChild(px, py, width, height, 0, 0, null);
}
// Now we have a BufferedImage starting at (0, 0)
// with the same contents that started at (minX, minY)
// in raster. So we must draw the BufferedImage with a
// translation of (minX, minY).
AffineTransform transXform = (AffineTransform) xform.clone();
transXform.translate(minX, minY);
ColorModel cm = img.getColorModel();
BufferedImage bufImg = new BufferedImage(cm, wRaster, cm.isAlphaPremultiplied(), null);
drawImage(bufImg, transXform, null);
}
Aggregations