home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************
- * fppmake.c
- ****************************************************************/
-
- /******
- Copyright (C) 1993 by Klaus Ehrenfried.
-
- Permission to use, copy, modify, and distribute this software
- is hereby granted, provided that the above copyright notice appears
- in all copies and that the software is available to all free of charge.
- The author disclaims all warranties with regard to this software,
- including all implied warranties of merchant-ability and fitness.
- The code is simply distributed as it is.
- *******/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <memory.h>
- #include "fpfli.h"
-
- #define MAXLEN 512
-
- #define SEEK_SET 0
-
- unsigned char *pixel_chunk;
-
- static unsigned char file_header[FLI_FILE_HEADER_SIZE];
- static LONG color1[FLI_MAX_COLORS];
- static LONG color2[FLI_MAX_COLORS];
- static LONG color3[FLI_MAX_COLORS];
-
- /****************************************************************
- * make_fli
- ****************************************************************/
-
- int make_fli()
- {
- char image_file_name[MAXLEN];
- char first_name[MAXLEN];
- char last_name[MAXLEN];
- struct stat statbuf;
- int i, nframes, help, irun;
- int file_size, frame_size, mem_size_one;
- int read_flag, first_flag;
- UBYTE *pb_run[3];
- UBYTE *first_pixel, *last_pixel, *curr_pixel, *pre_pixel, *prepre_pixel;
- LONG *curr_color, *first_color, *last_color;
-
- /* ........ first test the list file ...... */
-
- fprintf(stdout,"scanning list file...\n");
-
- for (i=0; i < FLI_MAX_FRAMES; i++)
- {
- if (! get_next_line(input, image_file_name, MAXLEN))
- break;
-
- if (stat(image_file_name, &statbuf) != 0)
- {
- fprintf
- (stderr,"flimake: %d. file %s not found\n",i,image_file_name);
- goto exit_error;
- }
- if (i == 0) strcpy(first_name, image_file_name);
- strcpy(last_name, image_file_name);
- }
- nframes=i;
-
- fprintf(stdout," %d frames\n",nframes);
- rewind(input);
-
- /* ....... prepare pointers ....... */
-
- first_pixel = big_buffer;
- last_pixel = first_pixel + fli_size;
- pb_run[0] = last_pixel + fli_size;
- pb_run[1] = pb_run[0] + fli_size;
- pb_run[2] = pb_run[1] + fli_size;
-
- first_color = color1;
- last_color = color2;
-
- /* ............. read first and last frame ........ */
-
- if (!get_image(first_name, first_pixel, first_color, 0)) goto exit_error;
- if (nframes > 1)
- {
- if (!get_image(last_name, last_pixel, last_color, 0)) goto exit_error;
- }
- else
- {
- last_pixel = first_pixel;
- last_color = first_color;
- }
-
- /* ............. write dummy header ........ */
-
- memset(&file_header, 0, FLI_FILE_HEADER_SIZE);
-
- if (fwrite(file_header, FLI_FILE_HEADER_SIZE, 1, output) != 1)
- {
- fprintf(stderr," write error\n");
- goto exit_error;
- }
-
- file_size=FLI_FILE_HEADER_SIZE;
-
- /* ................... loop ........................ */
-
- curr_pixel = last_pixel;
- pre_pixel = last_pixel;
- mem_size_one=0;
-
- for (i=1; i <= nframes; i++)
- {
- if (! get_next_line(input, image_file_name, MAXLEN)) break;
- fprintf(stdout,"\n Frame %d\n",i);
-
- irun = i % 3;
-
- prepre_pixel = pre_pixel;
- pre_pixel = curr_pixel;
-
- if (i == 1)
- {
- read_flag = 0;
- first_flag = 1;
- curr_pixel = first_pixel;
- curr_color = first_color;
- }
- else if (i == nframes)
- {
- read_flag = 0;
- first_flag = 0;
- curr_pixel = last_pixel;
- curr_color = last_color;
- }
- else
- {
- read_flag = 1;
- first_flag = 0;
- curr_pixel = pb_run[irun];
- curr_color = color3;
- }
-
- if (read_flag == 1)
- {
- /* fprintf(stdout," Reading image .....\n"); */
- if (!get_image (image_file_name, curr_pixel, curr_color, 0))
- {
- fprintf(stderr," Error reading bitmap from file %s\n",
- image_file_name);
- goto exit_error;
- }
- }
-
- /* fprintf(stdout," Writing frame.....\n"); */
- frame_size=fli_write_frame(prepre_pixel, pre_pixel, curr_pixel,
- curr_color, first_flag);
-
- if (frame_size == 0)
- {
- fprintf(stderr," Error writing frame %d\n",i);
- goto exit_error;
- }
- file_size += frame_size;
-
- if (i == 1)
- mem_size_one=frame_size;
- }
-
- /* ................. close loop ................... */
-
- fprintf(stdout,"\n Close loop\n");
-
- prepre_pixel = pre_pixel;
- pre_pixel = curr_pixel;
-
- frame_size=fli_write_frame(prepre_pixel, pre_pixel, first_pixel,
- first_color, 0);
-
- if (frame_size == 0)
- {
- fprintf(stderr," Error writing frame\n");
- goto exit_error;
- }
-
- file_size += frame_size;
-
- /* ..................... write actual header ......... */
-
- help=0;
-
- add_bytes(file_header, &help, file_size, IOM_LONG);
- if (old_format_flag == 1)
- add_bytes(file_header, &help, FLI_FILE_OLD_MAGIC, IOM_UWORD);
- else
- add_bytes(file_header, &help, FLI_FILE_MAGIC, IOM_UWORD);
- add_bytes(file_header, &help, nframes, IOM_UWORD);
- add_bytes(file_header, &help, fli_width, IOM_UWORD);
- add_bytes(file_header, &help, fli_height, IOM_UWORD);
- add_bytes(file_header, &help, 0x0008, IOM_UWORD);
- add_bytes(file_header, &help, 0x0000, IOM_UWORD);
- add_bytes(file_header, &help, fli_speed, IOM_UWORD);
-
- help=0x0050;
- add_bytes(file_header, &help, 0x0080, IOM_LONG);
- add_bytes(file_header, &help, (0x0080+mem_size_one), IOM_LONG);
-
- if (fseek(output, 0L, SEEK_SET) != 0)
- {
- fprintf(stderr," fseek error\n");
- goto exit_error;
- }
-
- if (fwrite(file_header, help, 1, output) != 1)
- {
- fprintf(stderr," write error\n");
- goto exit_error;
- }
-
- return(nframes);
-
- exit_error:
- exitialise(1);
- exit(1);
- return(0);
- }
-
- /****************************************************************
- * get_next_line
- ****************************************************************/
-
- int
- get_next_line
- (
- FILE *fp, /* file pointer */
- char buff[],
- int len
- )
- {
- int c, i;
-
- i=0;
- while (1)
- {
- c=getc(fp);
- if (i < len) buff[i]=c;
- if ((c == '\n') || (c == EOF))
- {
- if (i < len)
- buff[i]='\0';
- else
- buff[len-1]='\0';
- return(i);
- }
- i++;
- }
- }
-