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"
36 UndefinedQuantumAlpha,
37 AssociatedQuantumAlpha,
38 DisassociatedQuantumAlpha
43 UndefinedQuantumFormat,
44 FloatingPointQuantumFormat,
70 GrayPadQuantum, /* deprecated */
78 typedef struct _QuantumInfo
81 static inline Quantum RoundToQuantum(const MagickRealType value)
83 #if defined(MAGICKCORE_HDRI_SUPPORT)
84 return((Quantum) value);
88 if (value >= QuantumRange)
89 return((Quantum) QuantumRange);
90 return((Quantum) (value+0.5));
94 #if (MAGICKCORE_QUANTUM_DEPTH == 8)
95 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
97 #if !defined(MAGICKCORE_HDRI_SUPPORT)
98 return((unsigned char) quantum);
102 if (quantum >= 255.0)
104 return((unsigned char) (quantum+0.5));
107 #elif (MAGICKCORE_QUANTUM_DEPTH == 16)
108 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
110 #if !defined(MAGICKCORE_HDRI_SUPPORT)
111 return((unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8));
115 if ((quantum/257.0) >= 255.0)
117 return((unsigned char) (quantum/257.0+0.5));
120 #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
121 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
123 #if !defined(MAGICKCORE_HDRI_SUPPORT)
124 return((unsigned char) ((quantum+MagickULLConstant(8421504))/
125 MagickULLConstant(16843009)));
129 if ((quantum/16843009.0) >= 255.0)
131 return((unsigned char) (quantum/16843009.0+0.5));
134 #elif (MAGICKCORE_QUANTUM_DEPTH == 64)
135 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
137 #if !defined(MAGICKCORE_HDRI_SUPPORT)
138 return((unsigned char) ((quantum+2155839615.0)/71777214294589695.0));
140 return((unsigned char) (quantum/71777214294589695.0+0.5));
145 extern MagickExport MagickBooleanType
146 SetQuantumDepth(const Image *,QuantumInfo *,const unsigned long),
147 SetQuantumFormat(const Image *,QuantumInfo *,const QuantumFormatType),
148 SetQuantumPad(const Image *,QuantumInfo *,const unsigned long);
150 extern MagickExport QuantumInfo
151 *AcquireQuantumInfo(const ImageInfo *,Image *),
152 *DestroyQuantumInfo(QuantumInfo *);
154 extern MagickExport QuantumType
155 GetQuantumType(Image *,ExceptionInfo *);
157 extern MagickExport size_t
158 ExportQuantumPixels(const Image *,const CacheView *,const QuantumInfo *,
159 const QuantumType,unsigned char *,ExceptionInfo *),
160 GetQuantumExtent(const Image *,const QuantumInfo *,const QuantumType),
161 ImportQuantumPixels(Image *,CacheView *,const QuantumInfo *,const QuantumType,
162 const unsigned char *,ExceptionInfo *);
164 extern MagickExport unsigned char
165 *GetQuantumPixels(const QuantumInfo *);
167 extern MagickExport void
168 GetQuantumInfo(const ImageInfo *,QuantumInfo *),
169 SetQuantumAlphaType(QuantumInfo *,const QuantumAlphaType),
170 SetQuantumImageType(Image *,const QuantumType),
171 SetQuantumMinIsWhite(QuantumInfo *,const MagickBooleanType),
172 SetQuantumPack(QuantumInfo *,const MagickBooleanType),
173 SetQuantumQuantum(QuantumInfo *,const unsigned long),
174 SetQuantumScale(QuantumInfo *,const double);
176 #if defined(__cplusplus) || defined(c_plusplus)