     Here is a screen compression/decompression routine which I whipped up
back in early 1988. This one is better because it will also remove dark
as well as white bytes. The code is small, tight, and fast enough.
I played with doing RLE compression at the bit level, but it was very
slow, and the results weren't all that great. I'll be doing more
research on this in the future. I'm working with a new algorithm.

LCDP Packs a screen. Just put it on the stack. LCDP counts a string of 0's,
and prefixes the count by a zero. 255's are counted, and prefixed by 255.
The image of  SIN(x)=COS(x)  (with axis and RAD mode) can be packed down
to 380 bytes in 35 seconds.


LCDP - LCD display string image compressor. Version 1.0
       LCD-> string : Compressed image

       Method: Removed areas of all black or all white.

CHK[607]

<< -> s                                       ;  Get image.
   << "" 1 548                                ;  Set up loop.
      FOR i                                   ;  Loop through bytes.
        s i i SUB DUP NUM                     ;  Get byte.
        IF DUP 0 SAME SWAP 255 SAME OR THEN   ;+-If 0 or 255,
          -> t                                ;|  save.
          << t + 1                            ;|  Add prefix to output string.
             WHILE s OVER i + DUP SUB t SAME  ;|+-While each consecutive
                   OVER 255 <> AND REPEAT     ;||  byte is the same,
               1 +                            ;||  Keep a count.
             END                              ;|+-Endwhile- end of
          >>                                  ;|  end of run-length.
          SWAP OVER CHR + SWAP                ;|  Add count to output string.
        ELSE                                  ;|-Else
          + 1                                 ;| Just add byte to output.
        END                                   ;+-Endif
      STEP                                    ;  Get next byte.
   >>                                         ;
>>                                            ;  That's all, folks...



XLCDP will uncompress a compressed image. The image of SIN(x)=COS(x) can
be unpacked in 30 seconds.


XLCDP - Uncompress screen image.    Version 1.0
        Compressed image string : LCD image string

CHK[1518]

<< -> s                                      ;  Get compressed string.
   << "" 1 s SIZE                            ;  Calc size.
      FOR i                                  ;+-Loop through bytes.
        s i i SUB DUP NUM                    ;|  Extract byte.
        IF DUP 0 SAME SWAP 255 SAME OR THEN  ;|+-If 0 or 255,
          -> t                               ;||  Get value.
          << 1 s i 1 + DUP SUB NUM           ;||  Get next byte- count.
             START                           ;||+-Loop required count.
               t +                           ;|||  Add byte.
             NEXT                            ;||+-Add next.
             2                               ;||  Skip 2 bytes.
          >>                                 ;||
        ELSE                                 ;||-Else
          + 1                                ;||  Just add byte- skip 1.
        END                                  ;|+-Endif
      STEP                                   ;+-Get next byte.
   >>                                        ;
>>                                           ;  That's all, folks...




-----------------------------------------------------------------------------
       Bob Peraino                   UUCP    : uunet!pyrdc!gmu90x!peraino
 George Mason University             INTERNET: peraino@gmuvax.gmu.edu
UCIS, Thompson Hall, rm 2 <-         BITNET  : peraino@gmuvax
  4400 University Drive     \        PHONE   : (703)-323-2549
   Fairfax, VA  22030        \- Yeah, they put us in the basement, too.
-----------------------------------------------------------------------------
