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

  1. #ifdef __TURBOC__
  2. #include <mem.h>
  3. #endif
  4.  
  5. #ifdef __GNUC__
  6. #define SEEK_SET 0
  7. #endif
  8.  
  9. #include "aatypes.h"
  10. #include "aaerr.h"
  11. #include "aascreen.h"
  12. #include "aafli.h"
  13. #include "aaflisav.h"
  14. #include "str_low.h"
  15.  
  16. static Errval write_a_fframe(FILE *ff,  /* Fli file returned by fli_create */
  17.     Fli_head *fh,                     /* Header inited by fli_create */
  18.     Vscreen *this, Vscreen *last,         /* Current and previous frame */
  19.     int compress_type,                     /* FLI_BRUN, FLI_LC, etc. */
  20.     int frame_counts)                    /* 0 on ring frame, otherwise 1 */
  21. {
  22.     Cbuf *cbuf;
  23.     unsigned int fsize;
  24.     Pixel *lpixels;
  25.     Pixel *lcmap;
  26.     Errval err = AA_SUCCESS;
  27.  
  28.     if ((cbuf = (Cbuf *)malloc(FLI_CBUF_SIZE)) == NULL)    return AA_ERR_NOMEM;
  29.     if (last == NULL)    {
  30.         lpixels = NULL;
  31.         lcmap = NULL;
  32.     } else {
  33.         lpixels = last->pmap;
  34.         lcmap = last->cmap;
  35.     }
  36.     fsize = fli_comp_frame(cbuf, lpixels, lcmap, this->pmap, this->cmap,    compress_type);
  37.     fsize = fwrite(cbuf, 1, fsize, ff);
  38.     if (fsize == 0)        err = AA_ERR_SHORTWRITE;
  39.     free(cbuf);
  40.     fh->size += fsize;
  41.     fh->frame_count += frame_counts;
  42.     return err;
  43. }
  44.  
  45. static Errval write_head(FILE *ff, Fli_head *fh)
  46. {
  47. #ifdef __TURBOC__
  48.     if (fwrite(fh, HEAD_SIZE, 1, ff) != 1)                                                    return AA_ERR_SHORTWRITE;
  49.     return AA_SUCCESS;
  50. #else
  51.     Fli_head buf;
  52.     Cbuf *c;
  53.  
  54.     c = lbuf((Cbuf *) &buf, fh->size);
  55.     c = wbuf(c, fh->type);
  56.     c = wbuf(c, fh->frame_count);
  57.     c = wbuf(c, fh->width);
  58.     c = wbuf(c, fh->height);
  59.     c = wbuf(c, fh->bits_a_pixel);
  60.     c = wbuf(c, fh->flags);
  61.     c = wbuf(c, fh->speed);
  62.     c = lbuf(c, fh->next_head);
  63.     c = lbuf(c, fh->frames_in_table);
  64.     c = wbuf(c, fh->file);
  65.     c = lbuf(c, fh->frame1_off);
  66.     c = lbuf(c, fh->strokes);
  67.     c = lbuf(c, fh->session);
  68.     memset(c, 0, 88);
  69.     if (fwrite(&buf, HEAD_SIZE, 1, ff) != 1)                                                    return AA_ERR_SHORTWRITE;
  70.     return AA_SUCCESS;
  71. #endif
  72. }
  73.  
  74. Errval fli_write_next(FILE *ff,         /* Fli file returned by fli_create */
  75.     Fli_head *fh,                     /* Same header used by fli_create */
  76.     Vscreen *this,                         /* Current frame */
  77.     Vscreen *last)                        /* Previous frame */
  78. {
  79.     return write_a_fframe(ff, fh, this, last,
  80.         (fh->frame_count == 0 ? FLI_BRUN : FLI_LC), 1);
  81. }
  82.  
  83. /* Write the 'ring frame', that is the difference between the first and
  84.     last frame of a fli.  Pass in the final frame of the FLI in last_frame,
  85.     and the first frame in firstf_buf. */
  86.  
  87. Errval fli_end(FILE *ff, Fli_head *fh, Vscreen *end_frame, Vscreen *firstf_buf)
  88. {
  89.     Errval err;
  90.  
  91.     if ((err = write_a_fframe(ff, fh, firstf_buf, end_frame, FLI_LC, 0)) < AA_SUCCESS)    return err;
  92.     if (fseek (ff, 0L, SEEK_SET) < AA_SUCCESS)                                                        return AA_ERR_SEEK;
  93.     fh->flags = (FLI_FINISHED | FLI_LOOPED);
  94.     return write_head(ff, fh);
  95. }
  96.  
  97. FILE *fli_create(char *fliname, Fli_head *fh, int speed)
  98. {
  99.     FILE *ff;
  100.  
  101.     if ((ff = fopen(fliname, "wb")) == NULL)    return NULL;
  102.     memset(fh, 0, HEAD_SIZE);    /* zero out counts and so forth */
  103.     fh->type = FLIH_MAGIC;
  104.     fh->size = HEAD_SIZE;
  105.     fh->width = 320;
  106.     fh->height = 200;
  107.     fh->bits_a_pixel = 8;
  108.     fh->speed = speed;
  109.     if (fwrite(fh, HEAD_SIZE, 1, ff) != 1) {
  110.         fclose(ff);
  111.         return NULL;
  112.     }
  113.     return ff;
  114. }
  115.