blob: c0ab9a57b5751310aca688f7b1833ba49931d9af [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
Cristy7ce65e72015-12-12 18:03:16 -05002 Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization
cristy3ed852e2009-09-05 21:47:34 +00003 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
cristy6398ec72013-11-28 02:00:27 +000021#include "MagickCore/image.h"
22#include "MagickCore/semaphore.h"
23
cristy3ed852e2009-09-05 21:47:34 +000024#if defined(__cplusplus) || defined(c_plusplus)
25extern "C" {
26#endif
27
cristy3ed852e2009-09-05 21:47:34 +000028typedef enum
29{
30 UndefinedEndian,
31 LSBEndian,
32 MSBEndian
33} EndianType;
34
35typedef enum
36{
37 UndefinedQuantumAlpha,
38 AssociatedQuantumAlpha,
39 DisassociatedQuantumAlpha
40} QuantumAlphaType;
41
42typedef enum
43{
44 UndefinedQuantumFormat,
45 FloatingPointQuantumFormat,
46 SignedQuantumFormat,
cristyc9672a92010-01-06 00:57:45 +000047 UnsignedQuantumFormat
cristy3ed852e2009-09-05 21:47:34 +000048} QuantumFormatType;
49
50typedef enum
51{
52 UndefinedQuantum,
53 AlphaQuantum,
cristy4c08aed2011-07-01 19:47:50 +000054 BGRAQuantum,
55 BGROQuantum,
56 BGRQuantum,
cristy3ed852e2009-09-05 21:47:34 +000057 BlackQuantum,
58 BlueQuantum,
cristy4c08aed2011-07-01 19:47:50 +000059 CbYCrAQuantum,
60 CbYCrQuantum,
61 CbYCrYQuantum,
cristy3ed852e2009-09-05 21:47:34 +000062 CMYKAQuantum,
cristy4c08aed2011-07-01 19:47:50 +000063 CMYKOQuantum,
cristy3ed852e2009-09-05 21:47:34 +000064 CMYKQuantum,
65 CyanQuantum,
66 GrayAlphaQuantum,
67 GrayQuantum,
68 GreenQuantum,
69 IndexAlphaQuantum,
70 IndexQuantum,
71 MagentaQuantum,
72 OpacityQuantum,
73 RedQuantum,
74 RGBAQuantum,
cristy3ed852e2009-09-05 21:47:34 +000075 RGBOQuantum,
cristy3ed852e2009-09-05 21:47:34 +000076 RGBPadQuantum,
cristy4c08aed2011-07-01 19:47:50 +000077 RGBQuantum,
78 YellowQuantum
cristy3ed852e2009-09-05 21:47:34 +000079} QuantumType;
80
81typedef struct _QuantumInfo
82 QuantumInfo;
83
cristy82fb9212012-10-14 22:07:55 +000084static inline Quantum ClampToQuantum(const MagickRealType value)
cristy3ed852e2009-09-05 21:47:34 +000085{
cristye85007d2010-06-06 22:51:36 +000086#if defined(MAGICKCORE_HDRI_SUPPORT)
87 return((Quantum) value);
88#else
cristy82fb9212012-10-14 22:07:55 +000089 if (value <= 0.0f)
cristy3ed852e2009-09-05 21:47:34 +000090 return((Quantum) 0);
cristy82fb9212012-10-14 22:07:55 +000091 if (value >= (MagickRealType) QuantumRange)
cristy6e963d82012-06-19 15:23:24 +000092 return(QuantumRange);
cristy82fb9212012-10-14 22:07:55 +000093 return((Quantum) (value+0.5f));
cristy3ed852e2009-09-05 21:47:34 +000094#endif
95}
96
97#if (MAGICKCORE_QUANTUM_DEPTH == 8)
98static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
99{
100#if !defined(MAGICKCORE_HDRI_SUPPORT)
101 return((unsigned char) quantum);
102#else
103 if (quantum <= 0.0)
cristy4cfbb3f2010-03-14 20:40:23 +0000104 return(0);
cristy3ed852e2009-09-05 21:47:34 +0000105 if (quantum >= 255.0)
106 return(255);
107 return((unsigned char) (quantum+0.5));
108#endif
109}
110#elif (MAGICKCORE_QUANTUM_DEPTH == 16)
111static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
112{
113#if !defined(MAGICKCORE_HDRI_SUPPORT)
cristy45410e22010-06-09 02:43:31 +0000114 return((unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8));
cristy3ed852e2009-09-05 21:47:34 +0000115#else
116 if (quantum <= 0.0)
117 return(0);
cristycd817db2010-05-09 03:05:41 +0000118 if ((quantum/257.0) >= 255.0)
cristy3ed852e2009-09-05 21:47:34 +0000119 return(255);
cristycd817db2010-05-09 03:05:41 +0000120 return((unsigned char) (quantum/257.0+0.5));
cristy3ed852e2009-09-05 21:47:34 +0000121#endif
122}
123#elif (MAGICKCORE_QUANTUM_DEPTH == 32)
124static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
125{
126#if !defined(MAGICKCORE_HDRI_SUPPORT)
127 return((unsigned char) ((quantum+MagickULLConstant(8421504))/
128 MagickULLConstant(16843009)));
129#else
130 if (quantum <= 0.0)
131 return(0);
cristycd817db2010-05-09 03:05:41 +0000132 if ((quantum/16843009.0) >= 255.0)
cristy3ed852e2009-09-05 21:47:34 +0000133 return(255);
cristycd817db2010-05-09 03:05:41 +0000134 return((unsigned char) (quantum/16843009.0+0.5));
cristy3ed852e2009-09-05 21:47:34 +0000135#endif
136}
137#elif (MAGICKCORE_QUANTUM_DEPTH == 64)
138static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
139{
cristy8949e8e2010-05-11 01:46:22 +0000140#if !defined(MAGICKCORE_HDRI_SUPPORT)
cristy43513522010-05-11 13:46:36 +0000141 return((unsigned char) (quantum/72340172838076673.0+0.5));
cristy8949e8e2010-05-11 01:46:22 +0000142#else
143 if (quantum <= 0.0)
144 return(0);
cristy43513522010-05-11 13:46:36 +0000145 if ((quantum/72340172838076673.0) >= 255.0)
cristy8949e8e2010-05-11 01:46:22 +0000146 return(255);
cristy43513522010-05-11 13:46:36 +0000147 return((unsigned char) (quantum/72340172838076673.0+0.5));
cristy8949e8e2010-05-11 01:46:22 +0000148#endif
cristy3ed852e2009-09-05 21:47:34 +0000149}
150#endif
151
cristy9d4918b2012-11-14 20:18:32 +0000152extern MagickExport EndianType
153 GetQuantumEndian(const QuantumInfo *);
154
cristy3ed852e2009-09-05 21:47:34 +0000155extern MagickExport MagickBooleanType
cristybb503372010-05-27 20:51:26 +0000156 SetQuantumDepth(const Image *,QuantumInfo *,const size_t),
cristy9d4918b2012-11-14 20:18:32 +0000157 SetQuantumEndian(const Image *,QuantumInfo *,const EndianType),
cristy3ed852e2009-09-05 21:47:34 +0000158 SetQuantumFormat(const Image *,QuantumInfo *,const QuantumFormatType),
cristybb503372010-05-27 20:51:26 +0000159 SetQuantumPad(const Image *,QuantumInfo *,const size_t);
cristy3ed852e2009-09-05 21:47:34 +0000160
cristye11d00a2011-12-06 18:03:25 +0000161extern MagickExport QuantumFormatType
162 GetQuantumFormat(const QuantumInfo *);
163
cristy3ed852e2009-09-05 21:47:34 +0000164extern MagickExport QuantumInfo
cristy5f766ef2014-12-14 21:12:47 +0000165 *AcquireQuantumInfo(const ImageInfo *,Image *),
cristy3ed852e2009-09-05 21:47:34 +0000166 *DestroyQuantumInfo(QuantumInfo *);
167
168extern MagickExport QuantumType
169 GetQuantumType(Image *,ExceptionInfo *);
170
171extern MagickExport size_t
cristy71b27172012-01-13 00:21:44 +0000172 ExportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType,
dirk05d2ff72015-11-18 23:13:43 +0100173 unsigned char *magick_restrict,ExceptionInfo *),
cristy3ed852e2009-09-05 21:47:34 +0000174 GetQuantumExtent(const Image *,const QuantumInfo *,const QuantumType),
cristy71b27172012-01-13 00:21:44 +0000175 ImportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType,
dirk05d2ff72015-11-18 23:13:43 +0100176 const unsigned char *magick_restrict,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +0000177
cristyb1253cd2015-05-31 01:06:54 +0000178extern MagickExport unsigned char
179 *GetQuantumPixels(const QuantumInfo *);
180
cristy3ed852e2009-09-05 21:47:34 +0000181extern MagickExport void
182 GetQuantumInfo(const ImageInfo *,QuantumInfo *),
183 SetQuantumAlphaType(QuantumInfo *,const QuantumAlphaType),
184 SetQuantumImageType(Image *,const QuantumType),
185 SetQuantumMinIsWhite(QuantumInfo *,const MagickBooleanType),
186 SetQuantumPack(QuantumInfo *,const MagickBooleanType),
cristybb503372010-05-27 20:51:26 +0000187 SetQuantumQuantum(QuantumInfo *,const size_t),
cristy3ed852e2009-09-05 21:47:34 +0000188 SetQuantumScale(QuantumInfo *,const double);
189
190#if defined(__cplusplus) || defined(c_plusplus)
191}
192#endif
193
194#endif