Converting ZSoft Files to PC Paint Files by Bob Montgomery Orlando, Florida If you have an EGA display, PC Paint is a wonderful tool for doing color graphics. It comes with the Mouse Systems mouse, and can be purchased seperately. A mouse is almost a must for doing graphics work, and is relatively cheap. Another color graphics program along the same lines is PC Paintbrush (by Zsoft), which comes with the Microsoft mouse. The two programs are very similar, but each one does certain things better than the other. ZSoft Files ZSoft picture files have a 128 byte header with the following significance: Byte Manufacturer = 10 Byte Version = 5 Byte Encode = 1 Byte Bits/pixel = 1 Word X1 = Start X offset = 0 Word Y1 = Start Y offset (from top) = 0 Word X2 = End X offset = 0 Word Y2 = End Y offset = 0 Palette = 48 bytes (explained below) Byte Video mode = 0 Byte Planes = 4 Word Bytes/line = 80 60 filler bytes = 0 The palette data has 3 bytes for each palette register; there are 16 3 byte groups of palette data. The 3 bytes in a group correspond to red, green, blue from left to right. Each byte can have the hex value 0, 55h, AAh, or FFh, which corresponds to color levels none, secondary, normal, and both respectively. The palette register values (0-63) are derived from the bits: 0 0 sec_red sec_green sec_blue red green blue Thus, a group 00 55 FF specifies no red, secondary green, and normal and secondary blue. This translates to a palette register value of 0+16+9=25. The packed data uses the following rules: 1. If 2 msb's are both 1's, then this is a run count byte. The run count is the 6 lsb's, and the data to write is the next byte. 2. If the 2 msb's are not both 11, write this byte. Note that for a single screen data byte with both msb's set, the packed data contains 2 bytes; a count byte C1h and the screen data byte. In general, ZSoft picture files are about 30% larger than PC Paint picture files. The data is packed a line at a time starting at the upper left corner of the display. All the line data for the blue plane (0) is packed first, then the green plane (1) line data, then the red plane (2) line data, then the intensity plane (3) line data. When all plane data for the 1st line has been packed, the plane data for the 2nd line is packed, etc. This is continued until the end of the last screen line. When unpacking, keep going until the file data is exhausted. PC Paint Files PC Paint files are saved in at least 6 different formats, depending on the version and who created them. The file format for the full page packed version consists of a file header and blocks of packed data. The file header consists of the following info: Word Identifier 1234 hex Word Horizontal size (pixels) Word Vertical size (pixels) Word X offset into picture (not used) Word Y offset into picture (not used) Byte Bits/pixel (4 for EGA and 2 for CGA) Byte ID - Should be FF hex for PC Paint 2.00 picture Byte Video mode - should be ASCII G for EGA picture Byte Descriptor - should be 3 for EGA pics Byte Bytes of info to follow - should be 16 for EGA pic 16 Bytes Palette for picture (2 bytes for CGA pictures) The packed blocks follow the header. Each block has a 5 byte block header which gives: Word Packed block size (including header) Word Unpacked block size Byte Run Marker to identify packed data Each block consists of screen data bytes and packed data subblocks. A packed data subblock is identified by the run marker for that block, and consists of the following info: Byte Run Marker Byte Run length (bytes) Byte Screen data for run If the run length byte is zero, then the run length is the next word, and the screen data byte for the run is the next byte. Each screen data byte corresponds to 2 pixels for a 16 color EGA pictures, and 4 pixels for a 4 color CGA pictures. Pixels are written from left to right on each horizontal line. Lines are written from the last line up; the last line is written first, then the next to last line, etc. For a 16 color EGA picture, there are 4 bits/pixel and 2 pixels/byte. The most significant nibble is the color for the left pixel, and the least significant nibble is the color for the right pixel.