MagickCore  6.8.9
image-private.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2014 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  http://www.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 IsNaN(a) ((a) != (a) ? MagickTrue : MagickFalse)
30 #define MagickPI 3.14159265358979323846264338327950288419716939937510
31 #define Magick2PI 6.28318530717958647692528676655900576839433879875020
32 #define MagickPHI 1.61803398874989484820458683436563811772030917980576
33 #define MagickPI2 1.57079632679489661923132169163975144209858469968755
34 #define MagickSQ1_2 0.70710678118654752440084436210484903928483593768847
35 #define MagickSQ2 1.41421356237309504880168872420969807856967187537695
36 #define MagickSQ2PI 2.50662827463100024161235523934010416269302368164062
37 #define MAGICK_SIZE_MAX (SIZE_MAX)
38 #define MAGICK_SSIZE_MAX (SSIZE_MAX)
39 #define MAGICK_SSIZE_MIN (-(SSIZE_MAX)-1)
40 #define UndefinedTicksPerSecond 100L
41 #define UndefinedCompressionQuality 0UL
42 
43 extern MagickExport const char
45  BorderColor[],
50  MatteColor[],
51  LoadImageTag[],
52  LoadImagesTag[],
55  SaveImageTag[],
56  SaveImagesTag[];
57 
58 extern MagickExport const double
60 
61 
62 static inline size_t CastDoubleToLong(const double x)
63 {
64  double
65  value;
66 
67  if (IsNaN(x) != 0)
68  {
69  errno=ERANGE;
70  return(0);
71  }
72  if (x < 0.0)
73  {
74  value=ceil(x);
75  if (value < ((double) MAGICK_SSIZE_MIN))
76  {
77  errno=ERANGE;
78  return((ssize_t) MAGICK_SSIZE_MIN);
79  }
80  }
81  else
82  {
83  value=floor(x);
84  if (value > ((double) MAGICK_SSIZE_MAX))
85  {
86  errno=ERANGE;
87  return((ssize_t) MAGICK_SSIZE_MAX);
88  }
89  }
90  return((ssize_t) value);
91 }
92 
93 static inline QuantumAny CastDoubleToQuantumAny(const double x)
94 {
95  if (IsNaN(x) != 0)
96  return(0);
97  if (x > ((double) ((QuantumAny) ~0)))
98  return((QuantumAny) ~0);
99  if (x < 0.0)
100  return(0.0);
101  return((QuantumAny) (x+0.5));
102 }
103 
104 static inline size_t CastDoubleToUnsigned(const double x)
105 {
106  double
107  value;
108 
109  if (IsNaN(x) != 0)
110  {
111  errno=ERANGE;
112  return(0);
113  }
114  value=floor(x);
115  if (value >= ((double) MAGICK_SIZE_MAX))
116  {
117  errno=ERANGE;
118  return((size_t) MAGICK_SIZE_MAX);
119  }
120  if (value < 0.0)
121  {
122  errno=ERANGE;
123  return(0);
124  }
125  return((size_t) value);
126 }
127 
128 static inline double DegreesToRadians(const double degrees)
129 {
130  return((double) (MagickPI*degrees/180.0));
131 }
132 
133 static inline MagickRealType RadiansToDegrees(const MagickRealType radians)
134 {
135  return((MagickRealType) (180.0*radians/MagickPI));
136 }
137 
138 static inline unsigned char ScaleColor5to8(const unsigned int color)
139 {
140  return((unsigned char) (((color) << 3) | ((color) >> 2)));
141 }
142 
143 static inline unsigned char ScaleColor6to8(const unsigned int color)
144 {
145  return((unsigned char) (((color) << 2) | ((color) >> 4)));
146 }
147 
148 static inline unsigned int ScaleColor8to5(const unsigned char color)
149 {
150  return((unsigned int) (((color) & ~0x07) >> 3));
151 }
152 
153 static inline unsigned int ScaleColor8to6(const unsigned char color)
154 {
155  return((unsigned int) (((color) & ~0x03) >> 2));
156 }
157 
158 #if defined(__cplusplus) || defined(c_plusplus)
159 }
160 #endif
161 
162 #endif
MagickExport const char BackgroundColor[]
Definition: image.c:106
#define MAGICK_SSIZE_MIN
Definition: image-private.h:39
MagickExport const char PSDensityGeometry[]
Definition: image.c:115
static unsigned char ScaleColor6to8(const unsigned int color)
Definition: image-private.h:143
#define MAGICK_SIZE_MAX
Definition: image-private.h:37
MagickExport const char DefaultTileFrame[]
Definition: image.c:108
static unsigned char ScaleColor5to8(const unsigned int color)
Definition: image-private.h:138
#define MAGICK_SSIZE_MAX
Definition: image-private.h:38
MagickExport const char DefaultTileGeometry[]
Definition: image.c:109
static size_t CastDoubleToUnsigned(const double x)
Definition: image-private.h:104
#define MagickPI
Definition: image-private.h:30
MagickExport const char LoadImageTag[]
Definition: image.c:112
float MagickRealType
Definition: magick-type.h:79
MagickExport const char ForegroundColor[]
Definition: image.c:111
static QuantumAny CastDoubleToQuantumAny(const double x)
Definition: image-private.h:93
#define IsNaN(a)
Definition: image-private.h:29
static unsigned int ScaleColor8to6(const unsigned char color)
Definition: image-private.h:153
static double DegreesToRadians(const double degrees)
Definition: image-private.h:128
static unsigned int ScaleColor8to5(const unsigned char color)
Definition: image-private.h:148
MagickExport const char DefaultTileLabel[]
Definition: image.c:110
static size_t CastDoubleToLong(const double x)
Definition: image-private.h:62
MagickExport const char BorderColor[]
Definition: image.c:107
MagickExport const char SaveImageTag[]
Definition: image.c:117
MagickExport const char LoadImagesTag[]
Definition: image.c:113
MagickExport const char MatteColor[]
Definition: image.c:114
static MagickRealType RadiansToDegrees(const MagickRealType radians)
Definition: image-private.h:133
#define MagickExport
Definition: method-attribute.h:98
MagickExport const double DefaultResolution
Definition: image.c:122
MagickSizeType QuantumAny
Definition: magick-type.h:173
MagickExport const char PSPageGeometry[]
Definition: image.c:116
MagickExport const char SaveImagesTag[]
Definition: image.c:118