***** File PREVPIX.TXT The algorithm for the previous-pixel compression scheme used by the International Halley Watch is given here in pseudocode. It is based on the observation that, for many images of 16-bit data, the pixel-to-pixel differences may often be coded within the dynamic range available in 8 bits, yielding a substantial savings in file size from a small computational investment. All differences that lie in the range [-127,127] can be coded in a single byte. Each difference has the bias value 127 added to it in order to avoid problems on machines which require unsigned byte data. This yields the range [0,254] in the actual data stream. The value 255 is reserved as a flag to indicate that the difference between the two current pixels is too large to be stored in 8 bits. In this case, the two bytes that follow the flag byte are to be interpreted as a new 16-bit pixel value, which then provides a new zero-point for the differences. No allowances are made for ends of lines, that is, the successive differences are allowed to cross from the right-hand edge of the image to the next line at the left hand edge. For images with smooth backgrounds, this will often result in another 8-bit difference, and so save a few more bytes. PREVIOUS PIXEL ALGORITHM WITH DIFFERENCE FLAG AS SEPARATE BYTE COMPRESSION: Load 255 into output record READ first record Set first value to be PREVPIXEL Load first value into output record DO UNTIL no more data on input IF input buffer is empty THEN read next record Compute difference between CURRENTPIXEL and PREVPIXEL IF this difference is within -127:127 THEN Add bias of 127 to the difference Convert the biased difference to a single byte Load value of difference byte into output record IF output record full, WRITE out record ELSE IF the difference is outside -127:127 THEN Load flag byte (255) into output record IF output record full, WRITE out record Load high byte of CURRENTPIXEL into output record IF output record full, WRITE out record Load low byte of CURRENTPIXEL into output record IF output record full, WRITE out record ENDIF Set PREVPIXEL equal to CURRENTPIXEL ENDDO IF partially filled output buffer remains THEN Blank to the end of the buffer WRITE out final (partial) record ENDIF PREVIOUS PIXEL ALGORITHM WITH DIFFERENCE FLAG AS SEPARATE BYTE DECOMPRESSION: READ first record Verify that first byte is 255 Set first value to be PREVPIXEL Load first value into output record DO UNTIL no more data on input IF input buffer is empty THEN read next record Get CURRENTBYTE from input buffer IF CURRENTBYTE is not equal to 255 (is a difference) THEN NEWPIXEL = PREVPIXEL + CURRENTBYTE - 127 Load NEWPIXEL into output record IF output record full, WRITE out record ELSE IF CURRENTBYTE = 255 THEN IF input buffer has < 2 bytes left THEN read next record Set NEWPIXEL to the next 2 bytes in the input buffer Load NEWPIXEL into output record IF output record full, WRITE out record ENDIF Set PREVPIXEL equal to NEWPIXEL ENDDO IF partially filled output buffer remains THEN Blank to the end of the buffer WRITE out final (partial) record ENDIF