ReplicateScaleFilterpublic class ReplicateScaleFilter extends ImageFilter The ReplicateScaleFilter class scales an source image by replicating rows and
columns of pixels to scale up or omitting rows and columns of pixels to scale
down. |
Fields Summary |
---|
protected int | srcWidthThe width of a source image. | protected int | srcHeightThe height of a source image. | protected int | destWidthThe width of a destination image. | protected int | destHeightThe height of a destination image. | protected int[] | srcrowsThe integer array of source rows. | protected int[] | srccolsThe integer array of source columns. | protected Object | outpixbufAn Object (byte array with a destination width) provides a row of pixel
data to the ImageConsumer. |
Constructors Summary |
---|
public ReplicateScaleFilter(int width, int height)Instantiates a new ReplicateScaleFilter that filters the image with the
specified width and height.
if (width == 0 || height == 0) {
// awt.234=Width or Height equals zero
throw new IllegalArgumentException(Messages.getString("awt.234")); //$NON-NLS-1$
}
this.destWidth = width;
this.destHeight = height;
|
Methods Summary |
---|
private void | initArrays()Initialization of srccols and srcrows arrays.
if ((destWidth < 0) || (destHeight < 0)) {
throw new IndexOutOfBoundsException();
}
srccols = new int[destWidth];
int ca = srcWidth >>> 1;
for (int i = 0; i < destWidth; i++) {
srccols[i] = (i * srcWidth + ca) / destWidth;
}
srcrows = new int[destHeight];
int ra = srcHeight >>> 1;
for (int i = 0; i < destHeight; i++) {
srcrows[i] = (i * srcHeight + ra) / destHeight;
}
| public void | setDimensions(int w, int h)
srcWidth = w;
srcHeight = h;
if (destWidth < 0 && destHeight < 0) {
destWidth = srcWidth;
destHeight = srcHeight;
} else if (destWidth < 0) {
destWidth = destHeight * srcWidth / srcHeight;
} else if (destHeight < 0) {
destHeight = destWidth * srcHeight / srcWidth;
}
consumer.setDimensions(destWidth, destHeight);
| public void | setPixels(int x, int y, int w, int h, java.awt.image.ColorModel model, int[] pixels, int off, int scansize)
if (srccols == null) {
initArrays();
}
int buff[];
if (outpixbuf == null || !(outpixbuf instanceof int[])) {
buff = new int[destWidth];
outpixbuf = buff;
} else {
buff = (int[])outpixbuf;
}
int wa = (srcWidth - 1) >>> 1;
int ha = (srcHeight - 1) >>> 1;
int dstX = (x * destWidth + wa) / srcWidth;
int dstY = (y * destHeight + ha) / srcHeight;
int sx, sy, dx, dy;
dy = dstY;
while ((dy < destHeight) && ((sy = srcrows[dy]) < y + h)) {
dx = dstX;
int srcOff = off + (sy - y) * scansize;
while ((dx < destWidth) && ((sx = srccols[dx]) < x + w)) {
buff[dx] = pixels[srcOff + (sx - x)];
dx++;
}
consumer.setPixels(dstX, dy, dx - dstX, 1, model, buff, dstX, destWidth);
dy++;
}
| public void | setPixels(int x, int y, int w, int h, java.awt.image.ColorModel model, byte[] pixels, int off, int scansize)
if (srccols == null) {
initArrays();
}
byte buff[];
if (outpixbuf == null || !(outpixbuf instanceof byte[])) {
buff = new byte[destWidth];
outpixbuf = buff;
} else {
buff = (byte[])outpixbuf;
}
int wa = (srcWidth - 1) >>> 1;
int ha = (srcHeight - 1) >>> 1;
int dstX = (x * destWidth + wa) / srcWidth;
int dstY = (y * destHeight + ha) / srcHeight;
int sx, sy, dx, dy;
dy = dstY;
while ((dy < destHeight) && ((sy = srcrows[dy]) < y + h)) {
dx = dstX;
int srcOff = off + (sy - y) * scansize;
while ((dx < destWidth) && ((sx = srccols[dx]) < x + w)) {
buff[dx] = pixels[srcOff + (sx - x)];
dx++;
}
consumer.setPixels(dstX, dy, dx - dstX, 1, model, buff, dstX, destWidth);
dy++;
}
| public void | setProperties(java.util.Hashtable props)
Hashtable<Object, Object> fprops;
if (props == null) {
fprops = new Hashtable<Object, Object>();
} else {
fprops = (Hashtable<Object, Object>)props.clone();
}
String propName = "Rescale Filters"; //$NON-NLS-1$
String prop = "destWidth=" + destWidth + "; " + //$NON-NLS-1$ //$NON-NLS-2$
"destHeight=" + destHeight; //$NON-NLS-1$
Object o = fprops.get(propName);
if (o != null) {
if (o instanceof String) {
prop = (String)o + "; " + prop; //$NON-NLS-1$
} else {
prop = o.toString() + "; " + prop; //$NON-NLS-1$
}
}
fprops.put(propName, prop);
consumer.setProperties(fprops);
|
|