d.copyDataToRaster();
}
}
private void computeRectByte(PlanarImage src, RasterAccessor dst) {
RandomIter iter;
if(extender != null) {
Rectangle bounds = new Rectangle(src.getMinX(), src.getMinY(),
src.getWidth() + 1,
src.getHeight() + 1);
iter = RandomIterFactory.create(src.getExtendedData(bounds,
extender),
bounds);
} else {
iter = RandomIterFactory.create(src, src.getBounds());
}
int minX = src.getMinX();
int maxX = src.getMaxX() -
(extender != null ? 0 : 1); // Right padding
int minY = src.getMinY();
int maxY = src.getMaxY() -
(extender != null ? 0 : 1); // Bottom padding
int dstWidth = dst.getWidth();
int dstHeight = dst.getHeight();
int dstBands = dst.getNumBands();
int lineStride = dst.getScanlineStride();
int pixelStride = dst.getPixelStride();
int[] bandOffsets = dst.getBandOffsets();
byte[][] data = dst.getByteDataArrays();
float[] warpData = new float[2 * dstWidth];
int lineOffset = 0;
byte[] backgroundByte = new byte[dstBands];
for (int i = 0; i < dstBands; i++)
backgroundByte[i] = (byte)backgroundValues[i];
if (ctable == null) { // source does not have IndexColorModel
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
warp.warpRect(dst.getX(), dst.getY()+h, dstWidth, 1,
warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
float sx = warpData[count++];
float sy = warpData[count++];
int xint = floor(sx);
int yint = floor(sy);
float xfrac = sx - xint;
float yfrac = sy - yint;
if (xint < minX || xint >= maxX ||
yint < minY || yint >= maxY) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset+bandOffsets[b]] =
backgroundByte[b];
}
}
} else {
for (int b = 0; b < dstBands; b++) {
int s00 = iter.getSample(xint, yint, b) & 0xFF;
int s01 = iter.getSample(xint+1, yint, b) & 0xFF;
int s10 = iter.getSample(xint, yint+1, b) & 0xFF;
int s11 = iter.getSample(xint+1, yint+1, b) & 0xFF;
float s0 = (s01 - s00) * xfrac + s00;
float s1 = (s11 - s10) * xfrac + s10;
float s = (s1 - s0) * yfrac + s0;
data[b][pixelOffset+bandOffsets[b]] = (byte)s;
}
}
pixelOffset += pixelStride;
}
}
} else { // source has IndexColorModel
for (int h = 0; h < dstHeight; h++) {
int pixelOffset = lineOffset;
lineOffset += lineStride;
warp.warpRect(dst.getX(), dst.getY()+h, dstWidth, 1,
warpData);
int count = 0;
for (int w = 0; w < dstWidth; w++) {
float sx = warpData[count++];
float sy = warpData[count++];
int xint = floor(sx);
int yint = floor(sy);
float xfrac = sx - xint;
float yfrac = sy - yint;
if (xint < minX || xint >= maxX ||
yint < minY || yint >= maxY) {
/* Fill with a background color. */
if (setBackground) {
for (int b = 0; b < dstBands; b++) {
data[b][pixelOffset+bandOffsets[b]] =
backgroundByte[b];
}
}
} else {
for (int b = 0; b < dstBands; b++) {
byte[] t = ctable[b];
int s00 = t[iter.getSample(xint, yint, 0) &
0xFF] & 0xFF;
int s01 = t[iter.getSample(xint+1, yint, 0) &
0xFF] & 0xFF;
int s10 = t[iter.getSample(xint, yint+1, 0) &
0xFF] & 0xFF;
int s11 = t[iter.getSample(xint+1, yint+1, 0) &
0xFF] & 0xFF;
float s0 = (s01 - s00) * xfrac + s00;
float s1 = (s11 - s10) * xfrac + s10;
float s = (s1 - s0) * yfrac + s0;