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 MagickPI 3.14159265358979323846264338327950288419716939937510
33 #define Magick2PI 6.28318530717958647692528676655900576839433879875020
34 #define MagickPHI 1.61803398874989484820458683436563811772030917980576
35 #define MagickPI2 1.57079632679489661923132169163975144209858469968755
36 #define MagickSQ1_2 0.70710678118654752440084436210484903928483593768847
37 #define MagickSQ2 1.41421356237309504880168872420969807856967187537695
38 #define MagickSQ2PI 2.50662827463100024161235523934010416269302368164062
39 #define MAGICK_SIZE_MAX (SIZE_MAX)
40 #define MAGICK_SSIZE_MAX (SSIZE_MAX)
41 #define MAGICK_SSIZE_MIN (-(SSIZE_MAX)-1)
42 #define UndefinedTicksPerSecond 100L
43 #define UndefinedCompressionQuality 0UL
44 
45 extern MagickExport const char
47  BorderColor[],
52  MatteColor[],
53  LoadImageTag[],
54  LoadImagesTag[],
57  SaveImageTag[],
58  SaveImagesTag[];
59 
60 extern MagickExport const double
62 
63 static inline size_t CastDoubleToUnsigned(const double x)
64 {
65  if (IsNaN(x) != 0)
66  {
67  errno=ERANGE;
68  return(0);
69  }
70  if (floor(x) > ((double) MAGICK_SSIZE_MAX-1))
71  {
72  errno=ERANGE;
73  return((size_t) MAGICK_SIZE_MAX);
74  }
75  if (ceil(x) < 0.0)
76  {
77  errno=ERANGE;
78  return(0);
79  }
80  return((size_t) x);
81 }
82 
83 static inline ssize_t CastDoubleToLong(const double x)
84 {
85  if (IsNaN(x) != 0)
86  {
87  errno=ERANGE;
88  return(0);
89  }
90  if (floor(x) > ((double) MAGICK_SSIZE_MAX-1))
91  {
92  errno=ERANGE;
93  return((ssize_t) MAGICK_SSIZE_MAX);
94  }
95  if (ceil(x) < ((double) MAGICK_SSIZE_MIN+1))
96  {
97  errno=ERANGE;
98  return((ssize_t) MAGICK_SSIZE_MIN);
99  }
100  return((ssize_t) x);
101 }
102 
103 static inline double DegreesToRadians(const double degrees)
104 {
105  return((double) (MagickPI*degrees/180.0));
106 }
107 
108 static inline MagickRealType RadiansToDegrees(const MagickRealType radians)
109 {
110  return((MagickRealType) (180.0*radians/MagickPI));
111 }
112 
113 static inline unsigned char ScaleColor5to8(const unsigned int color)
114 {
115  return((unsigned char) (((color) << 3) | ((color) >> 2)));
116 }
117 
118 static inline unsigned char ScaleColor6to8(const unsigned int color)
119 {
120  return((unsigned char) (((color) << 2) | ((color) >> 4)));
121 }
122 
123 static inline unsigned int ScaleColor8to5(const unsigned char color)
124 {
125  return((unsigned int) (((color) & ~0x07) >> 3));
126 }
127 
128 static inline unsigned int ScaleColor8to6(const unsigned char color)
129 {
130  return((unsigned int) (((color) & ~0x03) >> 2));
131 }
132 
133 #if defined(__cplusplus) || defined(c_plusplus)
134 }
135 #endif
136 
137 #endif
MagickDoubleType MagickRealType
Definition: magick-type.h:125
MagickExport const char BackgroundColor[]
Definition: image.c:109
#define MAGICK_SSIZE_MIN
Definition: image-private.h:41
MagickExport const char PSDensityGeometry[]
Definition: image.c:118
static unsigned char ScaleColor6to8(const unsigned int color)
Definition: image-private.h:118
#define MAGICK_SIZE_MAX
Definition: image-private.h:39
MagickExport const char DefaultTileFrame[]
Definition: image.c:111
static unsigned char ScaleColor5to8(const unsigned int color)
Definition: image-private.h:113
#define MAGICK_SSIZE_MAX
Definition: image-private.h:40
MagickExport const char DefaultTileGeometry[]
Definition: image.c:112
static size_t CastDoubleToUnsigned(const double x)
Definition: image-private.h:63
#define MagickPI
Definition: image-private.h:32
MagickExport const char LoadImageTag[]
Definition: image.c:115
MagickExport const char ForegroundColor[]
Definition: image.c:114
static unsigned int ScaleColor8to6(const unsigned char color)
Definition: image-private.h:128
static ssize_t CastDoubleToLong(const double x)
Definition: image-private.h:83
static double DegreesToRadians(const double degrees)
Definition: image-private.h:103
static unsigned int ScaleColor8to5(const unsigned char color)
Definition: image-private.h:123
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
static MagickRealType RadiansToDegrees(const MagickRealType radians)
Definition: image-private.h:108
#define MagickExport
Definition: method-attribute.h:80
MagickExport const double DefaultResolution
Definition: image.c:125
MagickExport const char PSPageGeometry[]
Definition: image.c:119
MagickExport const char SaveImagesTag[]
Definition: image.c:121