MagickCore  7.0.7
Convert, Edit, Or Compose Bitmap Images
quantum.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2018 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  https://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 #include "MagickCore/image.h"
22 #include "MagickCore/semaphore.h"
23 
24 #if defined(__cplusplus) || defined(c_plusplus)
25 extern "C" {
26 #endif
27 
28 typedef enum
29 {
33 } EndianType;
34 
35 typedef enum
36 {
41 
42 typedef enum
43 {
49 
50 typedef enum
51 {
79 } QuantumType;
80 
81 typedef struct _QuantumInfo
83 
84 static inline Quantum ClampToQuantum(const MagickRealType value)
85 {
86 #if defined(MAGICKCORE_HDRI_SUPPORT)
87  return((Quantum) value);
88 #else
89  if (value <= 0.0f)
90  return((Quantum) 0);
91  if (value >= (MagickRealType) QuantumRange)
92  return(QuantumRange);
93  return((Quantum) (value+0.5f));
94 #endif
95 }
96 
97 #if (MAGICKCORE_QUANTUM_DEPTH == 8)
98 static 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)
104  return(0);
105  if (quantum >= 255.0)
106  return(255);
107  return((unsigned char) (quantum+0.5));
108 #endif
109 }
110 #elif (MAGICKCORE_QUANTUM_DEPTH == 16)
111 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
112 {
113 #if !defined(MAGICKCORE_HDRI_SUPPORT)
114  return((unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8));
115 #else
116  if (quantum <= 0.0)
117  return(0);
118  if ((quantum/257.0) >= 255.0)
119  return(255);
120  return((unsigned char) (quantum/257.0+0.5));
121 #endif
122 }
123 #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
124 static 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);
132  if ((quantum/16843009.0) >= 255.0)
133  return(255);
134  return((unsigned char) (quantum/16843009.0+0.5));
135 #endif
136 }
137 #elif (MAGICKCORE_QUANTUM_DEPTH == 64)
138 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
139 {
140 #if !defined(MAGICKCORE_HDRI_SUPPORT)
141  return((unsigned char) (quantum/72340172838076673.0+0.5));
142 #else
143  if (quantum <= 0.0)
144  return(0);
145  if ((quantum/72340172838076673.0) >= 255.0)
146  return(255);
147  return((unsigned char) (quantum/72340172838076673.0+0.5));
148 #endif
149 }
150 #endif
151 
152 extern MagickExport EndianType
153  GetQuantumEndian(const QuantumInfo *);
154 
156  SetQuantumDepth(const Image *,QuantumInfo *,const size_t),
157  SetQuantumEndian(const Image *,QuantumInfo *,const EndianType),
158  SetQuantumFormat(const Image *,QuantumInfo *,const QuantumFormatType),
159  SetQuantumPad(const Image *,QuantumInfo *,const size_t);
160 
161 extern MagickExport QuantumFormatType
162  GetQuantumFormat(const QuantumInfo *);
163 
165  *AcquireQuantumInfo(const ImageInfo *,Image *),
167 
168 extern MagickExport QuantumType
170 
171 extern MagickExport size_t
172  ExportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType,
173  unsigned char *magick_restrict,ExceptionInfo *),
174  GetQuantumExtent(const Image *,const QuantumInfo *,const QuantumType),
175  ImportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType,
176  const unsigned char *magick_restrict,ExceptionInfo *);
177 
178 extern MagickExport unsigned char
179  *GetQuantumPixels(const QuantumInfo *);
180 
181 extern MagickExport void
183  SetQuantumAlphaType(QuantumInfo *,const QuantumAlphaType),
184  SetQuantumImageType(Image *,const QuantumType),
187  SetQuantumQuantum(QuantumInfo *,const size_t),
188  SetQuantumScale(QuantumInfo *,const double);
189 
190 #if defined(__cplusplus) || defined(c_plusplus)
191 }
192 #endif
193 
194 #endif
#define magick_restrict
Definition: MagickCore.h:41
MagickDoubleType MagickRealType
Definition: magick-type.h:118
QuantumFormatType
Definition: quantum.h:42
MagickExport size_t ImportQuantumPixels(const Image *, CacheView *, QuantumInfo *, const QuantumType, const unsigned char *magick_restrict, ExceptionInfo *)
MagickExport void SetQuantumImageType(Image *, const QuantumType)
#define MagickULLConstant(c)
Definition: magick-type.h:36
MagickExport MagickBooleanType SetQuantumFormat(const Image *, QuantumInfo *, const QuantumFormatType)
MagickExport QuantumType GetQuantumType(Image *, ExceptionInfo *)
Definition: quantum.c:519
MagickExport QuantumInfo * DestroyQuantumInfo(QuantumInfo *)
Definition: quantum.c:213
MagickExport void SetQuantumMinIsWhite(QuantumInfo *, const MagickBooleanType)
EndianType
Definition: quantum.h:28
Definition: image.h:151
MagickExport MagickBooleanType SetQuantumDepth(const Image *, QuantumInfo *, const size_t)
MagickBooleanType
Definition: magick-type.h:156
MagickExport size_t ExportQuantumPixels(const Image *, CacheView *, QuantumInfo *, const QuantumType, unsigned char *magick_restrict, ExceptionInfo *)
MagickExport unsigned char * GetQuantumPixels(const QuantumInfo *)
Definition: quantum.c:485
MagickExport size_t GetQuantumExtent(const Image *, const QuantumInfo *, const QuantumType)
MagickExport void SetQuantumScale(QuantumInfo *, const double)
Definition: quantum.c:1005
static Quantum ClampToQuantum(const MagickRealType value)
Definition: quantum.h:84
unsigned short Quantum
Definition: magick-type.h:82
MagickExport MagickBooleanType SetQuantumEndian(const Image *, QuantumInfo *, const EndianType)
MagickExport void SetQuantumQuantum(QuantumInfo *, const size_t)
MagickExport QuantumFormatType GetQuantumFormat(const QuantumInfo *)
Definition: quantum.c:383
MagickExport void GetQuantumInfo(const ImageInfo *, QuantumInfo *)
MagickExport MagickBooleanType SetQuantumPad(const Image *, QuantumInfo *, const size_t)
Definition: quantum.c:902
QuantumType
Definition: quantum.h:50
#define MagickExport
MagickExport EndianType GetQuantumEndian(const QuantumInfo *)
Definition: quantum.c:354
MagickExport void SetQuantumPack(QuantumInfo *, const MagickBooleanType)
QuantumAlphaType
Definition: quantum.h:35
MagickExport void SetQuantumAlphaType(QuantumInfo *, const QuantumAlphaType)
MagickExport QuantumInfo * AcquireQuantumInfo(const ImageInfo *, Image *)
#define QuantumRange
Definition: magick-type.h:83