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

📄 png.java

📁 game for basketball. Midlet,support MIDP2.0
💻 JAVA
字号:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.util.*;
import java.io.*;
public class png extends Object
{
	private static final int IDAT_CHUNK =((int)'I' << 24)|
		((int)'D' << 16)|
		((int)'A' << 8)|
		((int)'T');
	private static final int PALETTE_CHUNK =((int)'P' << 24)|
		((int)'L' << 16)|
		((int)'T' << 8)|
		((int)'E');
	private static final int ENDMARK =((int)'I' << 24)|
		((int)'E' << 16)|
		((int)'N' << 8)|
		((int)'D');
	private static boolean IsCRCTableComputed = false;
	private static int[]CRCTable = new int[256];
	protected byte buffer[]= null;
	protected int size = 0;
	protected int plteDataOffset = 0;
	protected int plteSize = 0;
	protected int imageDataOffset = 0;
	protected int imageSize = 0;
	png(String name, byte plteRemaps[], int numRemaps)
	{
		try
		{
			InputStream in = name.getClass().getResourceAsStream(name);
			DataInputStream ind = new DataInputStream(in);
			size = 8;
			in.skip(8);
			int ChnkType, ChnkLen;
			do
			{
				ChnkLen = ind.readInt();
				ChnkType = ind.readInt();
				if(ChnkType == PALETTE_CHUNK)
				{
					plteDataOffset = size + 8;
					plteSize = ChnkLen;
				}
				if(ChnkType == IDAT_CHUNK)
				{
					imageDataOffset = size + 8;
					imageSize = ChnkLen;
				}
				size += ChnkLen + 12;
				in.skip(ChnkLen + 4);
			} while(ENDMARK != ChnkType);
			ind.close();
			buffer = new byte[size];
			in = name.getClass().getResourceAsStream(name);
			ind = new DataInputStream(in);
			size = ind.read(buffer, 0, size);
			ind.close();
			in.close();
		}
		catch(java.io.IOException e)
		{
		}
		catch(Exception e)
		{
		}
		if(0 != plteDataOffset)
		{
			if(null != plteRemaps)
			{
				for(int k = 0; k < numRemaps; k++)
				{
					int pos = 4 * k;
					int index =(((int)plteRemaps[pos]& 0xFF)* 3);
					if(index + 3 > plteSize)
					{
						break;
					}
					index += plteDataOffset;
					buffer[index]= plteRemaps[pos + 1];
					buffer[index + 1]= plteRemaps[pos + 2];
					buffer[index + 2]= plteRemaps[pos + 3];
				}
			}
			int CRC = getCRC(buffer, plteDataOffset - 4, plteSize + 4);
			buffer[plteDataOffset + plteSize]=(byte)((CRC >> 24)& 0xFF);
			buffer[plteDataOffset + plteSize + 1]=(byte)((CRC >> 16)& 0xFF);
			buffer[plteDataOffset + plteSize + 2]=(byte)((CRC >> 8)& 0xFF);
			buffer[plteDataOffset + plteSize + 3]=(byte)((CRC)& 0xFF);
		}
	}
	public static void Touch()
	{
	}
	public Image getImage()
	{
		Image img = null;
		if(null == buffer)
			return null;
		else {
				img = Image.createImage(buffer, 0, size);
			buffer = null;
		}
		return img;
	}
	private static void makeCRCTable()
	{
		int c, n, k;
		for(n = 0; n < 256; n++)
		{
			c = n;
			for(k = 0; k < 8; k++)
			{
				if((c & 1)== 1)
					c = 0xedb88320 ^(c >>> 1);
				else
					c = c >>> 1;
			}
			CRCTable[n]= c;
		}
		IsCRCTableComputed = true;
	}
	private static int getCRC(byte[]buf, int offset, int len)
	{
		if(!IsCRCTableComputed)
			makeCRCTable();
		int crc = 0xffffffff;
		int end = offset + len;
		for(int n = offset; n < end; n++)
		{
			crc = CRCTable[(crc ^ buf[n])& 0xff]^(crc >>> 8);
		}
		return crc ^ 0xffffffff;
	}
}

⌨️ 快捷键说明

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