home *** CD-ROM | disk | FTP | other *** search
/ Graphics 16,000 / graphics-16000.iso / msdos / animutil / pvquan / flilib / compfram.c < prev    next >
C/C++ Source or Header  |  1992-11-30  |  3KB  |  112 lines

  1. #ifdef __TURBOC__
  2. #include <mem.h>
  3. #endif
  4.  
  5. #include "aatypes.h"
  6. #include "aaerr.h"
  7. #include "aascreen.h"
  8. #include "aafli.h"
  9. #include "aaflisav.h"
  10. #include "aafii.h"
  11. #include "str_low.h"
  12.  
  13. #define FLI_EMPTY_DCOMP 8  /* Size returned by fii functions
  14.                             to indicate no change */
  15.  
  16. static unsigned full_cmap(Cbuf *cbuf, Cmap *cmap)
  17. {
  18.     *cbuf++ = 1;
  19.     *cbuf++ = 0;
  20.     *cbuf++ = 0;
  21.     *cbuf++ = 0;
  22.     memcpy(cbuf, cmap, AA_COLORS*3);
  23.     return AA_COLORS*3 + 4;
  24. }
  25.  
  26. static void chunk_buf(UBYTE *p, struct fli_chunk *c)
  27. {
  28. #ifdef __TURBOC__
  29.     memcpy(p, c, CHUNK_SIZE);
  30. #else
  31.     p = lbuf(p, c->size);
  32.     p = wbuf(p, c->type);
  33. #endif
  34. }
  35.  
  36. static UBYTE *frame_buf(UBYTE *p, struct fli_frame *f)
  37. {
  38. #ifdef __TURBOC__
  39.     memcpy(p, f, FRAME_SIZE);
  40.     return p + FRAME_SIZE;
  41. #else
  42.     p = lbuf(p, f->size);
  43.     p = wbuf(p, f->type);
  44.     p = wbuf(p, f->chunks);
  45.     memset(p, 0, 8);
  46.     return p + 8;
  47. #endif
  48. }
  49.  
  50. unsigned fli_comp_frame(
  51.     UBYTE *comp_buf, /* Buffer - should be FLI_CBUF_SIZE or bigger */
  52.     Pixel *last_screen, Cmap *last_cmap,     /* Data from previous frame */
  53.     Pixel *this_screen, Cmap *this_cmap,    /* Data for this frame */
  54.     int type)                    /* FLI_BRUN?  FLI_LCCOMP? */
  55. {
  56.     Cbuf colour_map[AA_COLORS*3+4];
  57.     Cbuf *screen_map, *c;
  58.     struct fli_frame frame;
  59.     struct fli_chunk colour_chunk, screen_chunk;
  60.     unsigned buf_len;
  61.  
  62.     if ((screen_map = (Cbuf *)malloc(64000U)) == NULL) return AA_ERR_NOMEM;
  63.     memset(&frame, 0, FRAME_SIZE);
  64.     frame.type = FLIF_MAGIC;
  65.     frame.size = FRAME_SIZE;
  66.  
  67. /* 1st make the color map chunk */
  68.     if (type == FLI_BRUN)    buf_len = full_cmap(colour_map, this_cmap);
  69.     else               buf_len = fii_fccomp(last_cmap, this_cmap, colour_map, AA_COLORS);
  70.     colour_chunk.type = FLI_COLOR;
  71.     colour_chunk.size = buf_len + CHUNK_SIZE;
  72.     if (colour_chunk.size != FLI_EMPTY_DCOMP) {
  73.         frame.chunks = 1;
  74.         frame.size += colour_chunk.size;
  75.     }
  76.  
  77.     switch (type) {
  78.     case FLI_LC:
  79.         buf_len = fii_lccomp(last_screen, this_screen, screen_map, 320, 200);
  80.         break;
  81.     case FLI_BRUN:
  82.         buf_len = fii_brun(this_screen, screen_map, 320, 200);
  83.         break;
  84.     }
  85.     if (buf_len == 0)    {
  86.         screen_chunk.size = 64000L+CHUNK_SIZE;
  87.         screen_chunk.type = FLI_COPY;
  88.         memcpy(screen_map, this_screen, 64000U);
  89.     } else {
  90.         screen_chunk.type = type;
  91.         screen_chunk.size = buf_len + CHUNK_SIZE;
  92.     }
  93.     if (screen_chunk.size != FLI_EMPTY_DCOMP)    {
  94.         frame.chunks++;
  95.         frame.size += screen_chunk.size;
  96.     }
  97.  
  98.     c = frame_buf(comp_buf, &frame);
  99.     if (colour_chunk.size != FLI_EMPTY_DCOMP) {
  100.         chunk_buf(c, &colour_chunk);
  101.         memcpy(c + CHUNK_SIZE, colour_map, (unsigned)colour_chunk.size - CHUNK_SIZE);
  102.         c += (unsigned)colour_chunk.size;
  103.     }
  104.     if (screen_chunk.size != FLI_EMPTY_DCOMP) {
  105.         chunk_buf(c, &screen_chunk);
  106.         memcpy(c + CHUNK_SIZE, screen_map, (unsigned)screen_chunk.size - CHUNK_SIZE);
  107.         c += (unsigned)screen_chunk.size;
  108.     }
  109.     free(screen_map);
  110.     return (unsigned)frame.size;
  111. }
  112.