home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Workbench / Archivers / PPCxDMSWOS.lha / source.lha / src / u_rle.c < prev    next >
C/C++ Source or Header  |  1998-02-17  |  799b  |  48 lines

  1.  
  2. /*
  3.  *     xDMS  v1.0  -  Portable DMS archive unpacker  -  Public Domain
  4.  *     Written by     Andre R. de la Rocha  <adlroc@usa.net>
  5.  *
  6.  *     Run Length Encoding decompression function used in most
  7.  *     modes after decompression by other algorithm
  8.  *
  9.  */
  10.  
  11. #include <string.h>
  12. #include "cdata.h"
  13. #include "u_rle.h"
  14.  
  15.  
  16.  
  17. USHORT Unpack_RLE(UCHAR *in, UCHAR *out, USHORT origsize){
  18.     USHORT n;
  19.     UCHAR a,b, *outend;
  20.  
  21.     outend = out+origsize;
  22.     while (out<outend){
  23.         a = *in++;
  24.         if (a != 0x90) {
  25.             *out++ = a;
  26.         } else {
  27.             b = *in++;
  28.             if (b == 0) {
  29.                 *out++ = a;
  30.             } else {
  31.                 a = *in++;
  32.                 if (b == 0xff) {
  33.                     n = *in++;
  34.                     n = (USHORT)((n<<8) + *in++);
  35.                 } else {
  36.                     n = b;
  37.                 }
  38.                 if (out+n > outend) return 1;
  39.                 memset(out,a,(size_t) n);
  40.                 out += n;
  41.             }
  42.         }
  43.     }
  44.     return 0;
  45. }
  46.  
  47.  
  48.