Subversion Repositories ipe_artfile_utils

Rev

Blame | Last modification | View Log | RSS feed

  1. /**
  2.  * LZW Encoder for Imagination Pilots Entertainment 16-bit games (IPE16)
  3.  * - Blown Away - The Interactive Game by Imagination Pilots (BA)
  4.  * - Panic in the Park - The Interactive Game by Imagination Pilots (PiP)
  5.  * - Where's Waldo? At the Circus (Waldo1)
  6.  * ART file packer and unpacker by Daniel Marschall, ViaThinkSoft (C) 2014-2018
  7.  * Revision: 2018-02-15
  8.  *
  9.  * The code is based on "Cross platform GIF source code" (c) L. Patrick
  10.  * http://www.cs.usyd.edu.au/~graphapp/package/src/libgif/gif.c
  11.  * It was simplified and modified to encode IPE16-LZW instead of GIF-LZW.
  12.  * The game uses exactly the compressed stream as defined in the GIF standard,
  13.  * but the compressed stream is not divided into chunks.
  14.  **/
  15.  
  16. #ifndef __inc__ipe16_lzw_encoder
  17. #define __inc__ipe16_lzw_encoder
  18.  
  19. #include <stdio.h>
  20. #include <stdbool.h>
  21.  
  22. #define LZ_MIN_BITS     9
  23.  
  24. #define LZ_MAX_CODE     4095    /* Largest 12 bit code */
  25. #define FLUSH_OUTPUT    4096    /* Impossible code = flush */
  26.  
  27. #define HT_SIZE         8192    /* 13 bit hash table size */
  28. #define HT_KEY_MASK     0x1FFF  /* 13 bit key mask */
  29.  
  30. #define CLEAR_CODE      256
  31. #define END_CODE        257
  32. #define FIRST_CODE      258
  33.  
  34. #define HT_GET_KEY(x)   ((x) >> 12)
  35. #define HT_GET_CODE(x)  ((x) & 0x0FFF)
  36. #define HT_PUT_KEY(x)   ((x) << 12)
  37. #define HT_PUT_CODE(x)  ((x) & 0x0FFF)
  38.  
  39. typedef struct tagIpe16LZWEncoder {
  40.     int running_code;
  41.         int running_bits;
  42.     int max_code_plus_one;
  43.         int shift_state;
  44.     unsigned long shift_data;
  45.     unsigned long hash_table[HT_SIZE];
  46.   } Ipe16LZWEncoder;
  47.  
  48. Ipe16LZWEncoder* new_ipe16lzw_encoder(void);
  49. void del_ipe16lzw_encoder(Ipe16LZWEncoder* encoder);
  50. void ipe16lzw_encode(FILE* outFile, Ipe16LZWEncoder* encoder, unsigned char* input, int inputLength);
  51.  
  52. #endif // #ifndef __inc__ipe16_lzw_encoder
  53.  
  54.