1 #ifndef GD_INTERN_H
2 #define GD_INTERN_H
3
4 #include <limits.h>
5
6 #ifndef MAXPATHLEN
7 # ifdef PATH_MAX
8 # define MAXPATHLEN PATH_MAX
9 # elif defined(MAX_PATH)
10 # define MAXPATHLEN MAX_PATH
11 # else
12 # if defined(__GNU__)
13 # define MAXPATHLEN 4096
14 # else
15 # define MAXPATHLEN 256 /* Should be safe for any weird systems that do not define it */
16 # endif
17 # endif
18 #endif
19
20 #ifdef HAVE_STDINT_H
21 # include <stdint.h>
22 #else
23 # if defined(HAVE_INTTYPES_H)
24 # include <inttypes.h>
25 # else
26 # include "msinttypes/inttypes.h"
27 # endif
28 #endif
29
30 #include "gd.h"
31
32 #ifndef MIN
33 #define MIN(a,b) ((a)<(b)?(a):(b))
34 #endif
35 #define MIN3(a,b,c) ((a)<(b)?(MIN(a,c)):(MIN(b,c)))
36 #ifndef MAX
37 #define MAX(a,b) ((a)<(b)?(b):(a))
38 #endif
39 #define MAX3(a,b,c) ((a)<(b)?(MAX(b,c)):(MAX(a,c)))
40
41
42 typedef enum {
43 HORIZONTAL,
44 VERTICAL,
45 } gdAxis;
46
47 /* Convert a double to an unsigned char, rounding to the nearest
48 * integer and clamping the result between 0 and max. The absolute
49 * value of clr must be less than the maximum value of an unsigned
50 * short. */
51 static inline unsigned char
uchar_clamp(double clr,unsigned char max)52 uchar_clamp(double clr, unsigned char max) {
53 unsigned short result;
54
55 //assert(fabs(clr) <= SHRT_MAX);
56
57 /* Casting a negative float to an unsigned short is undefined.
58 * However, casting a float to a signed truncates toward zero and
59 * casting a negative signed value to an unsigned of the same size
60 * results in a bit-identical value (assuming twos-complement
61 * arithmetic). This is what we want: all legal negative values
62 * for clr will be greater than 255. */
63
64 /* Convert and clamp. */
65 result = (unsigned short)(short)(clr + 0.5);
66 if (result > max) {
67 result = (clr < 0) ? 0 : max;
68 }/* if */
69
70 return result;
71 }/* uchar_clamp*/
72
73
74 /* Internal prototypes: */
75
76 /* gd_rotate.c */
77 gdImagePtr gdImageRotate90(gdImagePtr src, int ignoretransparent);
78 gdImagePtr gdImageRotate180(gdImagePtr src, int ignoretransparent);
79 gdImagePtr gdImageRotate270(gdImagePtr src, int ignoretransparent);
80
81
82
83
84
85
86 #endif
87