MagickCore  7.1.0
Convert, Edit, Or Compose Bitmap Images
quantum.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 quantum inline methods.
17 */
18 #ifndef MAGICKCORE_QUANTUM_H
19 #define MAGICKCORE_QUANTUM_H
20 
21 #include <float.h>
22 #include "MagickCore/image.h"
23 #include "MagickCore/semaphore.h"
24 
25 #if defined(__cplusplus) || defined(c_plusplus)
26 extern "C" {
27 #endif
28 
29 typedef enum
30 {
31  UndefinedEndian,
32  LSBEndian,
33  MSBEndian
34 } EndianType;
35 
36 typedef enum
37 {
38  UndefinedQuantumAlpha,
39  AssociatedQuantumAlpha,
40  DisassociatedQuantumAlpha
41 } QuantumAlphaType;
42 
43 typedef enum
44 {
45  UndefinedQuantumFormat,
46  FloatingPointQuantumFormat,
47  SignedQuantumFormat,
48  UnsignedQuantumFormat
49 } QuantumFormatType;
50 
51 typedef enum
52 {
53  UndefinedQuantum,
54  AlphaQuantum,
55  BGRAQuantum,
56  BGROQuantum,
57  BGRQuantum,
58  BlackQuantum,
59  BlueQuantum,
60  CbYCrAQuantum,
61  CbYCrQuantum,
62  CbYCrYQuantum,
63  CMYKAQuantum,
64  CMYKOQuantum,
65  CMYKQuantum,
66  CyanQuantum,
67  GrayAlphaQuantum,
68  GrayQuantum,
69  GreenQuantum,
70  IndexAlphaQuantum,
71  IndexQuantum,
72  MagentaQuantum,
73  OpacityQuantum,
74  RedQuantum,
75  RGBAQuantum,
76  RGBOQuantum,
77  RGBPadQuantum,
78  RGBQuantum,
79  YellowQuantum,
80  MultispectralQuantum
81 } QuantumType;
82 
83 typedef struct _QuantumInfo
85 
86 static inline Quantum ClampToQuantum(const MagickRealType quantum)
87 {
88 #if defined(MAGICKCORE_HDRI_SUPPORT)
89  return((Quantum) quantum);
90 #else
91  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
92  return((Quantum) 0);
93  if (quantum >= (MagickRealType) QuantumRange)
94  return(QuantumRange);
95  return((Quantum) (quantum+0.5));
96 #endif
97 }
98 
99 #if (MAGICKCORE_QUANTUM_DEPTH == 8)
100 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
101 {
102 #if !defined(MAGICKCORE_HDRI_SUPPORT)
103  return((unsigned char) quantum);
104 #else
105  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
106  return(0);
107  if (quantum >= 255.0)
108  return(255);
109  return((unsigned char) (quantum+0.5));
110 #endif
111 }
112 #elif (MAGICKCORE_QUANTUM_DEPTH == 16)
113 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
114 {
115 #if !defined(MAGICKCORE_HDRI_SUPPORT)
116  return((unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8));
117 #else
118  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
119  return(0);
120  if ((quantum/257.0) >= 255.0)
121  return(255);
122  return((unsigned char) (quantum/257.0+0.5));
123 #endif
124 }
125 #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
126 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
127 {
128 #if !defined(MAGICKCORE_HDRI_SUPPORT)
129  return((unsigned char) ((quantum+MagickULLConstant(8421504))/
130  MagickULLConstant(16843009)));
131 #else
132  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
133  return(0);
134  if ((quantum/16843009.0) >= 255.0)
135  return(255);
136  return((unsigned char) (quantum/16843009.0+0.5));
137 #endif
138 }
139 #elif (MAGICKCORE_QUANTUM_DEPTH == 64)
140 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
141 {
142 #if !defined(MAGICKCORE_HDRI_SUPPORT)
143  return((unsigned char) (quantum/72340172838076673.0+0.5));
144 #else
145  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
146  return(0);
147  if ((quantum/72340172838076673.0) >= 255.0)
148  return(255);
149  return((unsigned char) (quantum/72340172838076673.0+0.5));
150 #endif
151 }
152 #endif
153 
154 extern MagickExport EndianType
155  GetQuantumEndian(const QuantumInfo *);
156 
157 extern MagickExport MagickBooleanType
158  SetQuantumDepth(const Image *,QuantumInfo *,const size_t),
159  SetQuantumEndian(const Image *,QuantumInfo *,const EndianType),
160  SetQuantumFormat(const Image *,QuantumInfo *,const QuantumFormatType),
161  SetQuantumPad(const Image *,QuantumInfo *,const size_t);
162 
163 extern MagickExport QuantumFormatType
164  GetQuantumFormat(const QuantumInfo *);
165 
166 extern MagickExport QuantumInfo
167  *AcquireQuantumInfo(const ImageInfo *,Image *),
168  *DestroyQuantumInfo(QuantumInfo *);
169 
170 extern MagickExport QuantumType
171  GetQuantumType(Image *,ExceptionInfo *);
172 
173 extern MagickExport size_t
174  ExportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType,
175  unsigned char *magick_restrict,ExceptionInfo *),
176  GetQuantumExtent(const Image *,const QuantumInfo *,const QuantumType),
177  ImportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType,
178  const unsigned char *magick_restrict,ExceptionInfo *);
179 
180 extern MagickExport unsigned char
181  *GetQuantumPixels(const QuantumInfo *);
182 
183 extern MagickExport void
184  GetQuantumInfo(const ImageInfo *,QuantumInfo *),
185  SetQuantumAlphaType(QuantumInfo *,const QuantumAlphaType),
186  SetQuantumImageType(Image *,const QuantumType),
187  SetQuantumMinIsWhite(QuantumInfo *,const MagickBooleanType),
188  SetQuantumPack(QuantumInfo *,const MagickBooleanType),
189  SetQuantumQuantum(QuantumInfo *,const size_t),
190  SetQuantumScale(QuantumInfo *,const double);
191 
192 #if defined(__cplusplus) || defined(c_plusplus)
193 }
194 #endif
195 
196 #endif
Definition: image.h:152