package bmpviewer.bmp; /** * Super class of BmpReader and BmpWriter. *

* @author Hiroyuki Murata * @since JDK1.1 */ public abstract class BmpHeader { static final int // pointers in BITMAPFILEHEADER pbfType = 0, // (2) pbfSize = 2, // (4) pbfReserved1 = 6, // (2) pbfReserved2 = 8, // (2) pbfOffBits = 10, // (4) bf_size = 14, // pointers in BITMAPINFOHEADER pbiSize = 0, // (4) pbiWidth = 4, // (4) pbiHeight = 8, // (4) pbiPlanes = 12, // (2) pbiBitCount = 14, // (2) pbiCompression = 16, // (4) pbiSizeImage = 20, // (4) pbiXPelsPerMeter = 24, // (4) pbiYPelsPerMeter = 28, // (4) pbiClrUsed = 32, // (4) pbiClrImportant = 36, // (4) bi_size = 40 ; int // members of BITMAPFILEHEADER bfType, // (2) Type of object; set to "BM" bfSize, // (4) Size of the file, in bytes. bfReserved1, // (2) Reserved, set to zero. bfReserved2, // (2) Reserved, set to zero. bfOffBits, // (4) Offset, in bytes, from this structure // to the actual bitmap in the file. // members of BITMAPINFOHEADER biSize, // (4) # of bytes required by this structure. biWidth, // (4) Width of the image, in pixels. biHeight, // (4) Height of the image, in pixels. biPlanes, // (2) # of planes for the target device. biBitCount, // (2) # of bits per pixel. Must be 1, 4, 8, or 24. biCompression, // (4) Specifies the compression used. biSizeImage, // (4) Size of the image, in bytes. biXPelsPerMeter, // (4) Horizontal resolution of the image. biYPelsPerMeter, // (4) Vertical resolution of the image. biClrUsed, // (4) # of colors in the color table used by the image. biClrImportant // (4) # of important colors. ; ByteArrayManipulator fileheader,infoheader; /** * String representation. */ public String toString() { return "bfType = " + fileToHex2(pbfType) + "\n" + "bfSize = " + fileToHex4(pbfSize) + "\n" + "bfReserved1 = " + fileToHex2(pbfReserved1) + "\n" + "bfReserved2 = " + fileToHex2(pbfReserved2) + "\n" + "bfOffBits = " + fileToHex4(pbfOffBits) + "\n" + "biSize = " + infoToHex4(pbiSize) + "\n" + "biWidth = " + infoToHex4(pbiWidth) + "\n" + "biHeight = " + infoToHex4(pbiHeight) + "\n" + "biPlanes = " + infoToHex2(pbiPlanes) + "\n" + "biBitCount = " + infoToHex2(pbiBitCount) + "\n" + "biCompression = " + infoToHex4(pbiCompression) + "\n" + "biSizeImage = " + infoToHex4(pbiSizeImage) + "\n" + "biXPelsPerMeter = " + infoToHex4(pbiXPelsPerMeter) + "\n" + "biYPelsPerMeter = " + infoToHex4(pbiYPelsPerMeter) + "\n" + "biClrUsed = " + infoToHex4(pbiClrUsed) + "\n" + "biClrImportant = " + infoToHex4(pbiClrImportant) ; } String fileToHex2(int i) { return toHex2(fileheader.getU2(i)); } String fileToHex4(int i) { return toHex4(fileheader.getS4(i)); } String infoToHex2(int i) { return toHex2(infoheader.getU2(i)); } String infoToHex4(int i) { return toHex4(infoheader.getS4(i)); } String toHex2(int in) { String ret = Integer.toString(in & 0xffff, 16); while (ret.length() < 4) ret = "0" + ret; return " " + ret + " (" + in + ")"; } String toHex4(int in) { long lo = (long)in & 0xffffffffL; String ret = Long.toString(lo, 16); while (ret.length() < 8) ret = "0" + ret; return ret + " (" + lo + ")"; } }