blob: 5c6b898525d8eb7364dfbea455527924467aab7d [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2 Copyright 1999-2008 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.
6 obtain a copy of the License at
7
8 http://www.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#if defined(__cplusplus) || defined(c_plusplus)
22extern "C" {
23#endif
24
cristy4c08aed2011-07-01 19:47:50 +000025#include "MagickCore/semaphore.h"
cristy3ed852e2009-09-05 21:47:34 +000026
cristyce70c172010-01-07 17:15:30 +000027#define RoundToQuantum(quantum) ClampToQuantum(quantum)
28
cristy3ed852e2009-09-05 21:47:34 +000029typedef enum
30{
31 UndefinedEndian,
32 LSBEndian,
33 MSBEndian
34} EndianType;
35
36typedef enum
37{
38 UndefinedQuantumAlpha,
39 AssociatedQuantumAlpha,
40 DisassociatedQuantumAlpha
41} QuantumAlphaType;
42
43typedef enum
44{
45 UndefinedQuantumFormat,
46 FloatingPointQuantumFormat,
47 SignedQuantumFormat,
cristyc9672a92010-01-06 00:57:45 +000048 UnsignedQuantumFormat
cristy3ed852e2009-09-05 21:47:34 +000049} QuantumFormatType;
50
51typedef enum
52{
53 UndefinedQuantum,
54 AlphaQuantum,
cristy4c08aed2011-07-01 19:47:50 +000055 BGRAQuantum,
56 BGROQuantum,
57 BGRQuantum,
cristy3ed852e2009-09-05 21:47:34 +000058 BlackQuantum,
59 BlueQuantum,
cristy4c08aed2011-07-01 19:47:50 +000060 CbYCrAQuantum,
61 CbYCrQuantum,
62 CbYCrYQuantum,
cristy3ed852e2009-09-05 21:47:34 +000063 CMYKAQuantum,
cristy4c08aed2011-07-01 19:47:50 +000064 CMYKOQuantum,
cristy3ed852e2009-09-05 21:47:34 +000065 CMYKQuantum,
66 CyanQuantum,
67 GrayAlphaQuantum,
68 GrayQuantum,
69 GreenQuantum,
70 IndexAlphaQuantum,
71 IndexQuantum,
72 MagentaQuantum,
73 OpacityQuantum,
74 RedQuantum,
75 RGBAQuantum,
cristy3ed852e2009-09-05 21:47:34 +000076 RGBOQuantum,
cristy3ed852e2009-09-05 21:47:34 +000077 RGBPadQuantum,
cristy4c08aed2011-07-01 19:47:50 +000078 RGBQuantum,
79 YellowQuantum
cristy3ed852e2009-09-05 21:47:34 +000080} QuantumType;
81
82typedef struct _QuantumInfo
83 QuantumInfo;
84
cristyce70c172010-01-07 17:15:30 +000085static inline Quantum ClampToQuantum(const MagickRealType value)
cristy3ed852e2009-09-05 21:47:34 +000086{
cristye85007d2010-06-06 22:51:36 +000087#if defined(MAGICKCORE_HDRI_SUPPORT)
88 return((Quantum) value);
89#else
cristy3ed852e2009-09-05 21:47:34 +000090 if (value <= 0.0)
91 return((Quantum) 0);
cristyeaa75332010-01-09 16:47:14 +000092 if (value >= (MagickRealType) QuantumRange)
cristy3ed852e2009-09-05 21:47:34 +000093 return((Quantum) QuantumRange);
cristyed5f0022010-05-10 00:28:28 +000094 return((Quantum) (value+0.5));
cristy3ed852e2009-09-05 21:47:34 +000095#endif
96}
97
98#if (MAGICKCORE_QUANTUM_DEPTH == 8)
99static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
100{
101#if !defined(MAGICKCORE_HDRI_SUPPORT)
102 return((unsigned char) quantum);
103#else
104 if (quantum <= 0.0)
cristy4cfbb3f2010-03-14 20:40:23 +0000105 return(0);
cristy3ed852e2009-09-05 21:47:34 +0000106 if (quantum >= 255.0)
107 return(255);
108 return((unsigned char) (quantum+0.5));
109#endif
110}
111#elif (MAGICKCORE_QUANTUM_DEPTH == 16)
112static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
113{
114#if !defined(MAGICKCORE_HDRI_SUPPORT)
cristy45410e22010-06-09 02:43:31 +0000115 return((unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8));
cristy3ed852e2009-09-05 21:47:34 +0000116#else
117 if (quantum <= 0.0)
118 return(0);
cristycd817db2010-05-09 03:05:41 +0000119 if ((quantum/257.0) >= 255.0)
cristy3ed852e2009-09-05 21:47:34 +0000120 return(255);
cristycd817db2010-05-09 03:05:41 +0000121 return((unsigned char) (quantum/257.0+0.5));
cristy3ed852e2009-09-05 21:47:34 +0000122#endif
123}
124#elif (MAGICKCORE_QUANTUM_DEPTH == 32)
125static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
126{
127#if !defined(MAGICKCORE_HDRI_SUPPORT)
128 return((unsigned char) ((quantum+MagickULLConstant(8421504))/
129 MagickULLConstant(16843009)));
130#else
131 if (quantum <= 0.0)
132 return(0);
cristycd817db2010-05-09 03:05:41 +0000133 if ((quantum/16843009.0) >= 255.0)
cristy3ed852e2009-09-05 21:47:34 +0000134 return(255);
cristycd817db2010-05-09 03:05:41 +0000135 return((unsigned char) (quantum/16843009.0+0.5));
cristy3ed852e2009-09-05 21:47:34 +0000136#endif
137}
138#elif (MAGICKCORE_QUANTUM_DEPTH == 64)
139static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
140{
cristy8949e8e2010-05-11 01:46:22 +0000141#if !defined(MAGICKCORE_HDRI_SUPPORT)
cristy43513522010-05-11 13:46:36 +0000142 return((unsigned char) (quantum/72340172838076673.0+0.5));
cristy8949e8e2010-05-11 01:46:22 +0000143#else
144 if (quantum <= 0.0)
145 return(0);
cristy43513522010-05-11 13:46:36 +0000146 if ((quantum/72340172838076673.0) >= 255.0)
cristy8949e8e2010-05-11 01:46:22 +0000147 return(255);
cristy43513522010-05-11 13:46:36 +0000148 return((unsigned char) (quantum/72340172838076673.0+0.5));
cristy8949e8e2010-05-11 01:46:22 +0000149#endif
cristy3ed852e2009-09-05 21:47:34 +0000150}
151#endif
152
153extern MagickExport MagickBooleanType
cristybb503372010-05-27 20:51:26 +0000154 SetQuantumDepth(const Image *,QuantumInfo *,const size_t),
cristy3ed852e2009-09-05 21:47:34 +0000155 SetQuantumFormat(const Image *,QuantumInfo *,const QuantumFormatType),
cristybb503372010-05-27 20:51:26 +0000156 SetQuantumPad(const Image *,QuantumInfo *,const size_t);
cristy3ed852e2009-09-05 21:47:34 +0000157
158extern MagickExport QuantumInfo
159 *AcquireQuantumInfo(const ImageInfo *,Image *),
160 *DestroyQuantumInfo(QuantumInfo *);
161
162extern MagickExport QuantumType
163 GetQuantumType(Image *,ExceptionInfo *);
164
165extern MagickExport size_t
cristy4c08aed2011-07-01 19:47:50 +0000166 ExportQuantumPixels(Image *,CacheView *,const QuantumInfo *,const QuantumType,
167 unsigned char *,ExceptionInfo *),
cristy3ed852e2009-09-05 21:47:34 +0000168 GetQuantumExtent(const Image *,const QuantumInfo *,const QuantumType),
169 ImportQuantumPixels(Image *,CacheView *,const QuantumInfo *,const QuantumType,
170 const unsigned char *,ExceptionInfo *);
171
172extern MagickExport unsigned char
173 *GetQuantumPixels(const QuantumInfo *);
174
175extern MagickExport void
176 GetQuantumInfo(const ImageInfo *,QuantumInfo *),
177 SetQuantumAlphaType(QuantumInfo *,const QuantumAlphaType),
178 SetQuantumImageType(Image *,const QuantumType),
179 SetQuantumMinIsWhite(QuantumInfo *,const MagickBooleanType),
180 SetQuantumPack(QuantumInfo *,const MagickBooleanType),
cristybb503372010-05-27 20:51:26 +0000181 SetQuantumQuantum(QuantumInfo *,const size_t),
cristy3ed852e2009-09-05 21:47:34 +0000182 SetQuantumScale(QuantumInfo *,const double);
183
184#if defined(__cplusplus) || defined(c_plusplus)
185}
186#endif
187
188#endif