home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / gfx / edit / tsmorph / unpacker.c < prev   
C/C++ Source or Header  |  1993-12-21  |  2KB  |  69 lines

  1. //    $Author: M_J_Paddock $
  2. //    $Date: 1993/06/06 23:17:33 $
  3. //    $Revision: 1.2 $
  4.  
  5. #include "iffp/ilbm.h"
  6. #include "iffp/packer.h"
  7.  
  8. /*----------------------------------------------------------------------*
  9.  * unpacker.c Convert data from "cmpByteRun1" run compression. 11/15/85
  10.  *
  11.  * Based on code by Jerry Morrison and Steve Shaw, Electronic Arts.
  12.  * This software is in the public domain.
  13.  *
  14.  *    control bytes:
  15.  *     [0..127]   : followed by n+1 bytes of data.
  16.  *     [-1..-127] : followed by byte to be repeated (-n)+1 times.
  17.  *     -128       : NOOP.
  18.  *
  19.  * This version for the Commodore-Amiga computer.
  20.  *----------------------------------------------------------------------*/
  21.  
  22. /*----------- UnPackRow ------------------------------------------------*/
  23.  
  24. #define UGetByte()    (*source++)
  25. #define UPutByte(c)    (*dest++ = (c))
  26.  
  27. /* Given POINTERS to POINTER variables, unpacks one row, updating the source
  28.  * and destination pointers until it produces dstBytes bytes.
  29.  */
  30.  
  31. BOOL unpackrow(BYTE **pSource, BYTE **pDest, WORD srcBytes0, WORD dstBytes0)
  32.     {
  33.     register BYTE *source = *pSource;
  34.     register BYTE *dest   = *pDest;
  35.     register WORD n;
  36.     register BYTE c;
  37.     register WORD srcBytes = srcBytes0, dstBytes = dstBytes0;
  38.     BOOL error = TRUE;    /* assume error until we make it through the loop */
  39.     WORD minus128 = -128;  /* get the compiler to generate a CMP.W */
  40.  
  41.     while( dstBytes > 0 )  {
  42.     if ( (srcBytes -= 1) < 0 )  goto ErrorExit;
  43.         n = UGetByte();
  44.  
  45.         if (n >= 0) {
  46.         n += 1;
  47.         if ( (srcBytes -= n) < 0 )  goto ErrorExit;
  48.         if ( (dstBytes -= n) < 0 )  goto ErrorExit;
  49.         do {  UPutByte(UGetByte());  } while (--n > 0);
  50.         }
  51.  
  52.         else if (n != minus128) {
  53.         n = -n + 1;
  54.         if ( (srcBytes -= 1) < 0 )  goto ErrorExit;
  55.         if ( (dstBytes -= n) < 0 )  goto ErrorExit;
  56.         c = UGetByte();
  57.         do {  UPutByte(c);  } while (--n > 0);
  58.         }
  59.     }
  60.     error = FALSE;    /* success! */
  61.  
  62.   ErrorExit:
  63.     *pSource = source;  *pDest = dest;
  64.     return(error);
  65.     }
  66.  
  67.  
  68. /* end */
  69.