IMG_FILE.DOC IMAGE FILES 10/1/90 Description: Programs SSTMAP and IMGMAP (on the NAS9000) produce mapped and navigated AVHRR image data files from level 1B AVHRR data. SSTMAP and IMGMAP may produce image files of AVHRR channels 1 through 5, multi-channel sea surface temperature (MCSST). SSTMAP and IMGMAP may also produce other ancillary data files, such as angle files (i.e. solar zenith angle, satellite zenith angle, relative azimuth angle). All files are produced as arrays of 512 rows x 512 columns. The image files are produced as 2 bytes of image and graphics data per pixel. The angle files are produced as 2 bytes of data per pixel. Image files produced on the NAS9000 by SSTMAP and IMGMAP may be compressed prior to downloading to an IDIDAS PC. Compression of the image files substantially decreases transfer time, as well as disk storage requirements. Compression is performed automatically when an image file is prepared for transfer using programs IRMA (for SSTMAP) and IMAPCOMP (for IMGMAP). (NOTE: Ancillary data files are not compressed.) Image files are arranged as a section of image file orbital and mapping information, followed by the image and graphics data. The image orbital information is contained in a preamble of 1024 bytes, known as the image header. (See HEADER.DOC, SHOHDR.DOC, FILE_REQ.DOC, LOADIMG.DOC). The header section is followed by the image and graphics data. These data may be uncompressed or compressed. A compression flag is set in the header (Word 52 [starting with word 0] for SSTMAP image files, word 39 for IMGMAP image files.) Interpretation of the contents of the compression flag are as follows: 0 = uncompressed file 1 = compressed image file: image compression type 1; graphics compression type A. 2 = compressed image file: image compression type 1; graphics compression type B. Uncompressed image or data files are 525312 bytes in length. This consists of the header (1024 bytes), followed by 524288 bytes of combined image and graphics information (for image files) or ancillary information (for angle files), arranged as 2 bytes/pixel. (See format description below). When an image file is compressed, the file is written such that the uncompressed header data is written, then the compressed image data is written, followed by the compressed graphics. Compressed image files are of variable size, but are generally 280k to 350k bytes in size. SSTMAP image files are compressed using compression TYPE 1, while IMGMAP image files are compressed using compression TYPE 2. In each, the image data is compressed in the same format, but the graphics are compressed differently. Compression TYPE 1 uses graphics compression TYPE A, which is a pseudo-run-length encoding for the graphics data. Compression TYPE 2 uses graphics compression TYPE B, which is a true run-length encoding (STARTING WITH 0) for the graphics data. IMG_FILE.DOC 2 Graphics compression TYPE A is efficient for the graphics produced by SSTMAP, but is very inefficient for the much more complex graphics produced by IMGMAP. Therefore graphics compression TYPE B was developed. (NOTE: Graphics compression method TYPE B is the same as is used by GRFXSAVE and GRFXLOAD.) Image Data and Compression Notes: The uncompressed image files consist of two bytes per pixel. The data is arranged as follows: byte A B ÚÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄ¿ nibble 1 2 1 2 SIII IIII IIII GGGG Bit # 7654 3210 7654 3210 Bit 7 is most significant bit. Bit 0 is least significant bit. S: Sign bit (= 0) I: Image data bit (MSBs in byte A, nibbles A1 & A2, LSBs in byte B, nibble B1) G: Graphics bit (planes 3, 2, 1, and 0) Image compression is based on the difference between previous and next pixels. The compressed image data is written as a string of 8-bit bytes, according to the following scheme. If ((pixel is first pixel of image) or (abs(next pixel - previous pixel) > 63)) { write a two byte set arranged as byte 1, nibble 1 = 1000 [Hex 8]; byte 1, nibble 2 = same as byte A, nibble 1 in uncompressed image; byte 2, nibble 1 = same as byte A, nibble 2 in uncompressed image; byte 2, nibble 2 = same as byte B, nibble 1 in uncompressed image; } else /* (abs(next pixel - previous pixel) < 63) */ { write a single byte arranged as bit 8 = 0; bit 7 is the sign bit (0 = plus, 1 = minus); bits 6 through 0 are the difference between this pixel and the previous pixel; } IMG_FILE.DOC 3 Example: Below is an example uncompressed image byte sequence and the compressed byte sequence. Pixel 1 is the first pixel of the image. There are no graphics data in any of the example pixels. Uncompressed image Pixel # 1 2 3 ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ Byte # 1 2 3 4 5 6 ÚÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄ¿ Nibble 1 2 1 2 1 2 1 2 1 2 1 2 Binary 0011 0101 0010 0000 0011 0010 1100 0000 0011 0101 0101 0000 Hex 3 5 2 0 3 2 C 0 3 5 5 0 ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ Dec val 850 812 853 Compressed image Pixel # 1 2 3 ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄ¿ Byte # 1 2 3 4 ÚÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄ¿ Nibble 1 2 1 2 1 2 1 2 Binary 1000 0011 0101 0010 0110 0110 0010 1001 Hex 8 3 5 2 6 6 2 9 ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÙ Dec val 850 -38 +41 IMG_FILE.DOC 4 Graphics Data and Compression Notes: Graphics compression TYPE A SSTMAP image files contain large areas where there are no graphics. That is, the graphics bits in these blank pixels are zero. Graphics compression method TYPE A compresses the blank areas, or or zero graphics pixels. Pixels with graphics bits turned on are not compressed. Only graphics planes 1 through 7 may be encoded. Graphics compression TYPE A is done as a string of 8-bit bytes, according to the following algorithm. If graphics bits are on at a pixel { Write a byte arranged as byte 1, nibble 1 = 1000 [Hex 8]; byte 1, nibble 2 = same as byte B, nibble 2 in uncompressed image; } else there are no graphics bits on { Keep going to see how many pixels there are with no graphics bits on. If the number of pixels with no graphics bits < 127 { Write a byte arranged as bit 7 = 0; bits 6 through 0 = number of consecutive pixels with no graphics. } else there are >= 127 consecutive pixels with no graphics { Write a byte arranged as bit 7 = 0; bits 6 through 0 = 127 } } Graphics compressed with TYPE A compression may be decompressed with the following algorithm. If (bit 7 = OFF) { bits 6 through 0 contain the number of zero (no graphics) pixels. (The maximum number of zero pixels per byte is 127. If there are more than 127 zeros in a row, then two bytes are used.) } else /* (bit 7 = ON) */ { Graphics are on at that particular pixel. Bits 3, 2, 1, and 0 are the same as bits 3 through 0 of byte B in the uncompressed image format. } IMG_FILE.DOC 5 Example: 200 pixels with no graphics followed by two pixels with planes 4 and 3 on and one pixel with plane 4 on would be written as: Byte # 1 2 3 4 5 Binary 01111111 01001001 10001100 10001100 10001000 Decimal 127 73 140 140 136 Hex 7F 49 8C 8C 88 Graphics compression TYPE B Graphics compression TYPE B uses true run_length encoding. The graphics are specified as byte pairs, where the first byte is the value of the graphics pixel and the second byte is the number of consecutive pixels (STARTING WITH 0, up to 255) of that pixel. Thus all 8 graphics bits may be encoded and compressed. Graphics compression TYPE B is done as a string of 8-bit bytes, according to the following algorithm. Set pixel counter to 0. Get the value of the first graphics pixel. While there are more pixels { If new pixel is the same as previous one { If there is one byte's worth (255) of the same kind. { Write a byte pair, arranged as byte 1 = value of the graphics; byte 2 = the number of consecutive pixels with the the same graphics bits turned on. (NOTE: COUNT RANGE IS FROM 0 TO 255) Reset the pixel counter to zero; } else there is less than one byte's worth. { Increment the pixel counter; } } else the new pixel is different from previous one. { Write a byte pair, arranged as byte 1 = value of the previous graphics pixels; byte 2 = the number of consecutive pixels with the the same graphics bits turned on. (NOTE: COUNT RANGE IS FROM 0 TO 255) Reset the graphics comparison value to the new graphics value; Reset the pixel counter to zero; } } IMG_FILE.DOC 6 Graphics compressed with TYPE B compression may be decompressed with the following algorithm. While the TOTAL NUMBER OF PIXELS < 262144 { Read Byte 1 ( = GRAPHICS VALUE); Read Byte 2 ( = NUMBER OF CONSECUTIVE PIXELS); (NOTE: NUMBER OF CONSECUTIVE PIXELS RANGE IS FROM 0 TO 255) Write the GRAPHICS VALUE into the NUMBER OF CONSECUTIVE PIXELS; Increment the TOTAL NUMBER OF PIXELS by the NUMBER OF CONSECUTIVE PIXELS. } Example: 203 pixels with no graphics followed by 9 pixels with planes 7 and 4 on and one pixel with plane 4 on would be written as: Byte # 1 2 3 4 5 6 Binary 00000000 11001010 01001000 00001000 00001000 00000000 Decimal 0 202 72 8 08 0 Hex 00 CA 48 09 08 01