home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / MISC / PVQUAN15.ZIP / ANIM.ZIP / ANIMFLI.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-01  |  4.6 KB  |  132 lines

  1. /************************************************************************
  2.  *                                                                      *
  3.  *                  Copyright (c) 1992, Frank van der Hulst             *
  4.  *                          All Rights Reserved                         *
  5.  *                                                                      *
  6.  ************************************************************************
  7.  *                                                                      *
  8.  * Authors:                                                             *
  9.  *        FvdH - Frank van der Hulst (Wellington, NZ)                   *
  10.  *                                                                      *
  11.  * Versions:                                                            *
  12.  *    V1.5 920401 FvdH - Released as part of PVQUAN15.ZIP               *
  13.  *                                                                      *
  14.  ************************************************************************/
  15.  
  16. /*
  17.   This program uses FLI.LIB to create FLIC (Autodesk Animator) files from a
  18.   series of 2D frames. */
  19.  
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #ifdef __TURBOC__
  23. #include <dos.h>
  24. #include <mem.h>
  25. #include <io.h>
  26. #include <conio.h>
  27.  
  28. #else
  29. int getw(FILE *fp)
  30. {
  31.     int x;
  32.     
  33.     x = getc(fp);
  34.     return (getc(fp) << 8) | x;
  35. }
  36. #endif
  37.  
  38. #include "aatypes.h"
  39. #include "aascreen.h"
  40. #include "aaerr.h"
  41. #include "aafli.h"
  42. #include "aaflisav.h"
  43.  
  44. UBYTE palette[256][3];
  45.  
  46. void err_exit(char *msg)
  47. {
  48.     printf("%s\n", msg);
  49.     exit(1);
  50. }
  51.  
  52. /* Read one image from a 2D file, and load it into the buffers whose addresses
  53.     have been passed to it. Returns TRUE if successful, FALSE if not */
  54.  
  55. int read_image(char *fname, unsigned char *buff, unsigned char *palette)
  56. {
  57.     FILE *fp;
  58.     int maxcol, maxrow, colours;
  59.  
  60.     printf("Reading image %s\n", fname);
  61.     if ((fp = fopen(fname, "rb")) == NULL) return FALSE;
  62.  
  63.     if (getc(fp) != '2') err_exit("\nIncorrect signature on file.\n");
  64.     if (getc(fp) != 'D') err_exit("\nIncorrect signature on file.\n");
  65.  
  66.     maxcol = getw(fp);         /* store columns */
  67.     maxrow = getw(fp);        /* store rows */
  68.     if (maxcol != 320 || maxrow != 200) err_exit("\nInvalid image size -- must be 320*200.\n");
  69.     colours = getc(fp);
  70.     if (colours == 0) colours = 256;
  71.     fread(palette, 3, colours, fp);
  72.     fread(buff, 1, maxrow * maxcol, fp);
  73.     fclose(fp);
  74.     return TRUE;
  75. }
  76.  
  77. /* first_scr contains a copy of the first screen in the sequence, so that
  78.     the last frame->first frame wrap can be maintained. This is a little
  79.     wasteful of memory, but avoids having to decompress the first frame again
  80.     at the end. That saves having to port the decompression code too. */
  81.  
  82. void make_fli(char *in, char *out)
  83. {
  84.     Vscreen *curr_scr, *prev_scr, *first_scr;
  85.     Fli_head outhead;
  86.     FILE *outfile;
  87.     int file_no;
  88.     char in_fname[256];
  89.     int file_ok;
  90.     int result;
  91.  
  92.     if ((prev_scr  = aa_alloc_mem_screen()) == NULL) err_exit(fli_error_message(AA_ERR_NOMEM));
  93.     if ((curr_scr  = aa_alloc_mem_screen()) == NULL) err_exit(fli_error_message(AA_ERR_NOMEM));
  94.     if ((first_scr = aa_alloc_mem_screen()) == NULL) err_exit(fli_error_message(AA_ERR_NOMEM));
  95.     if ((outfile = fli_create(out, &outhead, 5)) == NULL) err_exit("Couldn't create output file.");
  96.     file_no = 0;
  97.     sprintf(in_fname, "%s.0", in);
  98.     file_ok = read_image(in_fname, curr_scr->pmap, curr_scr->cmap);
  99.     aa_copy_screen(curr_scr, first_scr);
  100.     if ((result = fli_write_next(outfile, &outhead, curr_scr, curr_scr)) < AA_SUCCESS) err_exit(fli_error_message(result));
  101.     while (file_ok) {
  102.         aa_copy_screen(curr_scr, prev_scr);
  103.         file_no++;
  104.         sprintf(in_fname, "%s.%d", in, file_no);
  105.         if (!read_image(in_fname, curr_scr->pmap, curr_scr->cmap)) break;
  106.         if ((result = fli_write_next(outfile, &outhead, curr_scr, prev_scr)) < AA_SUCCESS) err_exit(fli_error_message(result));
  107.     }
  108.     if ((result = fli_end(outfile, &outhead, prev_scr, first_scr)) < AA_SUCCESS) err_exit(fli_error_message(result));
  109.     fclose(outfile);
  110.     aa_free_mem_screen(prev_scr);
  111.     aa_free_mem_screen(curr_scr);
  112.     aa_free_mem_screen(first_scr);
  113. }
  114.  
  115. void cdecl main(int argc, char *argv[])
  116. {
  117.     char in_fname[256], out_fname[256];
  118.  
  119.     printf("ANIMFLI v1.5 -- Create a FLI file containing an animation sequence.\n");
  120.     printf("By F van der Hulst. Copyright 1992\n\n");
  121.     if (argc != 3) {
  122.         printf("Usage: %s frame output\n", argv[0]);
  123.         printf("       frame  is the name (without extension) of the input frame files\n");
  124.         printf("       output is the name (without extension) of the FLI output file\n\n");
  125.         exit(1);
  126.     }
  127.  
  128.     sprintf(in_fname, "%s.0", argv[1]);
  129.     sprintf(out_fname, "%s.fli", argv[2]);
  130.     make_fli(in_fname, out_fname);
  131. }
  132.