int dx2 = (int) Math.ceil(ddx2);
int dy2 = (int) Math.ceil(ddy2);
SurfaceType dstType = dstData.getSurfaceType();
MaskBlit maskblit;
Blit blit;
if (sg.compositeState <= sg.COMP_ALPHA) {
/* NOTE: We either have, or we can make,
* a MaskBlit for any alpha composite type
*/
maskblit = MaskBlit.getFromCache(SurfaceType.IntArgbPre,
sg.imageComp,
dstType);
/* NOTE: We can only use the native TransformHelper
* func to go directly to the dest if both the helper
* and the MaskBlit are native.
* All helpers are native at this point, but some MaskBlit
* objects are implemented in Java, so we need to check.
*/
if (maskblit.getNativePrim() != 0) {
// We can render directly.
helper.Transform(maskblit, srcData, dstData,
sg.composite, clip,
itx, interpType,
sx1, sy1, sx2, sy2,
dx1, dy1, dx2, dy2,
null, 0, 0);
return;
}
blit = null;
} else {
/* NOTE: We either have, or we can make,
* a Blit for any composite type, even Custom
*/
maskblit = null;
blit = Blit.getFromCache(SurfaceType.IntArgbPre,
sg.imageComp,
dstType);
}
// We need to transform to a temp image and then copy
// just the pieces that are valid data to the dest.
BufferedImage tmpimg = new BufferedImage(dx2-dx1, dy2-dy1,
BufferedImage.TYPE_INT_ARGB);
SurfaceData tmpData = SurfaceData.getPrimarySurfaceData(tmpimg);
SurfaceType tmpType = tmpData.getSurfaceType();
MaskBlit tmpmaskblit =
MaskBlit.getFromCache(SurfaceType.IntArgbPre,
CompositeType.SrcNoEa,
tmpType);
/*
* The helper function fills a temporary edges buffer
* for us with the bounding coordinates of each scanline
* in the following format:
*
* edges[0, 1] = [top y, bottom y)
* edges[2, 3] = [left x, right x) of top row
* ...
* edges[h*2, h*2+1] = [left x, right x) of bottom row
*
* all coordinates in the edges array will be relative to dx1, dy1
*
* edges thus has to be h*2+2 in length
*/
int edges[] = new int[(dy2-dy1)*2+2];
helper.Transform(tmpmaskblit, srcData, tmpData,
AlphaComposite.Src, null,
itx, interpType,
sx1, sy1, sx2, sy2,
0, 0, dx2-dx1, dy2-dy1,
edges, dx1, dy1);
/*
* Now copy the results, scanline by scanline, into the dest.
* The edges array helps us minimize the work.
*/
int index = 2;
for (int y = edges[0]; y < edges[1]; y++) {
int relx1 = edges[index++];
int relx2 = edges[index++];
if (relx1 >= relx2) {
continue;
}
if (maskblit != null) {
maskblit.MaskBlit(tmpData, dstData,
sg.composite, clip,
relx1, y,
dx1+relx1, dy1+y,
relx2 - relx1, 1,
null, 0, 0);
} else {
blit.Blit(tmpData, dstData,
sg.composite, clip,
relx1, y,
dx1+relx1, dy1+y,
relx2 - relx1, 1);
}