18#ifndef MAGICKCORE_QUANTUM_H
19#define MAGICKCORE_QUANTUM_H
22#include "MagickCore/image.h"
23#include "MagickCore/semaphore.h"
25#if defined(__cplusplus) || defined(c_plusplus)
38 UndefinedQuantumAlpha,
39 AssociatedQuantumAlpha,
40 DisassociatedQuantumAlpha
45 UndefinedQuantumFormat,
46 FloatingPointQuantumFormat,
86static inline Quantum ClampToQuantum(
const MagickRealType quantum)
88#if defined(MAGICKCORE_HDRI_SUPPORT)
89 return((Quantum) quantum);
91 if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
93 if (quantum >= (MagickRealType) QuantumRange)
95 return((Quantum) (quantum+0.5));
99#if (MAGICKCORE_QUANTUM_DEPTH == 8)
100static inline unsigned char ScaleQuantumToChar(
const Quantum quantum)
102#if !defined(MAGICKCORE_HDRI_SUPPORT)
103 return((
unsigned char) quantum);
105 if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
107 if (quantum >= 255.0)
109 return((
unsigned char) (quantum+0.5));
112#elif (MAGICKCORE_QUANTUM_DEPTH == 16)
113static inline unsigned char ScaleQuantumToChar(
const Quantum quantum)
115#if !defined(MAGICKCORE_HDRI_SUPPORT)
116 return((
unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8));
118 if ((IsNaN(quantum) != 0) || (quantum <= 0.0f))
120 if ((quantum/257.0f) >= 255.0f)
122 return((
unsigned char) (quantum/257.0f+0.5f));
125#elif (MAGICKCORE_QUANTUM_DEPTH == 32)
126static inline unsigned char ScaleQuantumToChar(
const Quantum quantum)
128#if !defined(MAGICKCORE_HDRI_SUPPORT)
129 return((
unsigned char) ((quantum+MagickULLConstant(8421504))/
130 MagickULLConstant(16843009)));
132 if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
134 if ((quantum/16843009.0) >= 255.0)
136 return((
unsigned char) (quantum/16843009.0+0.5));
139#elif (MAGICKCORE_QUANTUM_DEPTH == 64)
140static inline unsigned char ScaleQuantumToChar(
const Quantum quantum)
142#if !defined(MAGICKCORE_HDRI_SUPPORT)
143 return((
unsigned char) (quantum/72340172838076673.0+0.5));
145 if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
147 if ((quantum/72340172838076673.0) >= 255.0)
149 return((
unsigned char) (quantum/72340172838076673.0+0.5));
154extern MagickExport EndianType
157extern MagickExport MagickBooleanType
163extern MagickExport QuantumFormatType
170extern MagickExport QuantumType
173extern MagickExport
size_t
180extern MagickExport
unsigned char
183extern MagickExport
void
185 SetQuantumAlphaType(
QuantumInfo *,
const QuantumAlphaType),
186 SetQuantumImageType(
Image *,
const QuantumType),
187 SetQuantumMinIsWhite(
QuantumInfo *,
const MagickBooleanType),
188 SetQuantumPack(
QuantumInfo *,
const MagickBooleanType),
192#if defined(__cplusplus) || defined(c_plusplus)