MagickCore  6.9.10
Convert, Edit, Or Compose Bitmap Images
image-private.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2019 ImageMagick Studio LLC, a non-profit organization
3  dedicated to making software imaging solutions freely available.
4 
5  You may not use this file except in compliance with the License.
6  obtain a copy of the License at
7 
8  https://imagemagick.org/script/license.php
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  MagickCore image private methods.
17 */
18 #ifndef MAGICKCORE_IMAGE_PRIVATE_H
19 #define MAGICKCORE_IMAGE_PRIVATE_H
20 
21 #include <errno.h>
22 #include <limits.h>
23 #include <stdint.h>
24 
25 #if defined(__cplusplus) || defined(c_plusplus)
26 extern "C" {
27 #endif
28 
29 #define MagickAbsoluteValue(x) ((x) < 0 ? -(x) : (x))
30 #define MagickMax(x,y) (((x) > (y)) ? (x) : (y))
31 #define MagickMin(x,y) (((x) < (y)) ? (x) : (y))
32 #define MAGICK_INT_MAX (INT_MAX)
33 #define MagickPI 3.14159265358979323846264338327950288419716939937510
34 #define Magick2PI 6.28318530717958647692528676655900576839433879875020
35 #define MagickPHI 1.61803398874989484820458683436563811772030917980576
36 #define MagickPI2 1.57079632679489661923132169163975144209858469968755
37 #define MAGICK_PTRDIFF_MAX (PTRDIFF_MAX)
38 #define MAGICK_PTRDIFF_MIN (-PTRDIFF_MAX-1)
39 #define MagickSQ1_2 0.70710678118654752440084436210484903928483593768847
40 #define MagickSQ2 1.41421356237309504880168872420969807856967187537695
41 #define MagickSQ2PI 2.50662827463100024161235523934010416269302368164062
42 #define MAGICK_SIZE_MAX (SIZE_MAX)
43 #define MAGICK_SSIZE_MAX (SSIZE_MAX)
44 #define MAGICK_SSIZE_MIN (-(SSIZE_MAX)-1)
45 #define UndefinedTicksPerSecond 100L
46 #define UndefinedCompressionQuality 0UL
47 
48 extern MagickExport const char
50  BorderColor[],
55  MatteColor[],
56  LoadImageTag[],
57  LoadImagesTag[],
60  SaveImageTag[],
61  SaveImagesTag[];
62 
63 extern MagickExport const double
65 
66 
67 static inline int CastDoubleToInt(const double x)
68 {
69  double
70  value;
71 
72  if (IsNaN(x) != 0)
73  {
74  errno=ERANGE;
75  return(0);
76  }
77  value=(x < 0.0) ? ceil(x) : floor(x);
78  if (value < 0.0)
79  {
80  errno=ERANGE;
81  return(0);
82  }
83  if (value >= ((double) MAGICK_INT_MAX))
84  {
85  errno=ERANGE;
86  return(MAGICK_INT_MAX);
87  }
88  return((int) value);
89 }
90 
91 static inline ssize_t CastDoubleToLong(const double x)
92 {
93  double
94  value;
95 
96  if (IsNaN(x) != 0)
97  {
98  errno=ERANGE;
99  return(0);
100  }
101  value=(x < 0.0) ? ceil(x) : floor(x);
102  if (value < ((double) MAGICK_SSIZE_MIN))
103  {
104  errno=ERANGE;
105  return(MAGICK_SSIZE_MIN);
106  }
107  if (value >= ((double) MAGICK_SSIZE_MAX))
108  {
109  errno=ERANGE;
110  return(MAGICK_SSIZE_MAX);
111  }
112  return((ssize_t) value);
113 }
114 
115 static inline QuantumAny CastDoubleToQuantumAny(const double x)
116 {
117  double
118  value;
119 
120  if (IsNaN(x) != 0)
121  {
122  errno=ERANGE;
123  return(0);
124  }
125  value=(x < 0.0) ? ceil(x) : floor(x);
126  if (value < 0.0)
127  {
128  errno=ERANGE;
129  return(0);
130  }
131  if (value >= ((double) ((QuantumAny) ~0)))
132  {
133  errno=ERANGE;
134  return((QuantumAny) ~0);
135  }
136  return((QuantumAny) value);
137 }
138 
139 static inline size_t CastDoubleToUnsigned(const double x)
140 {
141  double
142  value;
143 
144  if (IsNaN(x) != 0)
145  {
146  errno=ERANGE;
147  return(0);
148  }
149  value=(x < 0.0) ? ceil(x) : floor(x);
150  if (value < 0.0)
151  {
152  errno=ERANGE;
153  return(0);
154  }
155  if (value >= ((double) MAGICK_SIZE_MAX))
156  {
157  errno=ERANGE;
158  return(MAGICK_SIZE_MAX);
159  }
160  return((size_t) value);
161 }
162 
163 static inline double DegreesToRadians(const double degrees)
164 {
165  return((double) (MagickPI*degrees/180.0));
166 }
167 
168 static inline MagickRealType RadiansToDegrees(const MagickRealType radians)
169 {
170  return((MagickRealType) (180.0*radians/MagickPI));
171 }
172 
173 static inline unsigned char ScaleColor5to8(const unsigned int color)
174 {
175  return((unsigned char) (((color) << 3) | ((color) >> 2)));
176 }
177 
178 static inline unsigned char ScaleColor6to8(const unsigned int color)
179 {
180  return((unsigned char) (((color) << 2) | ((color) >> 4)));
181 }
182 
183 static inline unsigned int ScaleColor8to5(const unsigned char color)
184 {
185  return((unsigned int) (((color) & ~0x07) >> 3));
186 }
187 
188 static inline unsigned int ScaleColor8to6(const unsigned char color)
189 {
190  return((unsigned int) (((color) & ~0x03) >> 2));
191 }
192 
193 #if defined(__cplusplus) || defined(c_plusplus)
194 }
195 #endif
196 
197 #endif
MagickDoubleType MagickRealType
Definition: magick-type.h:125
MagickExport const char BackgroundColor[]
Definition: image.c:109
#define MAGICK_SSIZE_MIN
Definition: image-private.h:44
MagickExport const char PSDensityGeometry[]
Definition: image.c:118
static unsigned char ScaleColor6to8(const unsigned int color)
Definition: image-private.h:178
#define MAGICK_SIZE_MAX
Definition: image-private.h:42
MagickExport const char DefaultTileFrame[]
Definition: image.c:111
static unsigned char ScaleColor5to8(const unsigned int color)
Definition: image-private.h:173
#define MAGICK_SSIZE_MAX
Definition: image-private.h:43
MagickExport const char DefaultTileGeometry[]
Definition: image.c:112
static int CastDoubleToInt(const double x)
Definition: image-private.h:67
static size_t CastDoubleToUnsigned(const double x)
Definition: image-private.h:139
#define MagickPI
Definition: image-private.h:33
MagickExport const char LoadImageTag[]
Definition: image.c:115
MagickExport const char ForegroundColor[]
Definition: image.c:114
static QuantumAny CastDoubleToQuantumAny(const double x)
Definition: image-private.h:115
static unsigned int ScaleColor8to6(const unsigned char color)
Definition: image-private.h:188
static ssize_t CastDoubleToLong(const double x)
Definition: image-private.h:91
static double DegreesToRadians(const double degrees)
Definition: image-private.h:163
static unsigned int ScaleColor8to5(const unsigned char color)
Definition: image-private.h:183
MagickExport const char DefaultTileLabel[]
Definition: image.c:113
MagickExport const char BorderColor[]
Definition: image.c:110
MagickExport const char SaveImageTag[]
Definition: image.c:120
#define IsNaN(a)
Definition: magick-type.h:214
MagickExport const char LoadImagesTag[]
Definition: image.c:116
MagickExport const char MatteColor[]
Definition: image.c:117
#define MAGICK_INT_MAX
Definition: image-private.h:32
static MagickRealType RadiansToDegrees(const MagickRealType radians)
Definition: image-private.h:168
#define MagickExport
Definition: method-attribute.h:80
MagickExport const double DefaultResolution
Definition: image.c:125
MagickSizeType QuantumAny
Definition: magick-type.h:150
MagickExport const char PSPageGeometry[]
Definition: image.c:119
MagickExport const char SaveImagesTag[]
Definition: image.c:121