Coverage Report

Created: 2023-06-07 07:18

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