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 #include <errno.h>
19 #include <stdint.h>
20 #include <limits.h>
21 #ifndef MAGICKCORE_IMAGE_PRIVATE_H
22 #define MAGICKCORE_IMAGE_PRIVATE_H
23 
24 #include <errno.h>
25 #include <limits.h>
26 #include <stdint.h>
27 
28 #if defined(__cplusplus) || defined(c_plusplus)
29 extern "C" {
30 #endif
31 
32 #define MagickAbsoluteValue(x) ((x) < 0 ? -(x) : (x))
33 #define MagickMax(x,y) (((x) > (y)) ? (x) : (y))
34 #define MagickMin(x,y) (((x) < (y)) ? (x) : (y))
35 #define MagickPI 3.14159265358979323846264338327950288419716939937510
36 #define Magick2PI 6.28318530717958647692528676655900576839433879875020
37 #define MagickPHI 1.61803398874989484820458683436563811772030917980576
38 #define MagickPI2 1.57079632679489661923132169163975144209858469968755
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
62 
63 extern MagickExport const double
65 
66 
67 static inline size_t CastDoubleToLong(const double x)
68 {
69  double
70  value;
71 
72  if (IsNaN(x) != 0)
73  {
74  errno=ERANGE;
75  return(0);
76  }
77  if (x < 0.0)
78  {
79  value=ceil(x);
80  if (value < ((double) MAGICK_SSIZE_MIN))
81  {
82  errno=ERANGE;
83  return((ssize_t) MAGICK_SSIZE_MIN);
84  }
85  }
86  else
87  {
88  value=floor(x);
89  if (value > ((double) MAGICK_SSIZE_MAX))
90  {
91  errno=ERANGE;
92  return((ssize_t) MAGICK_SSIZE_MAX);
93  }
94  }
95  return((ssize_t) value);
96 }
97 
98 static inline QuantumAny CastDoubleToQuantumAny(const double x)
99 {
100  if (IsNaN(x) != 0)
101  return(0);
102  if (x > ((double) ((QuantumAny) ~0)))
103  return((QuantumAny) ~0);
104  if (x < 0.0)
105  return(0.0);
106  return((QuantumAny) (x+0.5));
107 }
108 
109 static inline size_t CastDoubleToUnsigned(const double x)
110 {
111  double
112  value;
113 
114  if (IsNaN(x) != 0)
115  {
116  errno=ERANGE;
117  return(0);
118  }
119  value=floor(x);
120  if (value >= ((double) MAGICK_SIZE_MAX))
121  {
122  errno=ERANGE;
123  return((size_t) MAGICK_SIZE_MAX);
124  }
125  if (value < 0.0)
126  {
127  errno=ERANGE;
128  return(0);
129  }
130  return((size_t) value);
131 }
132 
133 static inline double DegreesToRadians(const double degrees)
134 {
135  return((double) (MagickPI*degrees/180.0));
136 }
137 
138 static inline MagickRealType RadiansToDegrees(const MagickRealType radians)
139 {
140  return((MagickRealType) (180.0*radians/MagickPI));
141 }
142 
143 static inline unsigned char ScaleColor5to8(const unsigned int color)
144 {
145  return((unsigned char) (((color) << 3) | ((color) >> 2)));
146 }
147 
148 static inline unsigned char ScaleColor6to8(const unsigned int color)
149 {
150  return((unsigned char) (((color) << 2) | ((color) >> 4)));
151 }
152 
153 static inline unsigned int ScaleColor8to5(const unsigned char color)
154 {
155  return((unsigned int) (((color) & ~0x07) >> 3));
156 }
157 
158 static inline unsigned int ScaleColor8to6(const unsigned char color)
159 {
160  return((unsigned int) (((color) & ~0x03) >> 2));
161 }
162 
163 #if defined(__cplusplus) || defined(c_plusplus)
164 }
165 #endif
166 
167 #endif
MagickExport
#define MagickExport
Definition: method-attribute.h:80
DefaultTileFrame
const MagickExport char DefaultTileFrame[]
Definition: image-private.h:51
ForegroundColor
const MagickExport char ForegroundColor[]
Definition: image-private.h:54
BackgroundColor
const MagickExport char BackgroundColor[]
Definition: image.c:109
RadiansToDegrees
static MagickRealType RadiansToDegrees(const MagickRealType radians)
Definition: image-private.h:138
LoadImagesTag
const MagickExport char LoadImagesTag[]
Definition: image-private.h:57
ScaleColor8to6
static unsigned int ScaleColor8to6(const unsigned char color)
Definition: image-private.h:158
MAGICK_SSIZE_MAX
#define MAGICK_SSIZE_MAX
Definition: image-private.h:43
MatteColor
const MagickExport char MatteColor[]
Definition: image-private.h:55
ScaleColor6to8
static unsigned char ScaleColor6to8(const unsigned int color)
Definition: image-private.h:148
ScaleColor8to5
static unsigned int ScaleColor8to5(const unsigned char color)
Definition: image-private.h:153
IsNaN
#define IsNaN(a)
Definition: magick-type.h:214
CastDoubleToLong
static size_t CastDoubleToLong(const double x)
Definition: image-private.h:67
SaveImageTag
const MagickExport char SaveImageTag[]
Definition: image-private.h:60
QuantumAny
MagickSizeType QuantumAny
Definition: magick-type.h:150
PSDensityGeometry
const MagickExport char PSDensityGeometry[]
Definition: image-private.h:58
DefaultTileGeometry
const MagickExport char DefaultTileGeometry[]
Definition: image-private.h:52
SaveImagesTag
const MagickExport char SaveImagesTag[]
Definition: image-private.h:61
CastDoubleToUnsigned
static size_t CastDoubleToUnsigned(const double x)
Definition: image-private.h:109
MagickPI
#define MagickPI
Definition: image-private.h:35
CastDoubleToQuantumAny
static QuantumAny CastDoubleToQuantumAny(const double x)
Definition: image-private.h:98
LoadImageTag
const MagickExport char LoadImageTag[]
Definition: image-private.h:56
DefaultResolution
const MagickExport double DefaultResolution
Definition: image.c:125
DegreesToRadians
static double DegreesToRadians(const double degrees)
Definition: image-private.h:133
MagickRealType
MagickDoubleType MagickRealType
Definition: magick-type.h:125
MAGICK_SSIZE_MIN
#define MAGICK_SSIZE_MIN
Definition: image-private.h:44
DefaultTileLabel
const MagickExport char DefaultTileLabel[]
Definition: image-private.h:53
MAGICK_SIZE_MAX
#define MAGICK_SIZE_MAX
Definition: image-private.h:42
BorderColor
const MagickExport char BorderColor[]
Definition: image-private.h:50
PSPageGeometry
const MagickExport char PSPageGeometry[]
Definition: image-private.h:59
ScaleColor5to8
static unsigned char ScaleColor5to8(const unsigned int color)
Definition: image-private.h:143