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