NativeSurfacepublic final class NativeSurface extends Object implements Surface
Fields Summary |
---|
private final int | width | private final int | height | private final int[] | data |
Constructors Summary |
---|
public NativeSurface(int width, int height)
this(null, width, height);
| public NativeSurface(int[] data, int width, int height)
this.data = (data != null) ? data : new int[width * height];
this.width = width;
this.height = height;
|
Methods Summary |
---|
public SurfaceDestination | createSurfaceDestination()
return new NativeSurfaceDestination();
| private void | drawRGBImpl(int[] argb, int offset, int scanLength, int x, int y, int width, int height, float opacity)
int srcX = 0;
int srcY = 0;
if (x < 0) {
srcX -= x;
width += x;
x = 0;
}
if (y < 0) {
srcY -= y;
height += y;
y = 0;
}
if ((x + width) > this.width) {
width = this.width - x;
}
if ((y + height) > this.height) {
height = this.height - y;
}
if ((width > 0) && (height > 0)) {
offset += srcY * scanLength + srcX;
paint(data, y * this.width + x, this.width,
argb, offset, scanLength,
width, height, opacity);
}
| int[] | getData()
return data;
| public int | getHeight()
return height;
| public void | getRGB(int[] argb, int offset, int scanLength, int x, int y, int width, int height)
if ((argb == data) && (offset == 0) && (scanLength == this.width) &&
(x == 0) && (y == 0) &&
(width == this.width) && (height == this.height)) {
return;
}
int dstX = 0;
int dstY = 0;
if (x < 0) {
dstX -= x;
width += x;
x = 0;
}
if (y < 0) {
dstY -= y;
height += y;
y = 0;
}
if ((x + width) > this.width) {
width = this.width - x;
}
if ((y + height) > this.height) {
height = this.height - y;
}
if ((width > 0) && (height > 0)) {
offset += dstY * scanLength + dstX;
transfer(argb, offset, scanLength,
data, y * this.width + x, this.width,
width, height);
}
| public int | getWidth()
return width;
| private static void | paint(int[] dstRGB, int dstOffset, int dstScanLength, int[] srcRGB, int srcOffset, int srcScanLength, int width, int height, float opacity)
int srcScanRest = srcScanLength - width;
int dstScanRest = dstScanLength - width;
int op = (int)(0x100 * opacity);
for (; height > 0; --height) {
for (int w = width; w > 0; --w) {
int salpha = ((srcRGB[srcOffset] >> 24) & 0xff) * op;
if (salpha == 0xff00) {
dstRGB[dstOffset++] = srcRGB[srcOffset++];
} else {
int dval = dstRGB[dstOffset];
int dalpha = (dval >> 24) & 0xff;
int anom = 255 * salpha;
int bnom = dalpha * (0xff00 - salpha);
int denom = anom + bnom;
if (denom > 0) {
long recip = ((long)1 << 32) / denom;
long fa = anom * recip;
long fb = bnom * recip;
int sval = srcRGB[srcOffset];
int oalpha = ((257 * denom) >> 24) & 0xff;
int ored = (int)((fa * ((sval >> 16) & 0xff) +
fb * ((dval >> 16) & 0xff)) >> 32);
int ogreen = (int)((fa * ((sval >> 8) & 0xff) +
fb * ((dval >> 8) & 0xff)) >> 32);
int oblue = (int)((fa * (sval & 0xff) +
fb * (dval & 0xff)) >> 32);
dstRGB[dstOffset] = (oalpha << 24) |
(ored << 16) | (ogreen << 8) | oblue;
}
++srcOffset;
++dstOffset;
}
}
srcOffset += srcScanRest;
dstOffset += dstScanRest;
}
| public void | setRGB(int[] argb, int offset, int scanLength, int x, int y, int width, int height)
if ((argb == data) && (offset == 0) && (scanLength == this.width) &&
(x == 0) && (y == 0) &&
(width == this.width) && (height == this.height)) {
return;
}
int srcX = 0;
int srcY = 0;
if (x < 0) {
srcX -= x;
width += x;
x = 0;
}
if (y < 0) {
srcY -= y;
height += y;
y = 0;
}
if ((x + width) > this.width) {
width = this.width - x;
}
if ((y + height) > this.height) {
height = this.height - y;
}
if ((width > 0) && (height > 0)) {
offset += srcY * scanLength + srcX;
transfer(data, y * this.width + x, this.width,
argb, offset, scanLength,
width, height);
}
| private static void | transfer(int[] dstRGB, int dstOffset, int dstScanLength, int[] srcRGB, int srcOffset, int srcScanLength, int width, int height)
int srcScanRest = srcScanLength - width;
int dstScanRest = dstScanLength - width;
for (; height > 0; --height) {
for (int w = width; w > 0; --w) {
dstRGB[dstOffset++] = srcRGB[srcOffset++];
}
srcOffset += srcScanRest;
dstOffset += dstScanRest;
}
|
|