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 "MagickCore/semaphore.h"
27 #define RoundToQuantum(quantum) ClampToQuantum(quantum)
38 UndefinedQuantumAlpha,
39 AssociatedQuantumAlpha,
40 DisassociatedQuantumAlpha
45 UndefinedQuantumFormat,
46 FloatingPointQuantumFormat,
82 typedef struct _QuantumInfo
85 static inline Quantum ClampToQuantum(const double value)
87 #if defined(MAGICKCORE_HDRI_SUPPORT)
88 return((Quantum) value);
92 if (value >= (double) QuantumRange)
93 return((Quantum) QuantumRange);
94 return((Quantum) (value+0.5));
98 #if (MAGICKCORE_QUANTUM_DEPTH == 8)
99 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
101 #if !defined(MAGICKCORE_HDRI_SUPPORT)
102 return((unsigned char) quantum);
106 if (quantum >= 255.0)
108 return((unsigned char) (quantum+0.5));
111 #elif (MAGICKCORE_QUANTUM_DEPTH == 16)
112 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
114 #if !defined(MAGICKCORE_HDRI_SUPPORT)
115 return((unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8));
119 if ((quantum/257.0) >= 255.0)
121 return((unsigned char) (quantum/257.0+0.5));
124 #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
125 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
127 #if !defined(MAGICKCORE_HDRI_SUPPORT)
128 return((unsigned char) ((quantum+MagickULLConstant(8421504))/
129 MagickULLConstant(16843009)));
133 if ((quantum/16843009.0) >= 255.0)
135 return((unsigned char) (quantum/16843009.0+0.5));
138 #elif (MAGICKCORE_QUANTUM_DEPTH == 64)
139 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
141 #if !defined(MAGICKCORE_HDRI_SUPPORT)
142 return((unsigned char) (quantum/72340172838076673.0+0.5));
146 if ((quantum/72340172838076673.0) >= 255.0)
148 return((unsigned char) (quantum/72340172838076673.0+0.5));
153 extern MagickExport MagickBooleanType
154 SetQuantumDepth(const Image *,QuantumInfo *,const size_t),
155 SetQuantumFormat(const Image *,QuantumInfo *,const QuantumFormatType),
156 SetQuantumPad(const Image *,QuantumInfo *,const size_t);
158 extern MagickExport QuantumFormatType
159 GetQuantumFormat(const QuantumInfo *);
161 extern MagickExport QuantumInfo
162 *AcquireQuantumInfo(const ImageInfo *,Image *),
163 *DestroyQuantumInfo(QuantumInfo *);
165 extern MagickExport QuantumType
166 GetQuantumType(Image *,ExceptionInfo *);
168 extern MagickExport size_t
169 ExportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType,
170 unsigned char *,ExceptionInfo *),
171 GetQuantumExtent(const Image *,const QuantumInfo *,const QuantumType),
172 ImportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType,
173 const unsigned char *,ExceptionInfo *);
175 extern MagickExport unsigned char
176 *GetQuantumPixels(const QuantumInfo *);
178 extern MagickExport void
179 GetQuantumInfo(const ImageInfo *,QuantumInfo *),
180 SetQuantumAlphaType(QuantumInfo *,const QuantumAlphaType),
181 SetQuantumImageType(Image *,const QuantumType),
182 SetQuantumMinIsWhite(QuantumInfo *,const MagickBooleanType),
183 SetQuantumPack(QuantumInfo *,const MagickBooleanType),
184 SetQuantumQuantum(QuantumInfo *,const size_t),
185 SetQuantumScale(QuantumInfo *,const double);
187 #if defined(__cplusplus) || defined(c_plusplus)