forked from uobikiemukot/recterm
-
Notifications
You must be signed in to change notification settings - Fork 11
/
gifsave89.h
150 lines (141 loc) · 7.65 KB
/
gifsave89.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Copyright(c) 2012-2012, John Forkosh Associates, Inc. All rights reserved.
* http://www.forkosh.com mailto: john@forkosh.com
* Copyright (C) 2014 haru <uobikiemukot at gmail dot com>
* Copyright (C) 2014 Hayaki Saito <user@zuse.jp>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* --- program id --- */
#define PROGRAMID "gifsave89" /* program name */
#define GIFSAVE_VERSION "1.00" /* version number */
#define REVISIONDATE " 10 Oct 2012 " /* date of most recent revision */
#define COPYRIGHTTEXT "Copyright(c) 2012-2012, John Forkosh Associates, Inc"
/* --- program messages --- */
static char *copyright = /* gnu/gpl copyright notice */
"+-----------------------------------------------------------------------+\n"
"|" PROGRAMID " ver" GIFSAVE_VERSION ", " COPYRIGHTTEXT "|\n"
"| ( current revision:" REVISIONDATE
") |\n"
"+-----------------------------------------------------------------------+\n"
"|gifsave89 is free software, licensed to you under terms of the GNU/GPL,|\n"
"| and comes with absolutely no warranty whatsoever. |\n"
"| See http://www.forkosh.com/gifsave89.html for further details. |\n"
"+-----------------------------------------------------------------------+";
/* -------------------------------------------------------------------------
url of cgi to pixelize plaintext expressions (see plainmimetext() below)...
-------------------------------------------------------------------------- */
/* --- pixelizing cgi --- */
#if !defined(MIMETEX)
#define MIMETEX "http://www.forkosh.com/mimetex.cgi"
#endif
/* --- local /path/to/wget to run the cgi (-DWGET to supply path/to) --- */
#if !defined(WGET)
#define WGET "wget"
#endif
/* -------------------------------------------------------------------------
gifsave89 data and structures...
-------------------------------------------------------------------------- */
/* ---
* gifsave89 datatypes
* ---------------------- */
typedef uint8_t BYTE; /* one byte (8 bits) */
typedef uint16_t WORD; /* used for two byte integers */
/* ---
* gif image buffer (note: ptr to caller's buffer address is BYTE **block)
* ----------------------------------------------------------------------- */
#define BLOCK struct _Block
#define BK BLOCK /* shorthand for funcs and args */
#define MAXBLKBYTES (1024) /* initial gif buffer allocation */
BLOCK {
BYTE **block; /* block buffer */
int nblkbytes, /* #bytes already in our block */
maxblkbytes; /* #bytes currently (re)allocated */
}; /* --- end-of-struct BLOCK --- */
/* ---
* data subblock (as per gif standard)
* -------------------------------------- */
#define SUBBLOCK struct _SubBlock
#define SB SUBBLOCK /* shorthand for funcs and args */
#define SUBBLOCKSIZE (255) /* maximum gif subblock size */
#define BITSPERBYTE (8) /* #bits per byte */
SUBBLOCK {
BYTE subblock[SUBBLOCKSIZE + 1]; /* subblock buffer */
BLOCK *block; /* parent block to flush subblock */
int nsubbytes, /* #bytes already in our subblock */
nsubbits; /* #bits already in current byte */
int index; /* >=0 writes subblock index# byte */
}; /* --- end-of-struct SUBBLOCK --- */
/* ---
* LZW parameters
* ----------------- */
#define POW2(n) ((int)(1<<(n))) /* 2**n */
#define RESCODES (2)
#define HASHFREE (0xFFFF)
#define NEXTFIRST (0xFFFF)
#define CODEBITS (12)
#define NSTRINGS POW2((CODEBITS))
#define HASHSIZE (9973)
#define HASHSTEP (2039)
#define HASH(index,byte) ( (((byte) << 8) ^ (index)) % (HASHSIZE) )
/* ---
* "global" gifsave89 data
* Note: gifsave89 is reentrant by keeping all variables that need to
* be maintained from call to call in this struct, i.e., no globals.
* --------------------------------------------------------------------- */
#define GIFSAVE89 struct _GifSave89
#define GS GIFSAVE89 /* shorthand for funcs and args */
GIFSAVE89 {
/* ---
* gif image block and subblock buffers
* --------------------------------------- */
BLOCK gifimage; /* buffer for gif image block */
SUBBLOCK gifsubblock; /* buffer for gifimage subblock */
/* ---
* LZW string table
* ------------------- */
BYTE strbyte[NSTRINGS];
int strnext[NSTRINGS], strhash[HASHSIZE], nstrings;
/* ---
* additional control data
* -------------------------- */
int version; /* 87=GIF87a, 89=GIF89a */
int width, height; /* #row, #col pixels for screen */
int ncolorbits_gct, /* #bits/index (global color table) */
ncolorbits; /* local(if given) or global #bits */
int bgindex; /* global&local colortable bgindex */
int npixels; /* width*height of current image */
int ncontrol; /* #controlgif calls before putgif */
int isanimated, /* true if animategif() called */
delay, tcolor, disposal; /* animation frame defaults */
/* ---
* plaintext control data
* ------------------------- */
int isplaintext; /* plaintext flag, 1or2 if present */
int pt_left, pt_top; /* col,row of top-left corner */
int pt_bg, pt_fg; /* bg,fg colortable indexes */
int pt_width, pt_height; /* width,height of pixelized data */
char pt_data[1024]; /* local copy of user text data */
BYTE *pt_pixels; /* pixelized data (kept if flag=2) */
/* ---
* debugging control data
* ------------------------- */
int msglevel; /* desired verbosity (0=none) */
void *msgfp; /* debug file ptr */
}; /* --- end-of-struct GIFSAVE89 --- */
void *newgif(void **gifimage, int width, int height, int *colors, int bgindex);
int controlgif(GS * gs, int tcolor, int delay, int userinput, int disposal);
int animategif(GS * gs, int nrepetitions, int delay, int tcolor, int disposal);
int putgif(GS * gs, void *pixels);
int endgif(GS * gs);