MagickCore  7.1.0
Convert, Edit, Or Compose Bitmap Images
image-private.h
1 /*
2  Copyright @ 1999 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 
25 #include "MagickCore/pixel-accessor.h"
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 x)
56 {
57  if (IsNaN(x) != 0)
58  return(0);
59  if (x > ((double) MAGICK_SSIZE_MAX+0.5))
60  return((ssize_t) MAGICK_SSIZE_MAX);
61  if (x < ((double) MAGICK_SSIZE_MIN-0.5))
62  return((ssize_t) MAGICK_SSIZE_MIN);
63  if (x >= 0.0)
64  return((ssize_t) (x+0.5));
65  return((ssize_t) (x-0.5));
66 }
67 
68 static inline QuantumAny CastDoubleToQuantumAny(const double x)
69 {
70  if (IsNaN(x) != 0)
71  return(0);
72  if (x > ((double) ((QuantumAny) ~0)))
73  return((QuantumAny) ~0);
74  if (x < 0.0)
75  return((QuantumAny) 0);
76  return((QuantumAny) (x+0.5));
77 }
78 
79 static inline double DegreesToRadians(const double degrees)
80 {
81  return((double) (MagickPI*degrees/180.0));
82 }
83 
84 static inline size_t GetImageChannels(const Image *image)
85 {
86  ssize_t
87  i;
88 
89  size_t
90  channels;
91 
92  channels=0;
93  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
94  {
95  PixelChannel channel = GetPixelChannelChannel(image,i);
96  PixelTrait traits = GetPixelChannelTraits(image,channel);
97  if ((traits & UpdatePixelTrait) != 0)
98  channels++;
99  }
100  return(channels == 0 ? (size_t) 1 : channels);
101 }
102 
103 static inline double RadiansToDegrees(const double radians)
104 {
105  return((double) (180.0*radians/MagickPI));
106 }
107 
108 static inline unsigned char ScaleColor5to8(const unsigned int color)
109 {
110  return((unsigned char) (((color) << 3) | ((color) >> 2)));
111 }
112 
113 static inline unsigned char ScaleColor6to8(const unsigned int color)
114 {
115  return((unsigned char) (((color) << 2) | ((color) >> 4)));
116 }
117 
118 static inline unsigned int ScaleColor8to5(const unsigned char color)
119 {
120  return((unsigned int) (((color) & ~0x07) >> 3));
121 }
122 
123 static inline unsigned int ScaleColor8to6(const unsigned char color)
124 {
125  return((unsigned int) (((color) & ~0x03) >> 2));
126 }
127 
128 #if defined(__cplusplus) || defined(c_plusplus)
129 }
130 #endif
131 
132 #endif
Definition: image.h:152