1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
/*
Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization
dedicated to making software imaging solutions freely available.
You may not use this file except in compliance with the License. You may
obtain a copy of the License at
https://imagemagick.org/script/license.php
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
MagickCore image private methods.
*/
#ifndef MAGICKCORE_IMAGE_PRIVATE_H
#define MAGICKCORE_IMAGE_PRIVATE_H
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
#define MagickMax(x,y) (((x) > (y)) ? (x) : (y))
#define MagickMin(x,y) (((x) < (y)) ? (x) : (y))
#include "MagickCore/pixel-accessor.h"
#include "MagickCore/quantum-private.h"
#define BackgroundColor "#ffffff" /* white */
#define BackgroundColorRGBA QuantumRange,QuantumRange,QuantumRange,OpaqueAlpha
#define BorderColor "#dfdfdf" /* gray */
#define BorderColorRGBA ScaleShortToQuantum(0xdfdf),\
ScaleShortToQuantum(0xdfdf),ScaleShortToQuantum(0xdfdf),OpaqueAlpha
#define DefaultResolution 72.0
#define DefaultTileFrame "15x15+3+3"
#define DefaultTileGeometry "120x120+4+3>"
#define DefaultTileLabel "%f\n%G\n%b"
#define ForegroundColor "#000" /* black */
#define ForegroundColorRGBA 0,0,0,OpaqueAlpha
#define LoadImagesTag "Load/Images"
#define LoadImageTag "Load/Image"
#define Magick2PI 6.28318530717958647692528676655900576839433879875020
#define MagickAbsoluteValue(x) ((x) < 0 ? -(x) : (x))
#define MagickPHI 1.61803398874989484820458683436563811772030917980576
#define MagickPI2 1.57079632679489661923132169163975144209858469968755
#define MagickPI 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define MAGICK_PTRDIFF_MAX (PTRDIFF_MAX)
#define MAGICK_PTRDIFF_MIN (-PTRDIFF_MAX-1)
#define MagickSQ1_2 0.70710678118654752440084436210484903928483593768847
#define MagickSQ2 1.41421356237309504880168872420969807856967187537695
#define MagickSQ2PI 2.50662827463100024161235523934010416269302368164062
#define MAGICK_SIZE_MAX (SIZE_MAX)
#define MAGICK_SSIZE_MAX (SSIZE_MAX)
#define MAGICK_SSIZE_MIN (-SSIZE_MAX-1)
#define MAGICK_UINT_MAX (UINT_MAX)
#define MAGICK_ULONG_MAX (ULONG_MAX)
#define MAGICK_USHORT_MAX (USHRT_MAX)
#define MatteColor "#bdbdbd" /* gray */
#define MatteColorRGBA ScaleShortToQuantum(0xbdbd),\
ScaleShortToQuantum(0xbdbd),ScaleShortToQuantum(0xbdbd),OpaqueAlpha
#define PSDensityGeometry "72.0x72.0"
#define PSPageGeometry "612x792"
#define SaveImagesTag "Save/Images"
#define SaveImageTag "Save/Image"
#define TransparentColor "#00000000" /* transparent black */
#define TransparentColorRGBA (Quantum) 0,(Quantum) 0,(Quantum) 0,TransparentAlpha
#define UndefinedCompressionQuality 0UL
#define UndefinedTicksPerSecond 100L
static inline ptrdiff_t CastDoubleToPtrdiffT(const double x)
{
double
value;
if (IsNaN(x) != 0)
{
errno=ERANGE;
return(0);
}
value=(x < 0.0) ? ceil(x) : floor(x);
if (value < ((double) MAGICK_PTRDIFF_MIN))
{
errno=ERANGE;
return(MAGICK_PTRDIFF_MIN);
}
if (value > ((double) MAGICK_PTRDIFF_MAX))
{
errno=ERANGE;
return(MAGICK_PTRDIFF_MAX);
}
return((ptrdiff_t) value);
}
static inline QuantumAny CastDoubleToQuantumAny(const double x)
{
double
value;
if (IsNaN(x) != 0)
{
errno=ERANGE;
return(0);
}
value=(x < 0.0) ? ceil(x) : floor(x);
if (value < 0.0)
{
errno=ERANGE;
return(0);
}
if (value > ((double) ((QuantumAny) ~0)))
{
errno=ERANGE;
return((QuantumAny) ~0);
}
return((QuantumAny) value);
}
static inline size_t CastDoubleToSizeT(const double x)
{
double
value;
if (IsNaN(x) != 0)
{
errno=ERANGE;
return(0);
}
value=(x < 0.0) ? ceil(x) : floor(x);
if (value < 0.0)
{
errno=ERANGE;
return(0);
}
if (value > ((double) MAGICK_SIZE_MAX))
{
errno=ERANGE;
return(MAGICK_SIZE_MAX);
}
return((size_t) value);
}
static inline ssize_t CastDoubleToSsizeT(const double x)
{
double
value;
if (IsNaN(x) != 0)
{
errno=ERANGE;
return(0);
}
value=(x < 0.0) ? ceil(x) : floor(x);
if (value < ((double) MAGICK_SSIZE_MIN))
{
errno=ERANGE;
return(MAGICK_SSIZE_MIN);
}
if (value > ((double) MAGICK_SSIZE_MAX))
{
errno=ERANGE;
return(MAGICK_SSIZE_MAX);
}
return((ssize_t) value);
}
static inline unsigned int CastDoubleToUInt(const double x)
{
double
value;
if (IsNaN(x) != 0)
{
errno=ERANGE;
return(0);
}
value=(x < 0.0) ? ceil(x) : floor(x);
if (value < 0.0)
{
errno=ERANGE;
return(0);
}
if (value > ((double) MAGICK_UINT_MAX))
{
errno=ERANGE;
return(MAGICK_UINT_MAX);
}
return((unsigned int) value);
}
static inline unsigned short CastDoubleToUShort(const double x)
{
double
value;
if (IsNaN(x) != 0)
{
errno=ERANGE;
return(0);
}
value=(x < 0.0) ? ceil(x) : floor(x);
if (value < 0.0)
{
errno=ERANGE;
return(0);
}
if (value > ((double) MAGICK_USHORT_MAX))
{
errno=ERANGE;
return(MAGICK_USHORT_MAX);
}
return((unsigned short) value);
}
static inline double DegreesToRadians(const double degrees)
{
return((double) (MagickPI*degrees/180.0));
}
static inline size_t GetImageChannels(const Image *image)
{
ssize_t
i;
size_t
channels;
channels=0;
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
PixelChannel channel = GetPixelChannelChannel(image,i);
PixelTrait traits = GetPixelChannelTraits(image,channel);
if ((traits & UpdatePixelTrait) != 0)
channels++;
}
return(channels == 0 ? (size_t) 1 : channels);
}
static inline double RadiansToDegrees(const double radians)
{
return((double) (180.0*radians/MagickPI));
}
static inline unsigned char ScaleColor5to8(const unsigned int color)
{
return((unsigned char) (((color) << 3) | ((color) >> 2)));
}
static inline unsigned char ScaleColor6to8(const unsigned int color)
{
return((unsigned char) (((color) << 2) | ((color) >> 4)));
}
static inline unsigned int ScaleColor8to5(const unsigned char color)
{
return((unsigned int) (((color) & ~0x07) >> 3));
}
static inline unsigned int ScaleColor8to6(const unsigned char color)
{
return((unsigned int) (((color) & ~0x03) >> 2));
}
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
#endif
|