home *** CD-ROM | disk | FTP | other *** search
/ Graphics 16,000 / graphics-16000.iso / msdos / animutil / flilib / flisrc / creatfli.c < prev    next >
C/C++ Source or Header  |  1990-02-26  |  3KB  |  106 lines

  1.  
  2. #include "aai86.h"
  3. #include "aados.h"
  4. #include "aaflisav.h"
  5.  
  6. static Errval write_a_fframe(Jfile ff,    /* Fli file returned by fli_create */
  7.     Fli_head *fh,                     /* Header inited by fli_create */
  8.     Vscreen *this, Vscreen *last,         /* Current and previous frame */
  9.     int compress_type,                     /* FLI_BRUN, FLI_LC, etc. */
  10.     int frame_counts)                    /* 0 on ring frame, otherwise 1 */
  11. {
  12. Cbuf *cbuf;
  13. long fsize;
  14. Pixel *lpixels;
  15. Pixel *lcmap;
  16. Errval err = AA_SUCCESS;
  17.  
  18. if ((cbuf = aa_malloc(FLI_CBUF_SIZE)) == NULL)
  19.     return(AA_ERR_NOMEM);
  20. if (last == NULL)
  21.     {
  22.     lpixels = NULL;
  23.     lcmap = NULL;
  24.     }
  25. else
  26.     {
  27.     lpixels = last->p;
  28.     lcmap = last->cmap;
  29.     }
  30. fsize = fli_comp_frame(cbuf, lpixels, lcmap, this->p, this->cmap, 
  31.     compress_type);
  32. if (dos_write(ff, cbuf, fsize) != fsize)
  33.     {
  34.     err = AA_ERR_SHORTWRITE;
  35.     }
  36. aa_free(cbuf);
  37. fh->size += fsize;
  38. fh->frame_count += frame_counts;
  39. return(err);
  40. }
  41.  
  42. Errval fli_write_next(Jfile ff,         /* Fli file returned by fli_create */
  43.     Fli_head *fh,                     /* Same header used by fli_create */
  44.     Vscreen *this,                         /* Current frame */
  45.     Vscreen *last)                        /* Previous frame */
  46. {
  47. return(write_a_fframe(ff, fh, this, last, 
  48.     (fh->frame_count == 0 ? FLI_BRUN : FLI_LC), 1));
  49. }
  50.  
  51. /* Write the 'ring frame', that is the difference between the first and
  52.    last frame of a fli.  Pass in the final frame of the FLI in last_frame.
  53.    firstf_buf will be loaded with the first frame of the FLI as a side
  54.    effect. */
  55. Errval fli_end(Jfile ff, Fli_head *fh, Vscreen *end_frame,
  56.     Vscreen *firstf_buf)
  57. {
  58. long lastpos;
  59. Errval err;
  60.  
  61. lastpos = dos_tell (ff);
  62. if (dos_seek (ff, (long)sizeof(*fh), DOS_SEEK_START)<AA_SUCCESS)
  63.     return(AA_ERR_SEEK);
  64. err = fli_read_display_frame(ff, firstf_buf, FALSE);
  65. if (err < AA_SUCCESS)
  66.     return(err);
  67. if (dos_seek (ff, lastpos, DOS_SEEK_START)<AA_SUCCESS)
  68.     return(AA_ERR_SEEK);
  69. err = write_a_fframe(ff, fh, firstf_buf, end_frame, FLI_LC, 0);
  70. if (err < AA_SUCCESS)
  71.     return(err);
  72. if (dos_seek (ff, 0L, DOS_SEEK_START)<AA_SUCCESS)
  73.     return(AA_ERR_SEEK);
  74. fh->flags = (FLI_FINISHED | FLI_LOOPED);
  75. if (dos_write(ff, fh, (long)sizeof(*fh)) != sizeof(*fh))
  76.     return(AA_ERR_SHORTWRITE);
  77. return(AA_SUCCESS);
  78. }
  79.  
  80. Jfile fli_create(char *fliname, Fli_head *fh, int speed)
  81. {
  82. Jfile ff;
  83. Errval err;
  84.  
  85. if ((ff = dos_create(fliname)) == 0)
  86.     {
  87.     return(AA_ERR_CANTMAKE);
  88.     }
  89. i86_bzero(fh, sizeof(*fh));    /* zero out counts and so forth */
  90. fh->type = FLIH_MAGIC;
  91. fh->size = sizeof(*fh);
  92. fh->width = 320;
  93. fh->height = 200;
  94. fh->bits_a_pixel = 8;
  95. fh->speed = speed;
  96. if (dos_write(ff, fh, (long)sizeof(*fh)) != sizeof(*fh))
  97.     {
  98.     dos_close (ff);
  99.     return(AA_ERR_SHORTWRITE);
  100.     }
  101. return(ff);
  102. }
  103.  
  104.  
  105.  
  106.