home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Late Night VRML 2.0 with Java CD-ROM
/
code.zip
/
Ch13
/
quake
/
BMP.java
< prev
next >
Wrap
Text File
|
1996-11-19
|
2KB
|
45 lines
// BMP file writer
// Written by Bernie Roehl, November 1996
package quake;
import java.io.*;
public class BMP {
static public void dump(String filename, byte[] picture, int width, int height, byte[] palette)
throws IOException {
DataOutputStream out = new DataOutputStream(new FileOutputStream(filename));
// write out file header
out.writeByte('B');
out.writeByte('M');
// total size is sizeof file header + sizeof bmp header + sizeof palette + bits
out.writeInt(swap32(14 + 40 + 1024 + width * height)); // total size
out.writeInt(0);
out.writeInt(swap32(14 + 40 + 1024)); // offset to bits
// write out BMP header
out.writeInt(swap32(40)); // size of bitmap header
out.writeInt(swap32(width)); // width
out.writeInt(swap32(height)); // height
out.writeInt(0x01000800);
// next few are zero for defaults
out.writeInt(0); // compression type
out.writeInt(0); // size of the bitmap in bytes
out.writeInt(0); // horizontal resolution
out.writeInt(0); // vertical resolution
out.writeInt(0); // number of colors in image
out.writeInt(0); // number of important colors
out.write(palette); // write out palette
out.write(picture); // write out bits
}
static int swap32(int value) {
return
((value >> 24) & 0x000000FF) +
((value >> 8) & 0x0000FF00) +
((value << 8) & 0x00FF0000) +
((value << 24) & 0xFF000000);
}
}