MagickCore 7.1.1-43
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
image-private.h
1/*
2 Copyright @ 1999 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. You may
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#if defined(__cplusplus) || defined(c_plusplus)
22extern "C" {
23#endif
24
25#define MagickMax(x,y) (((x) > (y)) ? (x) : (y))
26#define MagickMin(x,y) (((x) < (y)) ? (x) : (y))
27
28#include "MagickCore/pixel-accessor.h"
29#include "MagickCore/quantum-private.h"
30
31#define BackgroundColor "#ffffff" /* white */
32#define BackgroundColorRGBA QuantumRange,QuantumRange,QuantumRange,OpaqueAlpha
33#define BorderColor "#dfdfdf" /* gray */
34#define BorderColorRGBA ScaleShortToQuantum(0xdfdf),\
35 ScaleShortToQuantum(0xdfdf),ScaleShortToQuantum(0xdfdf),OpaqueAlpha
36#define DefaultResolution 72.0
37#define DefaultTileFrame "15x15+3+3"
38#define DefaultTileGeometry "120x120+4+3>"
39#define DefaultTileLabel "%f\n%G\n%b"
40#define ForegroundColor "#000" /* black */
41#define ForegroundColorRGBA 0,0,0,OpaqueAlpha
42#define LoadImagesTag "Load/Images"
43#define LoadImageTag "Load/Image"
44#define Magick2PI 6.28318530717958647692528676655900576839433879875020
45#define MagickAbsoluteValue(x) ((x) < 0 ? -(x) : (x))
46#define MAGICK_INT_MAX (INT_MAX)
47#define MagickPHI 1.61803398874989484820458683436563811772030917980576
48#define MagickPI2 1.57079632679489661923132169163975144209858469968755
49#define MagickPI 3.1415926535897932384626433832795028841971693993751058209749445923078164062
50#define MAGICK_PTRDIFF_MAX (PTRDIFF_MAX)
51#define MAGICK_PTRDIFF_MIN (-PTRDIFF_MAX-1)
52#define MagickSQ1_2 0.70710678118654752440084436210484903928483593768847
53#define MagickSQ2 1.41421356237309504880168872420969807856967187537695
54#define MagickSQ2PI 2.50662827463100024161235523934010416269302368164062
55#define MAGICK_SIZE_MAX (SIZE_MAX)
56#define MAGICK_SSIZE_MAX (SSIZE_MAX)
57#define MAGICK_SSIZE_MIN (-SSIZE_MAX-1)
58#define MAGICK_UINT_MAX (UINT_MAX)
59#define MAGICK_ULONG_MAX (ULONG_MAX)
60#define MAGICK_USHORT_MAX (USHRT_MAX)
61#define MatteColor "#bdbdbd" /* gray */
62#define MatteColorRGBA ScaleShortToQuantum(0xbdbd),\
63 ScaleShortToQuantum(0xbdbd),ScaleShortToQuantum(0xbdbd),OpaqueAlpha
64#define PSDensityGeometry "72.0x72.0"
65#define PSPageGeometry "612x792"
66#define SaveImagesTag "Save/Images"
67#define SaveImageTag "Save/Image"
68#define TransparentColor "#00000000" /* transparent black */
69#define TransparentColorRGBA 0,0,0,TransparentAlpha
70#define UndefinedCompressionQuality 0UL
71#define UndefinedTicksPerSecond 100L
72
73static inline int CastDoubleToInt(const double x)
74{
75 double
76 value;
77
78 if (IsNaN(x) != 0)
79 {
80 errno=ERANGE;
81 return(0);
82 }
83 value=(x < 0.0) ? ceil(x) : floor(x);
84 if (value < 0.0)
85 {
86 errno=ERANGE;
87 return(0);
88 }
89 if (value >= ((double) MAGICK_INT_MAX))
90 {
91 errno=ERANGE;
92 return(MAGICK_INT_MAX);
93 }
94 return((int) value);
95}
96
97static inline ptrdiff_t CastDoubleToPtrdiffT(const double x)
98{
99 double
100 value;
101
102 if (IsNaN(x) != 0)
103 {
104 errno=ERANGE;
105 return(0);
106 }
107 value=(x < 0.0) ? ceil(x) : floor(x);
108 if (value < ((double) MAGICK_PTRDIFF_MIN))
109 {
110 errno=ERANGE;
111 return(MAGICK_PTRDIFF_MIN);
112 }
113 if (value >= ((double) MAGICK_PTRDIFF_MAX))
114 {
115 errno=ERANGE;
116 return(MAGICK_PTRDIFF_MAX);
117 }
118 return((ptrdiff_t) value);
119}
120
121static inline QuantumAny CastDoubleToQuantumAny(const double x)
122{
123 double
124 value;
125
126 if (IsNaN(x) != 0)
127 {
128 errno=ERANGE;
129 return(0);
130 }
131 value=(x < 0.0) ? ceil(x) : floor(x);
132 if (value < 0.0)
133 {
134 errno=ERANGE;
135 return(0);
136 }
137 if (value >= ((double) ((QuantumAny) ~0)))
138 {
139 errno=ERANGE;
140 return((QuantumAny) ~0);
141 }
142 return((QuantumAny) value);
143}
144
145static inline size_t CastDoubleToSizeT(const double x)
146{
147 double
148 value;
149
150 if (IsNaN(x) != 0)
151 {
152 errno=ERANGE;
153 return(0);
154 }
155 value=(x < 0.0) ? ceil(x) : floor(x);
156 if (value < 0.0)
157 {
158 errno=ERANGE;
159 return(0);
160 }
161 if (value >= ((double) MAGICK_SIZE_MAX))
162 {
163 errno=ERANGE;
164 return(MAGICK_SIZE_MAX);
165 }
166 return((size_t) value);
167}
168
169
170static inline ssize_t CastDoubleToSsizeT(const double x)
171{
172 double
173 value;
174
175 if (IsNaN(x) != 0)
176 {
177 errno=ERANGE;
178 return(0);
179 }
180 value=(x < 0.0) ? ceil(x) : floor(x);
181 if (value < ((double) MAGICK_SSIZE_MIN))
182 {
183 errno=ERANGE;
184 return(MAGICK_SSIZE_MIN);
185 }
186 if (value >= ((double) MAGICK_SSIZE_MAX))
187 {
188 errno=ERANGE;
189 return(MAGICK_SSIZE_MAX);
190 }
191 return((ssize_t) value);
192}
193
194static inline unsigned int CastDoubleToUInt(const double x)
195{
196 double
197 value;
198 if (IsNaN(x) != 0)
199 {
200 errno=ERANGE;
201 return(0);
202 }
203 value=(x < 0.0) ? ceil(x) : floor(x);
204 if (value < 0.0)
205 {
206 errno=ERANGE;
207 return((QuantumAny) 0);
208 }
209 if (value >= ((double) MAGICK_UINT_MAX))
210 {
211 errno=ERANGE;
212 return(MAGICK_UINT_MAX);
213 }
214 return((unsigned int) value);
215}
216
217static inline unsigned short CastDoubleToUShort(const double x)
218{
219 double
220 value;
221
222 if (IsNaN(x) != 0)
223 {
224 errno=ERANGE;
225 return(0);
226 }
227 value=(x < 0.0) ? ceil(x) : floor(x);
228 if (value < 0.0)
229 {
230 errno=ERANGE;
231 return(0);
232 }
233 if (value >= ((double) MAGICK_USHORT_MAX))
234 {
235 errno=ERANGE;
236 return(MAGICK_USHORT_MAX);
237 }
238 return((unsigned short) value);
239}
240
241static inline double DegreesToRadians(const double degrees)
242{
243 return((double) (MagickPI*degrees/180.0));
244}
245
246static inline size_t GetImageChannels(const Image *image)
247{
248 ssize_t
249 i;
250
251 size_t
252 channels;
253
254 channels=0;
255 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
256 {
257 PixelChannel channel = GetPixelChannelChannel(image,i);
258 PixelTrait traits = GetPixelChannelTraits(image,channel);
259 if ((traits & UpdatePixelTrait) != 0)
260 channels++;
261 }
262 return(channels == 0 ? (size_t) 1 : channels);
263}
264
265static inline double RadiansToDegrees(const double radians)
266{
267 return((double) (180.0*radians/MagickPI));
268}
269
270static inline unsigned char ScaleColor5to8(const unsigned int color)
271{
272 return((unsigned char) (((color) << 3) | ((color) >> 2)));
273}
274
275static inline unsigned char ScaleColor6to8(const unsigned int color)
276{
277 return((unsigned char) (((color) << 2) | ((color) >> 4)));
278}
279
280static inline unsigned int ScaleColor8to5(const unsigned char color)
281{
282 return((unsigned int) (((color) & ~0x07) >> 3));
283}
284
285static inline unsigned int ScaleColor8to6(const unsigned char color)
286{
287 return((unsigned int) (((color) & ~0x03) >> 2));
288}
289
290/* compat inline wrapper for backport ease */
291static inline ssize_t CastDoubleToLong(const double x) {
292 return CastDoubleToSsizeT(x);
293}
294
295static inline size_t CastDoubleToUnsigned(const double x) {
296 return CastDoubleToSizeT(x);
297}
298#if defined(__cplusplus) || defined(c_plusplus)
299}
300#endif
301
302#endif