2 Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization
3 dedicated to making software imaging solutions freely available.
5 You may not use this file except in compliance with the License.
6 obtain a copy of the License at
8 http://www.imagemagick.org/script/license.php
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.
16 MagickCore quantum inline methods.
18 #ifndef _MAGICKCORE_QUANTUM_H
19 #define _MAGICKCORE_QUANTUM_H
21 #if defined(__cplusplus) || defined(c_plusplus)
25 #include "magick/semaphore.h"
27 #define RoundToQuantum(quantum) ClampToQuantum(quantum)
38 UndefinedQuantumAlpha,
39 AssociatedQuantumAlpha,
40 DisassociatedQuantumAlpha
45 UndefinedQuantumFormat,
46 FloatingPointQuantumFormat,
73 GrayPadQuantum, /* deprecated */
83 typedef struct _QuantumInfo
86 static inline Quantum ClampToQuantum(const MagickRealType value)
88 #if defined(MAGICKCORE_HDRI_SUPPORT)
89 return((Quantum) value);
93 if (value >= (MagickRealType) QuantumRange)
94 return((Quantum) QuantumRange);
95 return((Quantum) (value+0.5));
99 #if (MAGICKCORE_QUANTUM_DEPTH == 8)
100 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
102 #if !defined(MAGICKCORE_HDRI_SUPPORT)
103 return((unsigned char) quantum);
107 if (quantum >= 255.0)
109 return((unsigned char) (quantum+0.5));
112 #elif (MAGICKCORE_QUANTUM_DEPTH == 16)
113 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
115 #if !defined(MAGICKCORE_HDRI_SUPPORT)
116 return((unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8));
120 if ((quantum/257.0) >= 255.0)
122 return((unsigned char) (quantum/257.0+0.5));
125 #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
126 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
128 #if !defined(MAGICKCORE_HDRI_SUPPORT)
129 return((unsigned char) ((quantum+MagickULLConstant(8421504))/
130 MagickULLConstant(16843009)));
134 if ((quantum/16843009.0) >= 255.0)
136 return((unsigned char) (quantum/16843009.0+0.5));
139 #elif (MAGICKCORE_QUANTUM_DEPTH == 64)
140 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
142 #if !defined(MAGICKCORE_HDRI_SUPPORT)
143 return((unsigned char) (quantum/72340172838076673.0+0.5));
147 if ((quantum/72340172838076673.0) >= 255.0)
149 return((unsigned char) (quantum/72340172838076673.0+0.5));
154 extern MagickExport MagickBooleanType
155 SetQuantumDepth(const Image *,QuantumInfo *,const size_t),
156 SetQuantumFormat(const Image *,QuantumInfo *,const QuantumFormatType),
157 SetQuantumPad(const Image *,QuantumInfo *,const size_t);
159 extern MagickExport QuantumInfo
160 *AcquireQuantumInfo(const ImageInfo *,Image *),
161 *DestroyQuantumInfo(QuantumInfo *);
163 extern MagickExport QuantumType
164 GetQuantumType(Image *,ExceptionInfo *);
166 extern MagickExport size_t
167 ExportQuantumPixels(const Image *,const CacheView *,const QuantumInfo *,
168 const QuantumType,unsigned char *,ExceptionInfo *),
169 GetQuantumExtent(const Image *,const QuantumInfo *,const QuantumType),
170 ImportQuantumPixels(Image *,CacheView *,const QuantumInfo *,const QuantumType,
171 const unsigned char *,ExceptionInfo *);
173 extern MagickExport unsigned char
174 *GetQuantumPixels(const QuantumInfo *);
176 extern MagickExport void
177 GetQuantumInfo(const ImageInfo *,QuantumInfo *),
178 SetQuantumAlphaType(QuantumInfo *,const QuantumAlphaType),
179 SetQuantumImageType(Image *,const QuantumType),
180 SetQuantumMinIsWhite(QuantumInfo *,const MagickBooleanType),
181 SetQuantumPack(QuantumInfo *,const MagickBooleanType),
182 SetQuantumQuantum(QuantumInfo *,const size_t),
183 SetQuantumScale(QuantumInfo *,const double);
185 #if defined(__cplusplus) || defined(c_plusplus)