1 /*   gifgen.h
2 * ===========================================================================
3 *
4 *                            PUBLIC DOMAIN NOTICE
5 *            National Center for Biotechnology Information (NCBI)
6 *
7 *  This software/database is a "United States Government Work" under the
8 *  terms of the United States Copyright Act.  It was written as part of
9 *  the author's official duties as a United States Government employee and
10 *  thus cannot be copyrighted.  This software/database is freely available
11 *  to the public for use. The National Library of Medicine and the U.S.
12 *  Government do not place any restriction on its use or reproduction.
13 *  We would, however, appreciate having the NCBI and the author cited in
14 *  any work or product based on this material
15 *
16 *  Although all reasonable efforts have been taken to ensure the accuracy
17 *  and reliability of the software and data, the NLM and the U.S.
18 *  Government do not and cannot warrant the performance or results that
19 *  may be obtained by using this software or data. The NLM and the U.S.
20 *  Government disclaim all warranties, express or implied, including
21 *  warranties of performance, merchantability or fitness for any particular
22 *  purpose.
23 *
24 * ===========================================================================
25 */
26 
27 
28 /* +-------------------------------------------------------------------+ */
29 /* | Copyright 1990, 1991, 1993, David Koblas.  (koblas@netcom.com)    | */
30 /* |   Permission to use, copy, modify, and distribute this software   | */
31 /* |   and its documentation for any purpose and without fee is hereby | */
32 /* |   granted, provided that the above copyright notice appear in all | */
33 /* |   copies and that both that copyright notice and this permission  | */
34 /* |   notice appear in supporting documentation.  This software is    | */
35 /* |   provided "as is" without express or implied warranty.           | */
36 /* +-------------------------------------------------------------------+ */
37 
38 /*
39  * File Name:  gifgen.c
40  *
41  * Author:  Alex Smirnov
42  *
43  * Version Creation Date:   10/20/95
44  *
45  * File Description:
46  *       GIF generator header file
47  *
48  * $Log: gifgen.h,v $
49  * Revision 6.9  1999/10/26 15:47:35  vakatov
50  * + gdImageGifEx(), gdFWrite -- to specify an alternative GIF write func
51  * (with V.Chetvernin)
52  *
53  * Revision 6.8  1999/10/20 19:49:21  vakatov
54  * + gdImageGetDimensions()
55  *
56  * Revision 6.7  1999/08/13 21:23:09  vakatov
57  * Renamed "gd[Set|Get]ImageColor()" to "gdImage[Set|Get]Color()"
58  *
59  * Revision 6.6  1999/08/13 20:55:28  vakatov
60  * + gdSetImageColor()
61  * + gdImageGetAutoCropRectangle(), gdImageCrop(), gdImageAutoCrop()  <in
62  * a close collab. with S.Resenchuk & R.Tatusov>
63  *
64  * Revision 6.5  1998/06/15 22:02:54  vakatov
65  * Added gdImageSetClip() to allow clipping(rectangular area only)
66  *
67  * Revision 6.4  1998/04/27 15:52:54  vakatov
68  * Added gdImageRoundRectangle() and gdImageQuadrant() to draw a rounded
69  * rectangle and a quarter of an ellipse respectively
70  *
71  * Revision 6.3  1998/04/08 19:53:51  brandon
72  * Added gdImageCopy() and gdImageCopyResized() from gd1.2
73  *
74  * Revision 6.2  1998/03/30 18:40:51  kans
75  * needs to include ncbistd.h to define Nlm_Boolean
76  *
77  * Revision 6.1  1998/03/30 16:52:15  vakatov
78  * Added gdImageArcEx() and gdImageEllipse()
79  *
80  * Revision 6.0  1997/08/25 18:15:08  madden
81  * Revision changed to 6.0
82  *
83  * Revision 5.5  1997/08/19 19:26:46  vakatov
84  * Added gdImageSelectPattern() to provide Nlm_SelectPattern()
85  * functionality for GIFs
86  *
87  * Revision 5.4  1997/03/18 20:10:50  shavirin
88  * Added protection for usage with C++
89  *
90  * Revision 5.3  1996/12/03  21:48:33  vakatov
91  * Adopted for 32-bit MS-Windows DLLs
92  *
93  * Revision 5.2  1996/11/22  19:45:25  vakatov
94  * Added prototypes for gdImageCreateFromGif() and gdGetImageColor()
95  *
96  * Revision 5.1  1996/11/12  15:39:33  vakatov
97  * Added prototypes of the vertical text printing routines:  gdImageCharV()
98  * and gdImageStringV() -- [by R.Tatusov]
99  *
100  * Revision 5.0  1996/05/28  13:18:57  ostell
101  * Set to revision 5.0
102  *
103  * Revision 1.2  1996/04/19  14:17:56  vakatov
104  * Inserted non-NCBI copyright headers.
105  * Added VC log.
106  *
107  *
108  * ==========================================================================
109  */
110 
111 
112 #ifndef GIFGEN_H
113 #define GIFGEN_H 1
114 
115 #include <ncbistd.h>
116 #include <stdio.h>
117 
118 #undef NLM_EXTERN
119 #ifdef NLM_IMPORT
120 #define NLM_EXTERN NLM_IMPORT
121 #else
122 #define NLM_EXTERN extern
123 #endif
124 
125 
126 #ifdef __cplusplus
127 extern "C" {
128 #endif
129 
130 
131 /**************************************************************************/
132 /* DEFINES */
133 /**************************************************************************/
134 #define gdMaxColors     256
135 #define gdDashSize      4
136 #define gdStyled        (-2)
137 #define gdBrushed       (-3)
138 #define gdStyledBrushed (-4)
139 #define gdTiled         (-5)
140 #define gdTransparent   (-6)
141 
142 #define gdImageSX(im)             ((im)->sx)
143 #define gdImageSY(im)             ((im)->sy)
144 #define gdImageColorsTotal(im)    ((im)->colorsTotal)
145 #define gdImageRed(im,c)          ((im)->red[(c)])
146 #define gdImageGreen(im,c)        ((im)->green[(c)])
147 #define gdImageBlue(im,c)         ((im)->blue[(c)])
148 #define gdImageGetTransparent(im) ((im)->transparent)
149 #define gdImageGetInterlaced(im)  ((im)->interlace)
150 
151 /**************************************************************************/
152 /* TYPEDEFS */
153 /**************************************************************************/
154 typedef struct {
155   int    nchars;  /* # of characters in font */
156   int    offset;  /* First character is numbered... (usually 32 = space) */
157   int    w;       /* Character width  */
158   int    h;       /* Character height */
159   int    d;       /* Character descent */
160   char * data;    /* Font data; array of characters, one row after another.
161                      Easily included in code, also easily loaded from
162                      data files. */
163 } gdFont, *gdFontPtr;
164 
165 typedef struct {
166   int x, y;
167 } gdPoint, *gdPointPtr;
168 
169 typedef struct {
170   gdPoint lt;
171   gdPoint rb;
172 } gdRect;
173 
174 
175 typedef struct gdImageStruct {
176   unsigned char * pixels;
177   int             sx;
178   int             sy;
179   int             colorsTotal;
180   int             red[gdMaxColors];
181   int             green[gdMaxColors];
182   int             blue[gdMaxColors];
183   int             open[gdMaxColors];
184   int             transparent;
185   int           * polyInts;
186   int             polyAllocated;
187   struct gdImageStruct * brush;
188   struct gdImageStruct * tile;
189   int             brushColorMap[gdMaxColors];
190   int             tileColorMap[gdMaxColors];
191   int             styleLength;
192   int             stylePos;
193   int           * style;
194   int             interlace;
195   int             use_pattern;
196   unsigned char   pattern[8];
197   int             use_clip;
198   gdRect          clip, eff_clip;
199 } gdImage,  *gdImagePtr;
200 
201 
202 /* Functions to manipulate images. */
203 NLM_EXTERN gdImagePtr gdImageCreate         (int sx, int sy);
204 NLM_EXTERN gdImagePtr gdImageCreateFromGif  (FILE *fd);
205 NLM_EXTERN void       gdImageDestroy        (gdImagePtr im);
206 NLM_EXTERN void       gdImageSetPixel       (gdImagePtr im,
207                                              int x, int y, int color);
208 NLM_EXTERN int        gdImageGetPixel       (gdImagePtr im, int x, int y);
209 NLM_EXTERN void       gdImageLine           (gdImagePtr im, int x1, int y1,
210                                              int x2, int y2, int color);
211 NLM_EXTERN void       gdImageDashedLine     (gdImagePtr im, int x1, int y1,
212                                              int x2, int y2, int color);
213 NLM_EXTERN void       gdImageRectangle      (gdImagePtr im, int x1, int y1,
214                                              int x2, int y2, int color);
215 NLM_EXTERN void       gdImageFilledRectangle(gdImagePtr im, int x1, int y1,
216                                              int x2, int y2, int color);
217 NLM_EXTERN void       gdImageRoundRectangle (gdImagePtr im, int x1, int y1,
218                                              int x2, int y2,
219                                              int oval_w, int oval_h,
220                                              int color, Nlm_Boolean fill);
221 NLM_EXTERN int        gdImageBoundsSafe     (gdImagePtr im, int x, int y);
222 NLM_EXTERN void       gdImageChar           (gdImagePtr im, gdFontPtr f,
223                                              int x, int y,
224                                              int c, int color);
225 NLM_EXTERN void       gdImageCharV          (gdImagePtr im, gdFontPtr f,
226                                              int x, int y,
227                                              int c, int color);
228 NLM_EXTERN void       gdImageString         (gdImagePtr im, gdFontPtr f,
229                                              int x, int y,
230                                              char *s, int color);
231 NLM_EXTERN void       gdImageStringV        (gdImagePtr im, gdFontPtr f,
232                                              int x, int y,
233                                              char *s, int color);
234 NLM_EXTERN void       gdImagePolygon        (gdImagePtr im,
235                                              gdPointPtr p, int n, int c);
236 NLM_EXTERN void       gdImageFilledPolygon  (gdImagePtr im,
237                                              gdPointPtr p, int n, int c);
238 NLM_EXTERN int        gdImageColorAllocate  (gdImagePtr im,
239                                              int r, int g, int b);
240 
241 /* Do nothing and return FALSE if the "color" is bad or not allocated
242  */
243 #define gdGetImageColor gdImageGetColor
244 NLM_EXTERN int        gdImageGetColor       (gdImagePtr im, int color,
245                                              int *r, int *g, int *b);
246 
247 /* Do nothing and return FALSE if the "color" is bad or not allocated
248  */
249 NLM_EXTERN int        gdImageSetColor       (gdImagePtr im, int color,
250                                              int r, int g, int b);
251 
252 NLM_EXTERN int        gdImageColorClosest   (gdImagePtr im,
253                                              int r, int g, int b);
254 NLM_EXTERN int        gdImageColorExact     (gdImagePtr im,
255                                              int r, int g, int b);
256 NLM_EXTERN void       gdImageColorDeallocate   (gdImagePtr im, int color);
257 NLM_EXTERN void       gdImageColorTransparent  (gdImagePtr im, int color);
258 
259 /* Write out "size" bytes starting from address "buf".
260  * Return the # of succesfully written bytes. */
261 typedef size_t (*gdFWrite)(const void* buf, size_t size, void* userdata);
262 
263 /* Write in GIF format using write callback "func"
264  */
265 NLM_EXTERN void       gdImageGifEx          (gdImagePtr im,
266                                              gdFWrite   func,
267                                              void*      userdata);
268 
269 /* Write the image to file stream "out" in GIF format
270  */
271 NLM_EXTERN void       gdImageGif            (gdImagePtr im, FILE* out);
272 
273 
274 NLM_EXTERN void       gdImageArc            (gdImagePtr im, int cx, int cy,
275                                              int w, int h,
276                                              int s, int e, int color);
277 NLM_EXTERN void       gdImageArcEx          (gdImagePtr im, int cx, int cy,
278                                              int rx, int ry,
279                                              double s_angle, double e_angle,
280                                              int color, Nlm_Boolean fill);
281 NLM_EXTERN void       gdImageEllipse        (gdImagePtr im, int cx, int cy,
282                                              int rx, int ry, int color,
283                                              Nlm_Boolean fill);
284 NLM_EXTERN void       gdImageQuadrant       (gdImagePtr im, int cx, int cy,
285                                              int rx, int ry, int color,
286                                              Nlm_Boolean fill, int quadrant);
287 NLM_EXTERN void       gdImageInterlace      (gdImagePtr im, int interlaceArg);
288 NLM_EXTERN void       gdImageCopyBits       (gdImagePtr im, int x, int y,
289                                              int w, int h,
290                                              char * ptr, int color);
291 NLM_EXTERN void       gdImageSelectPattern  (gdImagePtr im,
292                                              const unsigned char pattern[]);
293 
294 NLM_EXTERN void       gdImageCopy           (gdImagePtr dst,
295                                              gdImagePtr src,
296                                              int dstX, int dstY,
297                                              int srcX, int srcY,
298                                              int w, int h);
299 NLM_EXTERN void       gdImageCopyResized    (gdImagePtr dst,
300                                              gdImagePtr src,
301                                              int dstX, int dstY,
302                                              int srcX, int srcY,
303                                              int dstW, int dstH,
304                                              int srcW, int srcH);
305 
306 /* (return non-zero value if the image was clipped before)
307  */
308 NLM_EXTERN int        gdImageSetClip        (gdImagePtr im,
309                                              const gdRect *clip,
310                                              gdRect *old_clip);
311 
312 
313 /* Get the image's width and height. ("width" and "height" can be NULLs).
314  */
315 NLM_EXTERN void gdImageGetDimensions(gdImagePtr im, int* width, int* height);
316 
317 
318 /* Determine a minimal rectangular area "rect" inside image "im" such that
319  * the area outside the "rect" contains only background pixels.
320  * NOTE: if the whole image contains only background pixels then
321  *       just return the image's boundaries.
322  */
323 NLM_EXTERN void gdImageGetAutoCropRectangle(gdImagePtr im, gdRect* rect);
324 
325 
326 /* Inside the image "im", move the rectangular area "rect" to the left
327  * top corner.
328  * NOTE:  "rect" will be automagically normalized and fit the image boundaries.
329  */
330 NLM_EXTERN void gdImageCrop(gdImagePtr im, const gdRect* rect);
331 
332 
333 /* Apply gdImageGetAutoCropRectangle(), then add no more than "border" pixels
334  * to each side of the resultant rectangular area, and do gdImageCrop().
335  */
336 NLM_EXTERN void gdImageAutoCrop(gdImagePtr im, int border);
337 
338 
339 
340 /**************************************************************************/
341 /* GLOBAL VARIABLE */
342 /**************************************************************************/
343 
344 extern gdFontPtr gdFont8X16;
345 extern gdFontPtr gdFont9X15b;
346 extern gdFontPtr gdFont7X13b;
347 extern gdFontPtr gdFont6X12;
348 extern gdFontPtr gdFont5X8;
349 
350 
351 #ifdef __cplusplus
352 }
353 #endif
354 
355 
356 #undef NLM_EXTERN
357 #ifdef NLM_EXPORT
358 #define NLM_EXTERN NLM_EXPORT
359 #else
360 #define NLM_EXTERN
361 #endif
362 
363 #endif /* GIFGEN_H */
364