2000 /* HSI Raw Files ------------------------------------------------------------------------ History The HSI Raw format was originally an internal format to Image Alchemy. Because of user demand the format has been documented to allow others to read and write HSI Raw files. Overview HSI Raw files are completely uncompressed, unpacked, and unpadded image data files. Therefore they tend to be larger than almost any compressed file format. However, they have the advantage, as far as Alchemy is concerned, that they are very fast to read and write and the location of any pixel in the image may be found by simple calculations. If you need to convert custom files to a format that Alchemy can read we recommend using a Raw file; it is the simplest format to write and the fastest for Alchemy to read. Variations There are two types of HSI Raw Files: paletted and true colour. Paletted images are stored one byte per pixel with a palette at the beginning of the file. True colour files are stored three bytes per pixel. Gray-scale Gray scale files are stored as paletted files with a palette that contains all gray values. Alchemy automatically recognizes such files during reading and will treat them appropriately. Black and white Black and White files are stored as paletted files with a palette that contains two values, black and white. Alchemy automatically recognizes such files during reading and will treat them appropriately. Warning Note that Handmade Software, Inc. reserves the right to make changes to this format at any time and without notice. And while it is unlikely, it is possible that future versions of Image Alchemy will not support this format. Old version files This appendix describes version 4 Raw files. This is the version that Image Alchemy has written since March 1991. Before this Alchemy wrote version 2 and 3 raw files (version 2 were 8 bit files, version 3 were 24 bit files). Those raw files can be read by current versions of Image Alchemy but are not otherwise supported. If you run across any of these raw files the easiest thing to do is to use a current copy of Alchemy to convert them to a version 4 raw file. Details Word size All values which are not otherwise identified are two byte integers (16 bits). This is the native integer size of most IBM PC C-compilers but not Macintosh and UNIX C-compilers. Byte order All integers are stored high byte first (big- endian order). This is the native mode for Macintosh's and Sun's but not the native mode for IBM PC's. See below for a CPU independent method to read and write 2-byte integers. Pixel format Paletted files are stored one byte per pixel. True colour files are stored as three bytes per pixel in red, green, blue order. Padding Neither the palette information nor the pixel data is padded to anything other than a byte boundary. This means that if you store a file which is 13 by 11 pixels it will occupy 429 bytes if stored as a true colour file (not including the header), or 143 bytes if stored as a paletted file (not including the header and palette data). Hex Numbers including a 0x prefix are hex; all other numbers are decimal. ----------------------------------------------------------------------------- File format The header for a paletted file is 32 bytes plus the size of the palette. The header for a true colour file is exactly 32 bytes (a true colour file contains no palette). Magic number Six bytes used to identify the file as an HSI Raw file: 0x6d 0x68 0x77 0x61 0x6e 0x68 Version An integer used to identify the version HSI file: 0x0004 Width An integer indicating the width of the image (in pixels). Height An integer indicating the height of the image (in pixels). Palette size An integer indicating the number of entries in the palette. Range is 2 to 256. A 0 or -24 indicates a true colour image (which has no palette data). Horizontal DPI An integer indicating the horizontal resolution of the image, in dots per inch. A zero indicates that the resolution is unknown. A negative number is used if only the aspect ratio is known. Vertical DPI An integer indicating the vertical resolution of the image, in dots per inch. A zero indicates that the resolution is unknown. A negative number is used if only the aspect ratio is known. Gamma An integer indicating the gamma of the image, scaled by 100 (a gamma of 2.2 is stored as 220). A zero indicates that the gamma is not known. Reserved Twelve bytes reserved for future use. Should be set to zero when writing. Palette The palette data is stored as 3 bytes per palette entry. The bytes are in red, green, blue order; 0 is black, 0xff is full intensity. True colour raw files have no palette. Image data The image data. Example files 8 bit paletted, 6D 68 77 61 6E 68 00 04 01 40 00 C8 01 00 00 00 320 x 200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 49 24 24 24 00 00 00 00 00 DB 6D 6D FF 92 92 FF B6 B6 92 49 49 FF DB DB FF B6 92 FF FF DB FF DB B6 FF FF FF B6 6D 6D 6D 24 24 DB 92 6D 6D 49 49 ... 24 bit true 6D 68 77 61 6E 68 00 04 01 40 00 C8 00 00 00 00 colour, 00 00 00 00 00 00 421 00 00 00 00 00 00 00 00 00 00 320 x 200: 49 24 24 49 24 24 49 24 24 49 24 24 49 24 24 49 24 24 49 24 24 49 24 24 49 24 24 49 24 24 49 24 24 49 24 24 49 24 24 49 24 24 49 24 24 49 24 24 ... Reading a two int getWord(int i, FILE *stream) { byte integer register int temp; temp=getc(stream)<<8; return(getc(stream) | temp); } Writing a two int putWord(int i, FILE *stream) { byte integer putc(i>>8, stream); return(putc(i&0xff, stream)); } */ struct hsi_struct { unsigned char magic[6]; unsigned int version; unsigned int width; unsigned int height; unsigned int palsize; unsigned int horiz_dpi; unsigned int vert_dpi; unsigned int gamma; unsigned char reserved[12]; }; . 0