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());
int srcScanlineStride = srcAccessor.getScanlineStride();
int srcPixelStride = srcAccessor.getPixelStride();
// Destination rectangle dimensions.
int dx = destRect.x;
int dy = destRect.y;
int dwidth = destRect.width;
int dheight = destRect.height;
// Precalculate the x positions and store them in an array.
int[] xvalues = new int[dwidth];
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;
// 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++) {
// Calculate the position
xvalues[i] = (srcXInt - srcRectX) * srcPixelStride;
// 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;
}
}
// Precalculate the y positions and store them in an array.
int[] yvalues = new int[dheight];
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;
// 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;
for (int i = 0; i < dheight; i++) {
// Calculate the position
yvalues[i] = (srcYInt - srcRectY) * srcScanlineStride;
// 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:
byteLoop(srcAccessor, destRect, dstAccessor, xvalues, yvalues);
break;
case DataBuffer.TYPE_SHORT:
case DataBuffer.TYPE_USHORT:
shortLoop(srcAccessor, destRect, dstAccessor, xvalues, yvalues);
break;
case DataBuffer.TYPE_INT:
intLoop(srcAccessor, destRect, dstAccessor, xvalues, yvalues);
break;
case DataBuffer.TYPE_FLOAT:
floatLoop(srcAccessor, destRect, dstAccessor, xvalues, yvalues);
break;
case DataBuffer.TYPE_DOUBLE:
doubleLoop(srcAccessor, destRect, dstAccessor, xvalues, yvalues);
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();
}
}