use of java.awt.image.WritableRaster in project jdk8u_jdk by JetBrains.
the class AlphaPaintPipe method renderPathTile.
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;
SunGraphics2D sg = context.sunG2D;
SurfaceData dstData = context.dstData;
SurfaceData srcData = null;
Raster lastRas = null;
if (context.lastData != null && context.lastRaster != null) {
srcData = (SurfaceData) context.lastData.get();
lastRas = (Raster) context.lastRaster.get();
if (srcData == null || lastRas == null) {
srcData = null;
lastRas = null;
}
}
ColorModel paintModel = context.paintModel;
for (int rely = 0; rely < h; rely += TILE_SIZE) {
int ty = y + rely;
int th = Math.min(h - rely, TILE_SIZE);
for (int relx = 0; relx < w; relx += TILE_SIZE) {
int tx = x + relx;
int tw = Math.min(w - relx, TILE_SIZE);
Raster srcRaster = paintCtxt.getRaster(tx, ty, tw, th);
if ((srcRaster.getMinX() != 0) || (srcRaster.getMinY() != 0)) {
srcRaster = srcRaster.createTranslatedChild(0, 0);
}
if (lastRas != srcRaster) {
lastRas = srcRaster;
context.lastRaster = new WeakReference(lastRas);
// REMIND: This will fail for a non-Writable raster!
BufferedImage bImg = new BufferedImage(paintModel, (WritableRaster) srcRaster, paintModel.isAlphaPremultiplied(), null);
srcData = BufImgSurfaceData.createData(bImg);
context.lastData = new WeakReference(srcData);
context.lastMask = null;
context.lastBlit = null;
}
if (atile == null) {
if (context.lastBlit == null) {
CompositeType comptype = sg.imageComp;
if (CompositeType.SrcOverNoEa.equals(comptype) && paintModel.getTransparency() == Transparency.OPAQUE) {
comptype = CompositeType.SrcNoEa;
}
context.lastBlit = Blit.getFromCache(srcData.getSurfaceType(), comptype, dstData.getSurfaceType());
}
context.lastBlit.Blit(srcData, dstData, sg.composite, null, 0, 0, tx, ty, tw, th);
} else {
if (context.lastMask == null) {
CompositeType comptype = sg.imageComp;
if (CompositeType.SrcOverNoEa.equals(comptype) && paintModel.getTransparency() == Transparency.OPAQUE) {
comptype = CompositeType.SrcNoEa;
}
context.lastMask = MaskBlit.getFromCache(srcData.getSurfaceType(), comptype, dstData.getSurfaceType());
}
int toff = offset + rely * tilesize + relx;
context.lastMask.MaskBlit(srcData, dstData, sg.composite, null, 0, 0, tx, ty, tw, th, atile, toff, tilesize);
}
}
}
}
use of java.awt.image.WritableRaster 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.WritableRaster in project jdk8u_jdk by JetBrains.
the class DropShadowEffect method applyEffect.
/**
* Apply the effect to the src image generating the result . The result image may or may not contain the source
* image depending on what the effect type is.
*
* @param src The source image for applying the effect to
* @param dst The destination image to paint effect result into. If this is null then a new image will be created
* @param w The width of the src image to apply effect to, this allow the src and dst buffers to be bigger than
* the area the need effect applied to it
* @param h The height of the src image to apply effect to, this allow the src and dst buffers to be bigger than
* the area the need effect applied to it
* @return Image with the result of the effect
*/
@Override
BufferedImage applyEffect(BufferedImage src, BufferedImage dst, int w, int h) {
if (src == null || src.getType() != BufferedImage.TYPE_INT_ARGB) {
throw new IllegalArgumentException("Effect only works with " + "source images of type BufferedImage.TYPE_INT_ARGB.");
}
if (dst != null && dst.getType() != BufferedImage.TYPE_INT_ARGB) {
throw new IllegalArgumentException("Effect only works with " + "destination images of type BufferedImage.TYPE_INT_ARGB.");
}
// calculate offset
double trangleAngle = Math.toRadians(angle - 90);
int offsetX = (int) (Math.sin(trangleAngle) * distance);
int offsetY = (int) (Math.cos(trangleAngle) * distance);
// clac expanded size
int tmpOffX = offsetX + size;
int tmpOffY = offsetX + size;
int tmpW = w + offsetX + size + size;
int tmpH = h + offsetX + size;
// create tmp buffers
int[] lineBuf = getArrayCache().getTmpIntArray(w);
byte[] tmpBuf1 = getArrayCache().getTmpByteArray1(tmpW * tmpH);
Arrays.fill(tmpBuf1, (byte) 0x00);
byte[] tmpBuf2 = getArrayCache().getTmpByteArray2(tmpW * tmpH);
// extract src image alpha channel and inverse and offset
Raster srcRaster = src.getRaster();
for (int y = 0; y < h; y++) {
int dy = (y + tmpOffY);
int offset = dy * tmpW;
srcRaster.getDataElements(0, y, w, 1, lineBuf);
for (int x = 0; x < w; x++) {
int dx = x + tmpOffX;
tmpBuf1[offset + dx] = (byte) ((lineBuf[x] & 0xFF000000) >>> 24);
}
}
// blur
float[] kernel = EffectUtils.createGaussianKernel(size);
// horizontal pass
EffectUtils.blur(tmpBuf1, tmpBuf2, tmpW, tmpH, kernel, size);
// vertical pass
EffectUtils.blur(tmpBuf2, tmpBuf1, tmpH, tmpW, kernel, size);
//rescale
float spread = Math.min(1 / (1 - (0.01f * this.spread)), 255);
for (int i = 0; i < tmpBuf1.length; i++) {
int val = (int) (((int) tmpBuf1[i] & 0xFF) * spread);
tmpBuf1[i] = (val > 255) ? (byte) 0xFF : (byte) val;
}
// create color image with shadow color and greyscale image as alpha
if (dst == null)
dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
WritableRaster shadowRaster = dst.getRaster();
int red = color.getRed(), green = color.getGreen(), blue = color.getBlue();
for (int y = 0; y < h; y++) {
int srcY = y + tmpOffY;
int shadowOffset = (srcY - offsetY) * tmpW;
for (int x = 0; x < w; x++) {
int srcX = x + tmpOffX;
lineBuf[x] = tmpBuf1[shadowOffset + (srcX - offsetX)] << 24 | red << 16 | green << 8 | blue;
}
shadowRaster.setDataElements(0, y, w, 1, lineBuf);
}
return dst;
}
use of java.awt.image.WritableRaster in project jdk8u_jdk by JetBrains.
the class ImagingLib method filter.
public static WritableRaster filter(RasterOp op, Raster src, WritableRaster dst) {
if (useLib == false) {
return null;
}
// Create the destination tile
if (dst == null) {
dst = op.createCompatibleDestRaster(src);
}
WritableRaster retRaster = null;
switch(getNativeOpIndex(op.getClass())) {
case LOOKUP_OP:
// REMIND: Fix this!
LookupTable table = ((LookupOp) op).getTable();
if (table.getOffset() != 0) {
// Right now the native code doesn't support offsets
return null;
}
if (table instanceof ByteLookupTable) {
ByteLookupTable bt = (ByteLookupTable) table;
if (lookupByteRaster(src, dst, bt.getTable()) > 0) {
retRaster = dst;
}
}
break;
case AFFINE_OP:
AffineTransformOp bOp = (AffineTransformOp) op;
double[] matrix = new double[6];
bOp.getTransform().getMatrix(matrix);
if (transformRaster(src, dst, matrix, bOp.getInterpolationType()) > 0) {
retRaster = dst;
}
break;
case CONVOLVE_OP:
ConvolveOp cOp = (ConvolveOp) op;
if (convolveRaster(src, dst, cOp.getKernel(), cOp.getEdgeCondition()) > 0) {
retRaster = dst;
}
break;
default:
break;
}
if (retRaster != null) {
SunWritableRaster.markDirty(retRaster);
}
return retRaster;
}
use of java.awt.image.WritableRaster 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