📄 mp3.txt
字号:
package javazoom.Util;
/**
* This class implements a BMP Loader.
*
*-----------------------------------------------------------------------
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*----------------------------------------------------------------------
*/
import java.awt.*;
import java.awt.image.*;
import java.io.*;
/**
* A decoder for Windows bitmap (.BMP) files.
* Compression not supported.
*/
public class BMPLoader
{
private InputStream is;
private int curPos = 0;
private int bitmapOffset; // starting position of image data
private int width; // image width in pixels
private int height; // image height in pixels
private short bitsPerPixel; // 1, 4, 8, or 24 (no color map)
private int compression; // 0 (none), 1 (8-bit RLE), or 2 (4-bit RLE)
private int actualSizeOfBitmap;
private int scanLineSize;
private int actualColorsUsed;
private byte r[], g[], b[]; // color palette
private int noOfEntries;
private byte[] byteData; // Unpacked data
private int[] intData; // Unpacked data
public BMPLoader()
{
}
public Image getBMPImage(InputStream stream) throws Exception
{
read(stream);
return Toolkit.getDefaultToolkit().createImage(getImageSource());
}
private int readInt() throws IOException {
int b1 = is.read();
int b2 = is.read();
int b3 = is.read();
int b4 = is.read();
curPos += 4;
return ((b4 << 24) + (b3 << 16) + (b2 << 8) + (b1 << 0));
}
private short readShort() throws IOException {
int b1 = is.read();
int b2 = is.read();
curPos += 4;
return (short)((b2 << 8) + b1);
}
void getFileHeader() throws IOException, Exception {
// Actual contents (14 bytes):
short fileType = 0x4d42;// always "BM"
int fileSize; // size of file in bytes
short reserved1 = 0; // always 0
short reserved2 = 0; // always 0
fileType = readShort();
if (fileType != 0x4d42)
throw new Exception("Not a BMP file"); // wrong file type
fileSize = readInt();
reserved1 = readShort();
reserved2 = readShort();
bitmapOffset = readInt();
}
void getBitmapHeader() throws IOException {
// Actual contents (40 bytes):
int size; // size of this header in bytes
short planes; // no. of color planes: always 1
int sizeOfBitmap; // size of bitmap in bytes (may be 0: if so, calculate)
int horzResolution; // horizontal resolution, pixels/meter (may be 0)
int vertResolution; // vertical resolution, pixels/meter (may be 0)
int colorsUsed; // no. of colors in palette (if 0, calculate)
int colorsImportant; // no. of important colors (appear first in palette) (0 means all are important)
boolean topDown;
int noOfPixels;
size = readInt();
width = readInt();
height = readInt();
planes = readShort();
bitsPerPixel = readShort();
compression = readInt();
sizeOfBitmap = readInt();
horzResolution = readInt();
vertResolution = readInt();
colorsUsed = readInt();
colorsImportant = readInt();
topDown = (height < 0);
noOfPixels = width * height;
// Scan line is padded with zeroes to be a multiple of four bytes
scanLineSize = ((width * bitsPerPixel + 31) / 32) * 4;
if (sizeOfBitmap != 0)
actualSizeOfBitmap = sizeOfBitmap;
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -