⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rotationfilter.java

📁 Sony Ericsson手机上的Facebook客户端全套代码
💻 JAVA
字号:
// 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:   RotationFilter.java

package se.southend.drops.pixelfilter;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import se.southend.drops.math.IntMath;

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

public class RotationFilter
    implements Filter
{

    public RotationFilter()
    {
        filtering = 0;
    }

    public RotationFilter(Image fromImage)
    {
        filtering = 0;
        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;
        this.width = width;
        this.height = height;
        srcWidth = width;
        srcHeight = height;
        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 setFiltering(int filtering)
    {
        this.filtering = filtering;
    }

    public void setAngle(int theta)
    {
        this.theta = theta;
        sinTheta = IntMath.sin(theta);
        cosTheta = IntMath.cos(theta);
        int absCosTheta = cosTheta >= 0 ? cosTheta : -cosTheta;
        int absSinTheta = sinTheta >= 0 ? sinTheta : -sinTheta;
        width = srcWidth * absCosTheta + srcHeight * absSinTheta >> 16;
        height = srcHeight * absCosTheta + srcWidth * absSinTheta >> 16;
        needsRender = true;
    }

    public void render()
    {
        if(theta != 0)
        {
            rgb = new int[width * height];
            if(filtering == 1)
                rgb = rotateLinear(fromRGB, srcWidth, srcHeight, rgb, width, height, sinTheta, cosTheta);
            else
                rgb = rotateNearest(fromRGB, srcWidth, srcHeight, rgb, width, height, sinTheta, cosTheta);
        }
        needsRender = false;
    }

    public void paintAt(Graphics graphics, int x, int y)
    {
        if(needsRender)
            render();
        if(theta == 0)
            graphics.drawRGB(fromRGB, 0, width, x, y, width, height, true);
        else
            graphics.drawRGB(rgb, 0, width, x, y, width, height, true);
    }

    public static final int[] rotateLinear(int src[], int srcWidth, int srcHeight, int dest[], int width, int height, int sinTheta, int cosTheta)
    {
        int halfSrcWidth = srcWidth >> 1;
        int halfSrcHeight = srcHeight >> 1;
        int halfDestWidth = width >> 1;
        int halfDestHeight = height >> 1;
        for(int yDest = 0; yDest < height; yDest++)
        {
            int yCentered = yDest - halfDestHeight;
            int yCentered_sinTheta = yCentered * sinTheta;
            int yCentered_cosTheta = yCentered * cosTheta;
            int yDest_destWidth = yDest * width;
            for(int xDest = 0; xDest < width; xDest++)
            {
                int xCentered = xDest - halfDestWidth;
                int xRotated = xCentered * cosTheta + yCentered_sinTheta >> 8;
                int yRotated = -xCentered * sinTheta + yCentered_cosTheta >> 8;
                int xInteger = (xRotated >> 8) + halfSrcWidth;
                int yInteger = (yRotated >> 8) + halfSrcHeight;
                int srcInArray = xInteger + yInteger * srcWidth;
                int tl = yInteger >= srcHeight || xInteger >= srcWidth || xInteger <= -1 || yInteger <= -1 ? 0 : src[srcInArray];
                int tr = yInteger >= srcHeight || xInteger + 1 >= srcWidth || xInteger <= -2 || yInteger <= -1 ? 0 : src[srcInArray + 1];
                int bl = yInteger + 1 >= srcHeight || xInteger >= srcWidth || xInteger <= -1 || yInteger <= -2 ? 0 : src[srcInArray + srcWidth];
                int br = yInteger + 1 >= srcHeight || xInteger + 1 >= srcWidth || xInteger <= -2 || yInteger <= -2 ? 0 : src[srcInArray + srcWidth + 1];
                int xDecimal = xRotated & 0xff;
                int yDecimal = yRotated & 0xff;
                int colorTop = RGBTools.blend32(tl, tr, xDecimal >> 3);
                int colorBtm = RGBTools.blend32(bl, br, xDecimal >> 3);
                int color = RGBTools.blend32(colorTop, colorBtm, yDecimal >> 3);
                dest[yDest_destWidth + xDest] = color;
            }

        }

        return dest;
    }

    public static final int[] rotateNearest(int src[], int srcWidth, int srcHeight, int dest[], int width, int height, int sinTheta, int cosTheta)
    {
        int halfSrcWidth = srcWidth >> 1;
        int halfSrcHeight = srcHeight >> 1;
        int halfDestWidth = width >> 1;
        int halfDestHeight = height >> 1;
        for(int yDest = 0; yDest < height; yDest++)
        {
            int yCentered = yDest - halfDestHeight;
            int yCentered_sinTheta = yCentered * sinTheta;
            int yCentered_cosTheta = yCentered * cosTheta;
            int yDest_destWidth = yDest * width;
            for(int xDest = 0; xDest < width; xDest++)
            {
                int xCentered = xDest - halfDestWidth;
                int xRotated = xCentered * cosTheta + yCentered_sinTheta >> 8;
                int yRotated = -xCentered * sinTheta + yCentered_cosTheta >> 8;
                int xInteger = (xRotated >> 8) + halfSrcWidth;
                int yInteger = (yRotated >> 8) + halfSrcHeight;
                int srcInArray = xInteger + yInteger * srcWidth;
                int color = yInteger >= srcHeight || xInteger >= srcWidth || xInteger <= -1 || yInteger <= -1 ? 0 : src[srcInArray];
                dest[yDest_destWidth + xDest] = color;
            }

        }

        return dest;
    }

    public static final int FILTER_NEAREST = 0;
    public static final int FILTER_LINEAR = 1;
    public static final int TRANS_NONE = 0;
    public static final int TRANS_FLIP_VERTICAL = 1;
    public static final int TRANS_FLIP_HORIZONTAL = 2;
    public static final int TRANS_ROTATE_180 = 4;
    public static final int TRANS_ROTATE_90_CW = 8;
    public static final int TRANS_ROTATE_90_CCW = 16;
    private int filtering;
    protected int fromRGB[];
    protected int rgb[];
    protected int width;
    protected int height;
    protected int srcWidth;
    protected int srcHeight;
    protected int theta;
    protected int sinTheta;
    protected int cosTheta;
    private boolean needsRender;
}

⌨️ 快捷键说明

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