blob: 232089775e4e152d29ad497a883cdf61b81a8730 [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
27typedef enum
28{
29 UndefinedEndian,
30 LSBEndian,
31 MSBEndian
32} EndianType;
33
34typedef enum
35{
36 UndefinedQuantumAlpha,
37 AssociatedQuantumAlpha,
38 DisassociatedQuantumAlpha
39} QuantumAlphaType;
40
41typedef enum
42{
43 UndefinedQuantumFormat,
44 FloatingPointQuantumFormat,
45 SignedQuantumFormat,
cristyc9672a92010-01-06 00:57:45 +000046 UnsignedQuantumFormat
cristy3ed852e2009-09-05 21:47:34 +000047} QuantumFormatType;
48
49typedef enum
50{
51 UndefinedQuantum,
52 AlphaQuantum,
cristy4c08aed2011-07-01 19:47:50 +000053 BGRAQuantum,
54 BGROQuantum,
55 BGRQuantum,
cristy3ed852e2009-09-05 21:47:34 +000056 BlackQuantum,
57 BlueQuantum,
cristy4c08aed2011-07-01 19:47:50 +000058 CbYCrAQuantum,
59 CbYCrQuantum,
60 CbYCrYQuantum,
cristy3ed852e2009-09-05 21:47:34 +000061 CMYKAQuantum,
cristy4c08aed2011-07-01 19:47:50 +000062 CMYKOQuantum,
cristy3ed852e2009-09-05 21:47:34 +000063 CMYKQuantum,
64 CyanQuantum,
65 GrayAlphaQuantum,
66 GrayQuantum,
67 GreenQuantum,
68 IndexAlphaQuantum,
69 IndexQuantum,
70 MagentaQuantum,
71 OpacityQuantum,
72 RedQuantum,
73 RGBAQuantum,
cristy3ed852e2009-09-05 21:47:34 +000074 RGBOQuantum,
cristy3ed852e2009-09-05 21:47:34 +000075 RGBPadQuantum,
cristy4c08aed2011-07-01 19:47:50 +000076 RGBQuantum,
77 YellowQuantum
cristy3ed852e2009-09-05 21:47:34 +000078} QuantumType;
79
80typedef struct _QuantumInfo
81 QuantumInfo;
82
cristy82fb9212012-10-14 22:07:55 +000083static inline Quantum ClampToQuantum(const MagickRealType value)
cristy3ed852e2009-09-05 21:47:34 +000084{
cristye85007d2010-06-06 22:51:36 +000085#if defined(MAGICKCORE_HDRI_SUPPORT)
86 return((Quantum) value);
87#else
cristy82fb9212012-10-14 22:07:55 +000088 if (value <= 0.0f)
cristy3ed852e2009-09-05 21:47:34 +000089 return((Quantum) 0);
cristy82fb9212012-10-14 22:07:55 +000090 if (value >= (MagickRealType) QuantumRange)
cristy6e963d82012-06-19 15:23:24 +000091 return(QuantumRange);
cristy82fb9212012-10-14 22:07:55 +000092 return((Quantum) (value+0.5f));
cristy3ed852e2009-09-05 21:47:34 +000093#endif
94}
95
96#if (MAGICKCORE_QUANTUM_DEPTH == 8)
97static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
98{
99#if !defined(MAGICKCORE_HDRI_SUPPORT)
100 return((unsigned char) quantum);
101#else
102 if (quantum <= 0.0)
cristy4cfbb3f2010-03-14 20:40:23 +0000103 return(0);
cristy3ed852e2009-09-05 21:47:34 +0000104 if (quantum >= 255.0)
105 return(255);
106 return((unsigned char) (quantum+0.5));
107#endif
108}
109#elif (MAGICKCORE_QUANTUM_DEPTH == 16)
110static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
111{
112#if !defined(MAGICKCORE_HDRI_SUPPORT)
cristy45410e22010-06-09 02:43:31 +0000113 return((unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8));
cristy3ed852e2009-09-05 21:47:34 +0000114#else
115 if (quantum <= 0.0)
116 return(0);
cristycd817db2010-05-09 03:05:41 +0000117 if ((quantum/257.0) >= 255.0)
cristy3ed852e2009-09-05 21:47:34 +0000118 return(255);
cristycd817db2010-05-09 03:05:41 +0000119 return((unsigned char) (quantum/257.0+0.5));
cristy3ed852e2009-09-05 21:47:34 +0000120#endif
121}
122#elif (MAGICKCORE_QUANTUM_DEPTH == 32)
123static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
124{
125#if !defined(MAGICKCORE_HDRI_SUPPORT)
126 return((unsigned char) ((quantum+MagickULLConstant(8421504))/
127 MagickULLConstant(16843009)));
128#else
129 if (quantum <= 0.0)
130 return(0);
cristycd817db2010-05-09 03:05:41 +0000131 if ((quantum/16843009.0) >= 255.0)
cristy3ed852e2009-09-05 21:47:34 +0000132 return(255);
cristycd817db2010-05-09 03:05:41 +0000133 return((unsigned char) (quantum/16843009.0+0.5));
cristy3ed852e2009-09-05 21:47:34 +0000134#endif
135}
136#elif (MAGICKCORE_QUANTUM_DEPTH == 64)
137static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
138{
cristy8949e8e2010-05-11 01:46:22 +0000139#if !defined(MAGICKCORE_HDRI_SUPPORT)
cristy43513522010-05-11 13:46:36 +0000140 return((unsigned char) (quantum/72340172838076673.0+0.5));
cristy8949e8e2010-05-11 01:46:22 +0000141#else
142 if (quantum <= 0.0)
143 return(0);
cristy43513522010-05-11 13:46:36 +0000144 if ((quantum/72340172838076673.0) >= 255.0)
cristy8949e8e2010-05-11 01:46:22 +0000145 return(255);
cristy43513522010-05-11 13:46:36 +0000146 return((unsigned char) (quantum/72340172838076673.0+0.5));
cristy8949e8e2010-05-11 01:46:22 +0000147#endif
cristy3ed852e2009-09-05 21:47:34 +0000148}
149#endif
150
151extern MagickExport MagickBooleanType
cristybb503372010-05-27 20:51:26 +0000152 SetQuantumDepth(const Image *,QuantumInfo *,const size_t),
cristy3ed852e2009-09-05 21:47:34 +0000153 SetQuantumFormat(const Image *,QuantumInfo *,const QuantumFormatType),
cristybb503372010-05-27 20:51:26 +0000154 SetQuantumPad(const Image *,QuantumInfo *,const size_t);
cristy3ed852e2009-09-05 21:47:34 +0000155
cristye11d00a2011-12-06 18:03:25 +0000156extern MagickExport QuantumFormatType
157 GetQuantumFormat(const QuantumInfo *);
158
cristy3ed852e2009-09-05 21:47:34 +0000159extern MagickExport QuantumInfo
160 *AcquireQuantumInfo(const ImageInfo *,Image *),
161 *DestroyQuantumInfo(QuantumInfo *);
162
163extern MagickExport QuantumType
164 GetQuantumType(Image *,ExceptionInfo *);
165
166extern MagickExport size_t
cristy71b27172012-01-13 00:21:44 +0000167 ExportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType,
cristy4c08aed2011-07-01 19:47:50 +0000168 unsigned char *,ExceptionInfo *),
cristy3ed852e2009-09-05 21:47:34 +0000169 GetQuantumExtent(const Image *,const QuantumInfo *,const QuantumType),
cristy71b27172012-01-13 00:21:44 +0000170 ImportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType,
cristy3ed852e2009-09-05 21:47:34 +0000171 const unsigned char *,ExceptionInfo *);
172
173extern MagickExport unsigned char
174 *GetQuantumPixels(const QuantumInfo *);
175
176extern 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),
cristybb503372010-05-27 20:51:26 +0000182 SetQuantumQuantum(QuantumInfo *,const size_t),
cristy3ed852e2009-09-05 21:47:34 +0000183 SetQuantumScale(QuantumInfo *,const double);
184
185#if defined(__cplusplus) || defined(c_plusplus)
186}
187#endif
188
189#endif