📄 blurfilter.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: BlurFilter.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 BlurFilter
implements Filter
{
public BlurFilter()
{
this(null, 1, 1);
}
public BlurFilter(Image fromImage, int blurSize)
{
this(fromImage, blurSize, 1);
}
public BlurFilter(Image fromImage, int blurSize, int iterations)
{
setIterations(iterations);
setBlurRadius(blurSize);
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 + blurRadius * 0 * 2;
this.height = height + blurRadius * 0 * 2;
rgb = new int[this.width * this.height];
needsRender = true;
}
public Image getImage()
{
return Image.createRGBImage(getRGB(), getWidth(), getHeight(), false);
}
public int[] getRGB()
{
return rgb;
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
public void setBlurRadius(int blurRadius)
{
this.blurRadius = blurRadius;
needsRender = true;
}
public void setIterations(int nbrIterations)
{
iterations = nbrIterations;
needsRender = true;
}
public void render()
{
if(!needsRender)
return;
switch(blurRadius)
{
case 1: // '\001'
tentBlur3x3(fromRGB, rgb, fromRGB, width, height);
break;
case 2: // '\002'
tentBlur5x5(fromRGB, rgb, fromRGB, width, height);
break;
case 3: // '\003'
tentBlur7x7(fromRGB, rgb, fromRGB, width, height);
break;
default:
boxBlur(fromRGB, rgb, fromRGB, width, height, blurRadius - 1, iterations);
break;
}
needsRender = false;
}
public void paintAt(Graphics graphics, int x, int y)
{
render();
graphics.drawRGB(fromRGB, 0, width, x, y, width, height, true);
}
public static void boxBlur(int src[], int temp[], int dest[], int width, int height, int blurRadius, int iterations)
{
if(blurRadius < 1)
return;
int logCount = blurRadius - 1;
int blurLog;
for(blurLog = 1; logCount > 0; blurLog++)
logCount >>= 1;
int rightBoundary = (width + width) - 1;
int bottomBoundary = (height + height) - 1;
int srcHeight = height - blurRadius * 0 * 2;
for(int i = 0; i < iterations; i++)
{
int shift = i & 0x1;
for(int y = 0; y < srcHeight; y++)
{
int y_width = y * width;
int rSum;
int gSum;
int bSum;
int aSum = rSum = gSum = bSum = 0;
for(int k = -blurRadius; k < blurRadius; k++)
{
int xCol = k + shift;
if(xCol < 0)
xCol = -xCol;
else
if(xCol >= width)
xCol = rightBoundary - xCol;
int color = src[xCol + y_width];
aSum += color >>> 24;
rSum += color >> 16 & 0xff;
gSum += color >> 8 & 0xff;
bSum += color & 0xff;
}
temp[y_width] = (aSum >> blurLog) << 24 | (rSum >> blurLog) << 16 | (gSum >> blurLog) << 8 | bSum >> blurLog;
for(int x = 1; x < width; x++)
{
int xOld = (x - blurRadius - 1) + shift;
int xNew = ((x + blurRadius) - 1) + shift;
if(xOld < 0)
xOld = -xOld;
if(xNew >= width)
xNew = rightBoundary - xNew;
int colorOld = src[xOld + y_width];
int colorNew = src[xNew + y_width];
aSum += (colorNew >>> 24) - (colorOld >>> 24);
rSum += (colorNew >> 16 & 0xff) - (colorOld >> 16 & 0xff);
gSum += (colorNew >> 8 & 0xff) - (colorOld >> 8 & 0xff);
bSum += (colorNew & 0xff) - (colorOld & 0xff);
temp[x + y_width] = (aSum >> blurLog) << 24 | (rSum >> blurLog) << 16 | (gSum >> blurLog) << 8 | bSum >> blurLog;
}
}
for(int x = 0; x < width; x++)
{
int rSum;
int gSum;
int bSum;
int aSum = rSum = gSum = bSum = 0;
for(int k = -blurRadius; k < blurRadius; k++)
{
int yCol = k + shift;
if(yCol < 0)
yCol = -yCol;
else
if(yCol >= height)
yCol = bottomBoundary - yCol;
int color = temp[x + yCol * width];
aSum += color >>> 24;
rSum += color >> 16 & 0xff;
gSum += color >> 8 & 0xff;
bSum += color & 0xff;
}
dest[x] = (aSum >> blurLog) << 24 | (rSum >> blurLog) << 16 | (gSum >> blurLog) << 8 | bSum >> blurLog;
for(int y = 1; y < height; y++)
{
int yOld = (y - blurRadius - 1) + shift;
int yNew = ((y + blurRadius) - 1) + shift;
if(yOld < 0)
yOld = -yOld;
if(yNew >= height)
yNew = bottomBoundary - yNew;
int colorOld = temp[x + yOld * width];
int colorNew = temp[x + yNew * width];
aSum += (colorNew >>> 24) - (colorOld >>> 24);
rSum += (colorNew >> 16 & 0xff) - (colorOld >> 16 & 0xff);
gSum += (colorNew >> 8 & 0xff) - (colorOld >> 8 & 0xff);
bSum += (colorNew & 0xff) - (colorOld & 0xff);
dest[x + y * width] = (aSum >> blurLog) << 24 | (rSum >> blurLog) << 16 | (gSum >> blurLog) << 8 | bSum >> blurLog;
}
}
}
}
private static final void tentBlur3x3(int src[], int temp[], int dest[], int width, int height)
{
for(int y = height - 1; y >= 0; y--)
{
int y_width = y * width;
for(int x = width - 2; x > 0; x--)
temp[x + y_width] = (src[(x - 1) + y_width] >> 2 & 0x3f3f3f3f) + (src[x + y_width] >> 1 & 0x7f7f7f7f) + (src[x + 1 + y_width] >> 2 & 0x3f3f3f3f);
}
for(int y = height - 2; y > 0; y--)
{
int y_width = y * width;
int y_width_minus1 = y_width - width;
int y_width_plus1 = y_width + width;
for(int x = width - 1; x >= 0; x--)
dest[x + y_width] = (temp[x + y_width_minus1] >> 2 & 0x3f3f3f3f) + (temp[x + y_width] >> 1 & 0x7f7f7f7f) + (temp[x + y_width_plus1] >> 2 & 0x3f3f3f3f);
}
}
private static final void tentBlur5x5(int src[], int temp[], int dest[], int width, int height)
{
int dblWidth = width << 1;
for(int y = height - 1; y > 1; y--)
{
int y_width = y * width;
for(int x = width - 3; x > 1; x--)
{
int i = src[x + y_width];
int i_minus1 = src[(x - 1) + y_width];
int i_plus1 = src[x + 1 + y_width];
temp[x + y_width] = (src[(x - 2) + y_width] >> 3 & 0x1f1f1f1f) + (i_minus1 >> 3 & 0x1f1f1f1f) + (i_minus1 >> 4 & 0xf0f0f0f) + (i >> 2 & 0x3f3f3f3f) + (i >> 3 & 0x1f1f1f1f) + (i_plus1 >> 3 & 0x1f1f1f1f) + (i_plus1 >> 4 & 0xf0f0f0f) + (src[x + 2 + y_width] >> 3 & 0x1f1f1f1f);
}
}
for(int y = height - 3; y > 1; y--)
{
int y_width = y * width;
for(int x = width - 1; x >= 0; x--)
{
int i = temp[x + y_width];
int i_minus1 = temp[(x + y_width) - width];
int i_plus1 = temp[x + y_width + width];
dest[x + y_width] = (temp[(x + y_width) - dblWidth] >> 3 & 0x1f1f1f1f) + (i_minus1 >> 3 & 0x1f1f1f1f) + (i_minus1 >> 4 & 0xf0f0f0f) + (i >> 2 & 0x3f3f3f3f) + (i >> 3 & 0x1f1f1f1f) + (i_plus1 >> 3 & 0x1f1f1f1f) + (i_plus1 >> 4 & 0xf0f0f0f) + (temp[x + y_width + dblWidth] >> 3 & 0x1f1f1f1f);
}
}
}
private static final void tentBlur7x7(int src[], int temp[], int dest[], int width, int height)
{
int dblWidth = width << 1;
int tplWidth = width * 3;
for(int y = height - 1; y >= 0; y--)
{
int y_width = y * width;
for(int x = width - 4; x > 2; x--)
{
int i_minus1 = src[(x - 1) + y_width];
int i_plus1 = src[x + 1 + y_width];
temp[x + y_width] = (src[(x - 3) + y_width] >> 4 & 0xf0f0f0f) + (src[(x - 2) + y_width] >> 3 & 0x1f1f1f1f) + (i_minus1 >> 3 & 0x1f1f1f1f) + (i_minus1 >> 4 & 0xf0f0f0f) + (src[x + y_width] >> 2 & 0x3f3f3f3f) + (i_plus1 >> 3 & 0x1f1f1f1f) + (i_plus1 >> 4 & 0xf0f0f0f) + (src[x + 2 + y_width] >> 3 & 0x1f1f1f1f) + (src[x + 3 + y_width] >> 4 & 0xf0f0f0f);
}
}
for(int y = height - 4; y > 2; y--)
{
int y_width = y * width;
for(int x = width - 1; x >= 0; x--)
{
int i_minus1 = temp[(x + y_width) - width];
int i_plus1 = temp[x + y_width + width];
dest[x + y_width] = (temp[(x + y_width) - tplWidth] >> 4 & 0xf0f0f0f) + (temp[(x + y_width) - dblWidth] >> 3 & 0x1f1f1f1f) + (i_minus1 >> 3 & 0x1f1f1f1f) + (i_minus1 >> 4 & 0xf0f0f0f) + (temp[x + y_width] >> 2 & 0x3f3f3f3f) + (i_plus1 >> 3 & 0x1f1f1f1f) + (i_plus1 >> 4 & 0xf0f0f0f) + (temp[x + y_width + dblWidth] >> 3 & 0x1f1f1f1f) + (temp[x + y_width + tplWidth] >> 4 & 0xf0f0f0f);
}
}
}
private static final boolean POWER_OF_2_ONLY = true;
protected int fromRGB[];
protected int rgb[];
protected int temp[];
protected int width;
protected int height;
protected int blurRadius;
protected int iterations;
private boolean needsRender;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -