waterfilter.java

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

JAVA
137
字号
// 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:   WaterFilter.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 WaterFilter
    implements Filter
{

    public WaterFilter()
    {
    }

    public WaterFilter(Image fromImage, int waveAmplitude)
    {
        setWaveAmplitude(waveAmplitude);
        setImage(fromImage);
    }

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

    public void setRGB(int fromRGB[], int width, int height)
    {
        this.fromRGB = fromRGB;
        srcWidth = width;
        srcHeight = height;
        this.width = width + 0 * waveAmplitude * 2;
        this.height = height + 0 * waveAmplitude * 2;
        rgb = new int[this.width * this.height];
    }

    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 setWaveAmplitude(int waveAmplitude)
    {
        this.waveAmplitude = waveAmplitude;
    }

    public void setWaveFrequency(int waveFrequency)
    {
        switch(waveFrequency)
        {
        case 1: // '\001'
            this.waveFrequency = 25;
            break;
        }
    }

    public void render()
    {
        rgb = waves(fromRGB, width, height, rgb, width, height, waveAmplitude);
    }

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

    public final int[] waves(int src[], int srcWidth, int srcHeight, int dest[], int width, int height, int waveAmplitude)
    {
        waveAmplitude = 3;
        phase++;
        int dist = 0;
        float alpha = (float)((6.2831853071795862D * (double)phase) / 20D);
        for(int y = 0; y < height; y++)
        {
            int yDest = (int)((double)waveAmplitude * Math.sin(alpha + (float)dist));
            int xDest = 0 * yDest;
            if(y + yDest >= 0 && y + yDest < height)
            {
                int srcScanline = (y + yDest) * width;
                int destScanline = (height - 1 - y) * width + xDest;
                for(int x = 0; x < width - 0; x++)
                    dest[x + destScanline] = src[x + srcScanline];

            }
            dist += PERIOD_MULT;
        }

        return dest;
    }

    protected int fromRGB[];
    protected int rgb[];
    protected int srcWidth;
    protected int srcHeight;
    protected int width;
    protected int height;
    protected int waveAmplitude;
    protected int waveFrequency;
    private static int PERIOD_MULT = 50;
    private static final int PERIOD_FRAMES = 20;
    private int phase;

}

⌨️ 快捷键说明

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