mirrorfilter.java

来自「Sony Ericsson手机上的Facebook客户端全套代码」· Java 代码 · 共 149 行

JAVA
149
字号
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   MirrorFilter.java

package se.southend.drops.pixelfilter;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

// Referenced classes of package se.southend.drops.pixelfilter:
//            Filter

public class MirrorFilter
    implements Filter
{

    public MirrorFilter()
    {
    }

    public MirrorFilter(Image fromImage)
    {
        setImage(fromImage);
    }

    public void setImage(Image fromImage)
    {
        if(fromImage == null)
        {
            return;
        } else
        {
            int width = fromImage.getWidth();
            int height = fromImage.getHeight();
            rgb = new int[width * height];
            fromImage.getRGB(rgb, 0, width, 0, 0, width, height);
            setRGB(rgb, width, height);
            return;
        }
    }

    public void setRGB(int fromRGB[], int width, int height)
    {
        this.fromRGB = fromRGB;
        this.width = width;
        this.height = height;
        if(rgb == null || rgb.length != fromRGB.length)
            rgb = new int[fromRGB.length];
        needsRender = true;
    }

    public Image getImage()
    {
        return Image.createRGBImage(getRGB(), getWidth(), getHeight(), true);
    }

    public int[] getRGB()
    {
        return rgb;
    }

    public int getWidth()
    {
        return width;
    }

    public int getHeight()
    {
        return height;
    }

    public void setMode(int mode)
    {
        this.mode = mode;
    }

    public void setAlpha(int alpha)
    {
        if(alpha == this.alpha)
        {
            return;
        } else
        {
            this.alpha = alpha;
            needsRender = true;
            return;
        }
    }

    public void setClipHeight(int height)
    {
        clipHeight = height;
        rgb = new int[width * height];
    }

    public void render()
    {
        if(mode == 0)
            rgb = fadeARGB(fromRGB, rgb, width, height, clipHeight, alpha);
        else
            rgb = fade(rgb, width, height, clipHeight, alpha);
    }

    public void paintAt(Graphics graphics, int x, int y)
    {
        if(needsRender)
            render();
        graphics.drawRGB(rgb, 0, width, x, y, width, clipHeight, true);
    }

    public static final int[] fade(int dest[], int width, int height, int clipHeight, int alpha)
    {
        int length = width * clipHeight;
        for(int i = length - 1; i >= 0; i--)
            dest[i] = dest[i] & 0xffffff | alpha << 24;

        return dest;
    }

    public static final int[] fadeARGB(int src[], int dest[], int width, int height, int clipHeight, int alpha)
    {
        for(int y = clipHeight - 1; y >= 0; y--)
        {
            int scanline = y * width;
            int mirrorscanline = (height - 1 - y) * width;
            for(int x = width - 1; x >= 0; x--)
            {
                int argb = src[x + mirrorscanline];
                dest[x + scanline] = argb & 0xffffff | ((argb >>> 24) * alpha >> 8) << 24;
            }

        }

        return dest;
    }

    public static final int MODE_ARGB = 0;
    public static final int MODE_RGB = 1;
    protected int fromRGB[];
    protected int rgb[];
    protected int width;
    protected int height;
    protected int alpha;
    protected int mode;
    protected int clipHeight;
    private boolean needsRender;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?