]> granicus.if.org Git - imagemagick/blob - magick/quantum.h
(no commit message)
[imagemagick] / magick / quantum.h
1 /*
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)
22 extern "C" {
23 #endif
24
25 #include "magick/semaphore.h"
26
27 #define RoundToQuantum(quantum)  ClampToQuantum(quantum)
28
29 typedef enum
30 {
31   UndefinedEndian,
32   LSBEndian,
33   MSBEndian
34 } EndianType;
35
36 typedef enum
37 {
38   UndefinedQuantumAlpha,
39   AssociatedQuantumAlpha,
40   DisassociatedQuantumAlpha
41 } QuantumAlphaType;
42
43 typedef enum
44 {
45   UndefinedQuantumFormat,
46   FloatingPointQuantumFormat,
47   SignedQuantumFormat,
48   UnsignedQuantumFormat
49 } QuantumFormatType;
50
51 typedef enum
52 {
53   UndefinedQuantum,
54   AlphaQuantum,
55   BlackQuantum,
56   BlueQuantum,
57   CMYKAQuantum,
58   CMYKQuantum,
59   CyanQuantum,
60   GrayAlphaQuantum,
61   GrayQuantum,
62   GreenQuantum,
63   IndexAlphaQuantum,
64   IndexQuantum,
65   MagentaQuantum,
66   OpacityQuantum,
67   RedQuantum,
68   RGBAQuantum,
69   BGRAQuantum,
70   RGBOQuantum,
71   RGBQuantum,
72   YellowQuantum,
73   GrayPadQuantum,  /* deprecated */
74   RGBPadQuantum,
75   CbYCrYQuantum,
76   CbYCrQuantum,
77   CbYCrAQuantum,
78   CMYKOQuantum,
79   BGRQuantum,
80   BGROQuantum
81 } QuantumType;
82
83 typedef struct _QuantumInfo
84   QuantumInfo;
85
86 static inline Quantum ClampToQuantum(const MagickRealType value)
87 {
88 #if defined(MAGICKCORE_HDRI_SUPPORT)
89   return((Quantum) value);
90 #else
91   if (value <= 0.0)
92     return((Quantum) 0);
93   if (value >= (MagickRealType) QuantumRange)
94     return((Quantum) QuantumRange);
95   return((Quantum) (value+0.5));
96 #endif
97 }
98
99 #if (MAGICKCORE_QUANTUM_DEPTH == 8)
100 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
101 {
102 #if !defined(MAGICKCORE_HDRI_SUPPORT)
103   return((unsigned char) quantum);
104 #else
105   if (quantum <= 0.0)
106     return(0);
107   if (quantum >= 255.0)
108     return(255);
109   return((unsigned char) (quantum+0.5));
110 #endif
111 }
112 #elif (MAGICKCORE_QUANTUM_DEPTH == 16)
113 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
114 {
115 #if !defined(MAGICKCORE_HDRI_SUPPORT)
116   return((unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8));
117 #else
118   if (quantum <= 0.0)
119     return(0);
120   if ((quantum/257.0) >= 255.0)
121     return(255);
122   return((unsigned char) (quantum/257.0+0.5));
123 #endif
124 }
125 #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
126 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
127 {
128 #if !defined(MAGICKCORE_HDRI_SUPPORT)
129   return((unsigned char) ((quantum+MagickULLConstant(8421504))/
130     MagickULLConstant(16843009)));
131 #else
132   if (quantum <= 0.0)
133     return(0);
134   if ((quantum/16843009.0) >= 255.0)
135     return(255);
136   return((unsigned char) (quantum/16843009.0+0.5));
137 #endif
138 }
139 #elif (MAGICKCORE_QUANTUM_DEPTH == 64)
140 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
141 {
142 #if !defined(MAGICKCORE_HDRI_SUPPORT)
143   return((unsigned char) (quantum/72340172838076673.0+0.5));
144 #else
145   if (quantum <= 0.0)
146     return(0);
147   if ((quantum/72340172838076673.0) >= 255.0)
148     return(255);
149   return((unsigned char) (quantum/72340172838076673.0+0.5));
150 #endif
151 }
152 #endif
153
154 extern MagickExport MagickBooleanType
155   SetQuantumDepth(const Image *,QuantumInfo *,const size_t),
156   SetQuantumFormat(const Image *,QuantumInfo *,const QuantumFormatType),
157   SetQuantumPad(const Image *,QuantumInfo *,const size_t);
158
159 extern MagickExport QuantumInfo
160   *AcquireQuantumInfo(const ImageInfo *,Image *),
161   *DestroyQuantumInfo(QuantumInfo *);
162
163 extern MagickExport QuantumType
164   GetQuantumType(Image *,ExceptionInfo *);
165
166 extern MagickExport size_t
167   ExportQuantumPixels(const Image *,const CacheView *,const QuantumInfo *,
168     const QuantumType,unsigned char *,ExceptionInfo *),
169   GetQuantumExtent(const Image *,const QuantumInfo *,const QuantumType),
170   ImportQuantumPixels(Image *,CacheView *,const QuantumInfo *,const QuantumType,
171     const unsigned char *,ExceptionInfo *);
172
173 extern MagickExport unsigned char
174   *GetQuantumPixels(const QuantumInfo *);
175
176 extern 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),
182   SetQuantumQuantum(QuantumInfo *,const size_t),
183   SetQuantumScale(QuantumInfo *,const double);
184
185 #if defined(__cplusplus) || defined(c_plusplus)
186 }
187 #endif
188
189 #endif