MagickCore  7.1.0
image-private.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2021 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)
22 extern "C" {
23 #endif
24 
26 
27 #define BackgroundColor "#ffffff" /* white */
28 #define BorderColor "#dfdfdf" /* gray */
29 #define DefaultResolution 72.0
30 #define DefaultTileFrame "15x15+3+3"
31 #define DefaultTileGeometry "120x120+4+3>"
32 #define DefaultTileLabel "%f\n%G\n%b"
33 #define ForegroundColor "#000" /* black */
34 #define LoadImagesTag "Load/Images"
35 #define LoadImageTag "Load/Image"
36 #define Magick2PI 6.28318530717958647692528676655900576839433879875020
37 #define MagickAbsoluteValue(x) ((x) < 0 ? -(x) : (x))
38 #define MagickMax(x,y) (((x) > (y)) ? (x) : (y))
39 #define MagickMin(x,y) (((x) < (y)) ? (x) : (y))
40 #define MagickPHI 1.61803398874989484820458683436563811772030917980576
41 #define MagickPI2 1.57079632679489661923132169163975144209858469968755
42 #define MagickPI 3.14159265358979323846264338327950288419716939937510
43 #define MagickSQ1_2 0.70710678118654752440084436210484903928483593768847
44 #define MagickSQ2 1.41421356237309504880168872420969807856967187537695
45 #define MagickSQ2PI 2.50662827463100024161235523934010416269302368164062
46 #define MatteColor "#bdbdbd" /* gray */
47 #define PSDensityGeometry "72.0x72.0"
48 #define PSPageGeometry "612x792"
49 #define SaveImagesTag "Save/Images"
50 #define SaveImageTag "Save/Image"
51 #define TransparentColor "#00000000" /* transparent black */
52 #define UndefinedCompressionQuality 0UL
53 #define UndefinedTicksPerSecond 100L
54 
55 static inline ssize_t CastDoubleToLong(const double value)
56 {
57  if (IsNaN(value) != 0)
58  return(0);
59  if (floor(value) > ((double) MAGICK_SSIZE_MAX-1))
60  return((ssize_t) MAGICK_SSIZE_MAX);
61  if (ceil(value) < ((double) MAGICK_SSIZE_MIN+1))
62  return((ssize_t) MAGICK_SSIZE_MIN);
63  return((ssize_t) value);
64 }
65 
66 static inline double DegreesToRadians(const double degrees)
67 {
68  return((double) (MagickPI*degrees/180.0));
69 }
70 
71 static inline size_t GetImageChannels(const Image *image)
72 {
73  ssize_t
74  i;
75 
76  size_t
77  channels;
78 
79  channels=0;
80  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
81  {
82  PixelChannel channel = GetPixelChannelChannel(image,i);
83  PixelTrait traits = GetPixelChannelTraits(image,channel);
84  if ((traits & UpdatePixelTrait) != 0)
85  channels++;
86  }
87  return(channels == 0 ? (size_t) 1 : channels);
88 }
89 
90 static inline double RadiansToDegrees(const double radians)
91 {
92  return((double) (180.0*radians/MagickPI));
93 }
94 
95 static inline unsigned char ScaleColor5to8(const unsigned int color)
96 {
97  return((unsigned char) (((color) << 3) | ((color) >> 2)));
98 }
99 
100 static inline unsigned char ScaleColor6to8(const unsigned int color)
101 {
102  return((unsigned char) (((color) << 2) | ((color) >> 4)));
103 }
104 
105 static inline unsigned int ScaleColor8to5(const unsigned char color)
106 {
107  return((unsigned int) (((color) & ~0x07) >> 3));
108 }
109 
110 static inline unsigned int ScaleColor8to6(const unsigned char color)
111 {
112  return((unsigned int) (((color) & ~0x03) >> 2));
113 }
114 
115 #if defined(__cplusplus) || defined(c_plusplus)
116 }
117 #endif
118 
119 #endif
static unsigned char ScaleColor6to8(const unsigned int color)
static unsigned char ScaleColor5to8(const unsigned int color)
Definition: image-private.h:95
#define MAGICK_SSIZE_MIN
Definition: studio.h:340
#define MAGICK_SSIZE_MAX
Definition: studio.h:339
static PixelTrait GetPixelChannelTraits(const Image *magick_restrict image, const PixelChannel channel)
#define MagickPI
Definition: image-private.h:42
Definition: image.h:151
static unsigned int ScaleColor8to6(const unsigned char color)
static double DegreesToRadians(const double degrees)
Definition: image-private.h:66
static unsigned int ScaleColor8to5(const unsigned char color)
PixelChannel
Definition: pixel.h:70
static size_t GetPixelChannels(const Image *magick_restrict image)
#define IsNaN(a)
Definition: magick-type.h:184
static ssize_t CastDoubleToLong(const double value)
Definition: image-private.h:55
static PixelChannel GetPixelChannelChannel(const Image *magick_restrict image, const ssize_t offset)
static double RadiansToDegrees(const double radians)
Definition: image-private.h:90
static size_t GetImageChannels(const Image *image)
Definition: image-private.h:71
PixelTrait
Definition: pixel.h:137