pixelimage.java
来自「Sony Ericsson手机上的Facebook客户端全套代码」· Java 代码 · 共 170 行
JAVA
170 行
// 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: PixelImage.java
package se.southend.drops.gui;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class PixelImage
{
public PixelImage(Image image)
{
this(image.getWidth(), image.getHeight());
replace(image, 0, 0);
}
public PixelImage(int width, int height)
{
imageWidth = width;
imageHeight = height;
pixels = new int[imageWidth * imageHeight];
}
public int getWidth()
{
return imageWidth;
}
public int getHeight()
{
return imageHeight;
}
public int[] getRGB()
{
return pixels;
}
public Image getImage()
{
return Image.createRGBImage(pixels, imageWidth, imageHeight, true);
}
public void clear(int argb)
{
for(int i = pixels.length - 1; i >= 0; i--)
pixels[i] = argb;
}
public void replace(Image image, int x, int y)
{
replace(getPixels(image), x, y, image.getWidth(), image.getHeight());
}
public void replace(int argb[], int x, int y, int width, int height)
{
setRegion(x, y, width, height);
for(int yPos = yBeg; yPos < yEnd; yPos++)
{
int srcScanlength = (yPos - y) * width;
int destScanlength = yPos * imageWidth;
for(int xPos = xBeg; xPos < xEnd; xPos++)
pixels[destScanlength + xPos] = argb[(srcScanlength + xPos) - x];
}
}
public void blend(Image image, int x, int y)
{
blend(getPixels(image), x, y, image.getWidth(), image.getHeight());
}
public void blend(int argb[], int x, int y, int width, int height)
{
setRegion(x, y, width, height);
for(int yPos = yBeg; yPos < yEnd; yPos++)
{
int srcScanlength = (yPos - y) * width;
int destScanlength = yPos * imageWidth;
for(int xPos = xBeg; xPos < xEnd; xPos++)
{
int fg = argb[(srcScanlength + xPos) - x];
int bg = pixels[destScanlength + xPos];
int fgalpha = fg >>> 24;
int bgalpha = bg >>> 24;
int total = fgalpha + bgalpha;
if(total > 255)
total = 255;
int fgpart = (fgalpha << 8) / (total + 1);
int bgpart = 0xff ^ fgpart;
int a = 255 - ((0xff ^ fgalpha) * (0xff ^ bgalpha) >>> 8);
int r = (bg >>> 16 & 0xff) * bgpart + (fg >>> 16 & 0xff) * fgpart >>> 8;
int g = (bg >>> 8 & 0xff) * bgpart + (fg >>> 8 & 0xff) * fgpart >>> 8;
int b = (bg & 0xff) * bgpart + (fg & 0xff) * fgpart >>> 8;
pixels[destScanlength + xPos] = a << 24 | r << 16 | g << 8 | b;
}
}
}
public void add(Image image, int gain, int x, int y)
{
add(getPixels(image), gain, x, y, image.getWidth(), image.getHeight());
}
public void add(int argb[], int gain, int x, int y, int width, int height)
{
setRegion(x, y, width, height);
for(int yPos = yBeg; yPos < yEnd; yPos++)
{
int srcScanlength = (yPos - y) * width;
int destScanlength = yPos * imageWidth;
for(int xPos = xBeg; xPos < xEnd; xPos++)
{
int fg = argb[(srcScanlength + xPos) - x];
int bg = pixels[destScanlength + xPos];
int fgalpha = fg >>> 24;
int r = (bg >>> 16 & 0xff) + ((fg >>> 16 & 0xff) * gain * fgalpha >>> 8);
int g = (bg >>> 8 & 0xff) + ((fg >>> 8 & 0xff) * gain * fgalpha >>> 8);
int b = (bg & 0xff) + ((fg & 0xff) * gain * fgalpha >>> 8);
if(r > 255)
r = 255;
if(g > 255)
g = 255;
if(b > 255)
b = 255;
pixels[destScanlength + xPos] = bg & 0xffffff | r << 16 | g << 8 | b;
}
}
}
private final void setRegion(int x, int y, int width, int height)
{
xBeg = x <= 0 ? 0 : x;
xEnd = x + width >= imageWidth ? imageWidth : x + width;
yBeg = y <= 0 ? 0 : y;
yEnd = y + height >= imageHeight ? imageHeight : y + height;
}
private static final int[] getPixels(Image image)
{
int width = image.getWidth();
int height = image.getHeight();
int argb[] = new int[width * height];
image.getRGB(argb, 0, width, 0, 0, width, height);
return argb;
}
public void paint(Graphics graphics)
{
graphics.drawRGB(pixels, 0, imageWidth, 0, 0, imageWidth, imageHeight, true);
}
private int pixels[];
private int imageWidth;
private int imageHeight;
private int xBeg;
private int yBeg;
private int xEnd;
private int yEnd;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?