Rectangle srcRect = source.getBounds();
int srcRectX = srcRect.x;
int srcRectY = srcRect.y;
RasterAccessor srcAccessor =
new RasterAccessor(source, srcRect,
formatTags[0], getSource(0).getColorModel());
RasterAccessor dstAccessor =
new RasterAccessor(dest, destRect, formatTags[1], getColorModel());
// Loop variables based on the destination rectangle to be calculated.
int dx = destRect.x;
int dy = destRect.y;
int dwidth = destRect.width;
int dheight = destRect.height;
int srcPixelStride = srcAccessor.getPixelStride();
int srcScanlineStride = srcAccessor.getScanlineStride();
int[] ypos = new int[dheight];
int[] xpos = new int[dwidth];
// Precalculate the y positions and store them in an array.
int[] yfracvalues = new int[dheight];
// Precalculate the x positions and store them in an array.
int[] xfracvalues = new int[dwidth];
long syNum = dy, syDenom = 1;
// Subtract the X translation factor sy -= transY
syNum = syNum * transYRationalDenom - transYRationalNum * syDenom;
syDenom *= transYRationalDenom;
// Add 0.5
syNum = 2 * syNum + syDenom;
syDenom *= 2;
// Multply by invScaleX
syNum *= invScaleYRationalNum;
syDenom *= invScaleYRationalDenom;
// Subtract 0.5
syNum = 2 * syNum - syDenom;
syDenom *= 2;
// Separate the x source coordinate into integer and fractional part
int srcYInt = Rational.floor(syNum , syDenom);
long srcYFrac = syNum % syDenom;
if (srcYInt < 0) {
srcYFrac = syDenom + srcYFrac;
}
// Normalize - Get a common denominator for the fracs of
// src and invScaleY
long commonYDenom = syDenom * invScaleYRationalDenom;
srcYFrac *= invScaleYRationalDenom;
long newInvScaleYFrac = invScaleYFrac * syDenom;
long sxNum = dx, sxDenom = 1;
// Subtract the X translation factor sx -= transX
sxNum = sxNum * transXRationalDenom - transXRationalNum * sxDenom;
sxDenom *= transXRationalDenom;
// Add 0.5
sxNum = 2 * sxNum + sxDenom;
sxDenom *= 2;
// Multply by invScaleX
sxNum *= invScaleXRationalNum;
sxDenom *= invScaleXRationalDenom;
// Subtract 0.5
sxNum = 2 * sxNum - sxDenom;
sxDenom *= 2;
// Separate the x source coordinate into integer and fractional part
// int part is floor(sx), frac part is sx - floor(sx)
int srcXInt = Rational.floor(sxNum , sxDenom);
long srcXFrac = sxNum % sxDenom;
if (srcXInt < 0) {
srcXFrac = sxDenom + srcXFrac;
}
// Normalize - Get a common denominator for the fracs of
// src and invScaleX
long commonXDenom = sxDenom * invScaleXRationalDenom;
srcXFrac *= invScaleXRationalDenom;
long newInvScaleXFrac = invScaleXFrac * sxDenom;
for (int i=0; i<dwidth; i++) {
xpos[i] = (srcXInt - srcRectX) * srcPixelStride;
xfracvalues[i] = (int)(((float)srcXFrac/(float)commonXDenom) * one);
// Move onto the next source pixel.
// Add the integral part of invScaleX to the integral part
// of srcX
srcXInt += invScaleXInt;
// Add the fractional part of invScaleX to the fractional part
// of srcX
srcXFrac += newInvScaleXFrac;
// If the fractional part is now greater than equal to the
// denominator, divide so as to reduce the numerator to be less
// than the denominator and add the overflow to the integral part.
if (srcXFrac >= commonXDenom) {
srcXInt += 1;
srcXFrac -= commonXDenom;
}
}
for (int i = 0; i < dheight; i++) {
// Calculate the source position in the source data array.
ypos[i] = (srcYInt - srcRectY) * srcScanlineStride;
// Calculate the yfrac value
yfracvalues[i] = (int)(((float)srcYFrac/(float)commonYDenom) * one);
// Move onto the next source pixel.
// Add the integral part of invScaleY to the integral part
// of srcY
srcYInt += invScaleYInt;
// Add the fractional part of invScaleY to the fractional part
// of srcY
srcYFrac += newInvScaleYFrac;
// If the fractional part is now greater than equal to the
// denominator, divide so as to reduce the numerator to be less
// than the denominator and add the overflow to the integral part.
if (srcYFrac >= commonYDenom) {
srcYInt += 1;
srcYFrac -= commonYDenom;
}
}
switch (dstAccessor.getDataType()) {
case DataBuffer.TYPE_BYTE:
initTableDataI();
byteLoop(srcAccessor, destRect, dstAccessor,
xpos, ypos, xfracvalues, yfracvalues);
break;
case DataBuffer.TYPE_SHORT:
initTableDataI();
shortLoop(srcAccessor, destRect, dstAccessor,
xpos, ypos, xfracvalues, yfracvalues);
break;
case DataBuffer.TYPE_USHORT:
initTableDataI();
ushortLoop(srcAccessor, destRect, dstAccessor,
xpos, ypos, xfracvalues, yfracvalues);
break;
case DataBuffer.TYPE_INT:
initTableDataI();
intLoop(srcAccessor, destRect, dstAccessor,
xpos, ypos, xfracvalues, yfracvalues);
break;
case DataBuffer.TYPE_FLOAT:
initTableDataF();
floatLoop(srcAccessor, destRect, dstAccessor,
xpos, ypos, xfracvalues, yfracvalues);
break;
case DataBuffer.TYPE_DOUBLE:
initTableDataD();
doubleLoop(srcAccessor, destRect, dstAccessor,
xpos, ypos, xfracvalues, yfracvalues);
break;
default:
throw
new RuntimeException(JaiI18N.getString("OrderedDitherOpImage0"));
}
// If the RasterAccessor object set up a temporary buffer for the
// op to write to, tell the RasterAccessor to write that data
// to the raster no that we're done with it.
if (dstAccessor.isDataCopy()) {
dstAccessor.clampDataArrays();
dstAccessor.copyDataToRaster();
}
}