use of java.awt.image.WritableRaster in project jdk8u_jdk by JetBrains.
the class SunGraphics2D method drawTranslatedRenderedImage.
/**
* Draw a portion of a RenderedImage tile-by-tile with a given
* integer image to user space translation. The user to
* device transform must also be an integer translation.
*/
private void drawTranslatedRenderedImage(RenderedImage img, Rectangle region, int i2uTransX, int i2uTransY) {
// Cache tile grid info
int tileGridXOffset = img.getTileGridXOffset();
int tileGridYOffset = img.getTileGridYOffset();
int tileWidth = img.getTileWidth();
int tileHeight = img.getTileHeight();
// Determine the tile index extrema in each direction
int minTileX = getTileIndex(region.x, tileGridXOffset, tileWidth);
int minTileY = getTileIndex(region.y, tileGridYOffset, tileHeight);
int maxTileX = getTileIndex(region.x + region.width - 1, tileGridXOffset, tileWidth);
int maxTileY = getTileIndex(region.y + region.height - 1, tileGridYOffset, tileHeight);
// Create a single ColorModel to use for all BufferedImages
ColorModel colorModel = img.getColorModel();
// Reuse the same Rectangle for each iteration
Rectangle tileRect = new Rectangle();
for (int ty = minTileY; ty <= maxTileY; ty++) {
for (int tx = minTileX; tx <= maxTileX; tx++) {
// Get the current tile.
Raster raster = img.getTile(tx, ty);
// Fill in tileRect with the tile bounds
tileRect.x = tx * tileWidth + tileGridXOffset;
tileRect.y = ty * tileHeight + tileGridYOffset;
tileRect.width = tileWidth;
tileRect.height = tileHeight;
// Clip the tile against the image bounds and
// backwards mapped clip region
// The result can't be empty
clipTo(tileRect, region);
// Create a WritableRaster containing the tile
WritableRaster wRaster = null;
if (raster instanceof WritableRaster) {
wRaster = (WritableRaster) raster;
} else {
// Create a WritableRaster in the same coordinate system
// as the original raster.
wRaster = Raster.createWritableRaster(raster.getSampleModel(), raster.getDataBuffer(), null);
}
// Translate wRaster to start at (0, 0) and to contain
// only the relevent portion of the tile
wRaster = wRaster.createWritableChild(tileRect.x, tileRect.y, tileRect.width, tileRect.height, 0, 0, null);
// Wrap wRaster in a BufferedImage
BufferedImage bufImg = new BufferedImage(colorModel, wRaster, colorModel.isAlphaPremultiplied(), null);
// Now we have a BufferedImage starting at (0, 0) that
// represents data from a Raster starting at
// (tileRect.x, tileRect.y). Additionally, it needs
// to be translated by (i2uTransX, i2uTransY). We call
// copyImage to draw just the region of interest
// without needing to create a child image.
copyImage(bufImg, tileRect.x + i2uTransX, tileRect.y + i2uTransY, 0, 0, tileRect.width, tileRect.height, null, null);
}
}
}
use of java.awt.image.WritableRaster in project jdk8u_jdk by JetBrains.
the class SunCompositeContext method compose.
/**
* This method composes the two source tiles
* and places the result in the destination tile. Note that
* the destination can be the same object as either
* the first or second source.
* @param src1 The first source tile for the compositing operation.
* @param src2 The second source tile for the compositing operation.
* @param dst The tile where the result of the operation is stored.
*/
public void compose(Raster srcArg, Raster dstIn, WritableRaster dstOut) {
WritableRaster src;
int w;
int h;
if (dstIn != dstOut) {
dstOut.setDataElements(0, 0, dstIn);
}
// BufferedImage.
if (srcArg instanceof WritableRaster) {
src = (WritableRaster) srcArg;
} else {
src = srcArg.createCompatibleWritableRaster();
src.setDataElements(0, 0, srcArg);
}
w = Math.min(src.getWidth(), dstIn.getWidth());
h = Math.min(src.getHeight(), dstIn.getHeight());
BufferedImage srcImg = new BufferedImage(srcCM, src, srcCM.isAlphaPremultiplied(), null);
BufferedImage dstImg = new BufferedImage(dstCM, dstOut, dstCM.isAlphaPremultiplied(), null);
SurfaceData srcData = BufImgSurfaceData.createData(srcImg);
SurfaceData dstData = BufImgSurfaceData.createData(dstImg);
Blit blit = Blit.getFromCache(srcData.getSurfaceType(), comptype, dstData.getSurfaceType());
blit.Blit(srcData, dstData, composite, null, 0, 0, 0, 0, w, h);
}
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 Bug7049339 method main.
public static void main(String[] argv) {
int x = 100, y = 100;
BufferedImage src = new BufferedImage(x, y, BufferedImage.TYPE_INT_ARGB);
BufferedImage dst = new BufferedImage(x, y, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D dstg2d = dst.createGraphics();
dstg2d.setComposite(new Composite() {
@Override
public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) {
return new CompositeContext() {
@Override
public void compose(Raster src, Raster dstIn, WritableRaster dstOut) {
// do nothing
}
@Override
public void dispose() {
}
};
}
});
Shape clip = new Ellipse2D.Double(x / 4, y / 4, x / 2, y / 2);
dstg2d.setClip(clip);
// This will throw a RasterFormatException if the bug is present.
dstg2d.drawImage(src, 0, 0, null);
}
Aggregations