FileDocCategorySizeDatePackage
ReplicateScaleFilter.javaAPI DocAndroid 1.5 API6734Wed May 06 22:41:54 BST 2009java.awt.image

ReplicateScaleFilter

public 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.
since
Android 1.0

Fields Summary
protected int
srcWidth
The width of a source image.
protected int
srcHeight
The height of a source image.
protected int
destWidth
The width of a destination image.
protected int
destHeight
The height of a destination image.
protected int[]
srcrows
The integer array of source rows.
protected int[]
srccols
The integer array of source columns.
protected Object
outpixbuf
An 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.

param
width the width of scaled image.
param
height the height of scaled image.

        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 voidinitArrays()
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 voidsetDimensions(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 voidsetPixels(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 voidsetPixels(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 voidsetProperties(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);