1 /* ======================================================================== */
2 /*  GIF Encoder routines.                                                   */
3 /*                                                                          */
4 /*  These are intended to support single-frame and multi-frame GIFs.        */
5 /*  Single frame support is for screen shots, multi-frame support is for    */
6 /*  converting movies to animated GIFs.                                     */
7 /*                                                                          */
8 /*  This GIF encoder doesn't trust that the decoder honors the aspect       */
9 /*  ratio stored in the GIF.  We just set it to 0.                          */
10 /*                                                                          */
11 /*  None of this code's thread-safe/reentrant.  BFD.                        */
12 /* ======================================================================== */
13 #ifndef GIF_ENC_H_
14 #define GIF_ENC_H_
15 
16 typedef struct gif_t
17 {
18     FILE    *f;
19     int     x_dim, y_dim;
20     int     trans, n_cols;
21     uint8_t  *vid, *pal;
22 } gif_t;
23 
24 extern int gif_best_stat[6];
25 
26 typedef const uint8_t(*gif_pal_t)[3];
27 
28 /* ======================================================================== */
29 /*  GIF_START -- Starts a single or multi-frame GIF.                        */
30 /* ======================================================================== */
31 int gif_start
32 (
33     gif_t         *gif,
34     FILE          *f,           /* file to attach to GIF.                   */
35     int            x_dim,       /* source image X dimension                 */
36     int            y_dim,       /* source image Y dimension                 */
37     const uint8_t  pal[][3],    /* palette to use for GIF.                  */
38     int            n_cols,      /* number of colors in GIF.                 */
39     int            multi        /* 0: Single image, 1: Multiple image       */
40 );
41 
42 /* ======================================================================== */
43 /*  GIF_FINISH -- Finishes off a GIF, terminating it and freeing memory.    */
44 /* ======================================================================== */
45 int gif_finish(gif_t *gif);
46 
47 
48 /* ======================================================================== */
49 /*  GIF_WR_FRAME_S -- Writes single-frame image to GIF.                     */
50 /* ======================================================================== */
51 int gif_wr_frame_s
52 (
53     gif_t         *gif,
54     const uint8_t *vid
55 );
56 
57 /* ======================================================================== */
58 /*  GIF_WRITE       -- Wrapper around gif_start/gif_wr_frame_s.             */
59 /* ======================================================================== */
60 int gif_write
61 (
62     FILE          *f,
63     const uint8_t *vid,
64     int            x_dim,
65     int            y_dim,
66     const uint8_t  pal[][3],
67     int            n_cols
68 );
69 
70 
71 /* ======================================================================== */
72 /*  GIF_WR_FRAME_M -- Writes next frame to a multi-frame GIF.               */
73 /*                    Attempts to optimize image.                           */
74 /* ======================================================================== */
75 int gif_wr_frame_m
76 (
77     gif_t         *gif,
78     const uint8_t *vid,
79     int            delay,
80     int            mode
81 );
82 
83 #endif
84 /* ======================================================================== */
85 /*  This program is free software; you can redistribute it and/or modify    */
86 /*  it under the terms of the GNU General Public License as published by    */
87 /*  the Free Software Foundation; either version 2 of the License, or       */
88 /*  (at your option) any later version.                                     */
89 /*                                                                          */
90 /*  This program is distributed in the hope that it will be useful,         */
91 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of          */
92 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       */
93 /*  General Public License for more details.                                */
94 /*                                                                          */
95 /*  You should have received a copy of the GNU General Public License along */
96 /*  with this program; if not, write to the Free Software Foundation, Inc., */
97 /*  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.             */
98 /* ======================================================================== */
99 /*                   Copyright (c) 2005, Joseph Zbiciak                     */
100 /* ======================================================================== */
101