use of java.awt.image.WritableRaster in project jdk8u_jdk by JetBrains.
the class XorPixelWriter method doSetRect.
static void doSetRect(SurfaceData sData, PixelWriter pw, int x1, int y1, int x2, int y2) {
WritableRaster dstRast = (WritableRaster) sData.getRaster(x1, y1, x2 - x1, y2 - y1);
pw.setRaster(dstRast);
while (y1 < y2) {
for (int x = x1; x < x2; x++) {
pw.writePixel(x, y1);
}
y1++;
}
}
use of java.awt.image.WritableRaster in project jdk8u_jdk by JetBrains.
the class XorPixelWriter method doDrawLine.
static int[] doDrawLine(SurfaceData sData, PixelWriter pw, int[] boundPts, Region clip, int origx1, int origy1, int origx2, int origy2) {
if (boundPts == null) {
boundPts = new int[8];
}
boundPts[0] = origx1;
boundPts[1] = origy1;
boundPts[2] = origx2;
boundPts[3] = origy2;
if (!adjustLine(boundPts, clip.getLoX(), clip.getLoY(), clip.getHiX(), clip.getHiY())) {
return boundPts;
}
int x1 = boundPts[0];
int y1 = boundPts[1];
int x2 = boundPts[2];
int y2 = boundPts[3];
WritableRaster dstRast = (WritableRaster) sData.getRaster(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2) + 1, Math.abs(y1 - y2) + 1);
pw.setRaster(dstRast);
/* this could be made smaller, more elegant, more traditional. */
if (x1 == x2) {
if (y1 > y2) {
do {
pw.writePixel(x1, y1);
y1--;
} while (y1 >= y2);
} else {
do {
pw.writePixel(x1, y1);
y1++;
} while (y1 <= y2);
}
} else if (y1 == y2) {
if (x1 > x2) {
do {
pw.writePixel(x1, y1);
x1--;
} while (x1 >= x2);
} else {
do {
pw.writePixel(x1, y1);
x1++;
} while (x1 <= x2);
}
} else {
int dx = boundPts[4];
int dy = boundPts[5];
int ax = boundPts[6];
int ay = boundPts[7];
int steps;
int bumpmajor;
int bumpminor;
int errminor;
int errmajor;
int error;
boolean xmajor;
if (ax >= ay) {
/* x is dominant */
xmajor = true;
errmajor = ay * 2;
errminor = ax * 2;
bumpmajor = (dx < 0) ? -1 : 1;
bumpminor = (dy < 0) ? -1 : 1;
ax = -ax;
/* For clipping adjustment below */
steps = x2 - x1;
} else {
/* y is dominant */
xmajor = false;
errmajor = ax * 2;
errminor = ay * 2;
bumpmajor = (dy < 0) ? -1 : 1;
bumpminor = (dx < 0) ? -1 : 1;
ay = -ay;
/* For clipping adjustment below */
steps = y2 - y1;
}
error = -(errminor / 2);
if (y1 != origy1) {
int ysteps = y1 - origy1;
if (ysteps < 0) {
ysteps = -ysteps;
}
error += ysteps * ax * 2;
}
if (x1 != origx1) {
int xsteps = x1 - origx1;
if (xsteps < 0) {
xsteps = -xsteps;
}
error += xsteps * ay * 2;
}
if (steps < 0) {
steps = -steps;
}
if (xmajor) {
do {
pw.writePixel(x1, y1);
x1 += bumpmajor;
error += errmajor;
if (error >= 0) {
y1 += bumpminor;
error -= errminor;
}
} while (--steps >= 0);
} else {
do {
pw.writePixel(x1, y1);
y1 += bumpmajor;
error += errmajor;
if (error >= 0) {
x1 += bumpminor;
error -= errminor;
}
} while (--steps >= 0);
}
}
return boundPts;
}
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