MagickCore  7.0.10
quantum.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2020 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. You may
6  obtain a copy of the License at
7 
8  https://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 <float.h>
22 #include "MagickCore/image.h"
23 #include "MagickCore/semaphore.h"
24 
25 #if defined(__cplusplus) || defined(c_plusplus)
26 extern "C" {
27 #endif
28 
29 typedef enum
30 {
34 } EndianType;
35 
36 typedef enum
37 {
42 
43 typedef enum
44 {
50 
51 typedef enum
52 {
80 } QuantumType;
81 
82 typedef struct _QuantumInfo
84 
86 {
87 #if defined(MAGICKCORE_HDRI_SUPPORT)
88  return((Quantum) quantum);
89 #else
90  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
91  return((Quantum) 0);
92  if (quantum >= (MagickRealType) QuantumRange)
93  return(QuantumRange);
94  return((Quantum) (quantum+0.5));
95 #endif
96 }
97 
98 #if (MAGICKCORE_QUANTUM_DEPTH == 8)
99 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
100 {
101 #if !defined(MAGICKCORE_HDRI_SUPPORT)
102  return((unsigned char) quantum);
103 #else
104  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
105  return(0);
106  if (quantum >= 255.0)
107  return(255);
108  return((unsigned char) (quantum+0.5));
109 #endif
110 }
111 #elif (MAGICKCORE_QUANTUM_DEPTH == 16)
112 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
113 {
114 #if !defined(MAGICKCORE_HDRI_SUPPORT)
115  return((unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8));
116 #else
117  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
118  return(0);
119  if ((quantum/257.0) >= 255.0)
120  return(255);
121  return((unsigned char) (quantum/257.0+0.5));
122 #endif
123 }
124 #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
125 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
126 {
127 #if !defined(MAGICKCORE_HDRI_SUPPORT)
128  return((unsigned char) ((quantum+MagickULLConstant(8421504))/
129  MagickULLConstant(16843009)));
130 #else
131  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
132  return(0);
133  if ((quantum/16843009.0) >= 255.0)
134  return(255);
135  return((unsigned char) (quantum/16843009.0+0.5));
136 #endif
137 }
138 #elif (MAGICKCORE_QUANTUM_DEPTH == 64)
139 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
140 {
141 #if !defined(MAGICKCORE_HDRI_SUPPORT)
142  return((unsigned char) (quantum/72340172838076673.0+0.5));
143 #else
144  if ((IsNaN(quantum) != MagickFalse) || (quantum <= 0.0))
145  return(0);
146  if ((quantum/72340172838076673.0) >= 255.0)
147  return(255);
148  return((unsigned char) (quantum/72340172838076673.0+0.5));
149 #endif
150 }
151 #endif
152 
154  GetQuantumEndian(const QuantumInfo *);
155 
157  SetQuantumDepth(const Image *,QuantumInfo *,const size_t),
158  SetQuantumEndian(const Image *,QuantumInfo *,const EndianType),
160  SetQuantumPad(const Image *,QuantumInfo *,const size_t);
161 
163  GetQuantumFormat(const QuantumInfo *);
164 
166  *AcquireQuantumInfo(const ImageInfo *,Image *),
168 
171 
172 extern MagickExport size_t
174  unsigned char *magick_restrict,ExceptionInfo *),
175  GetQuantumExtent(const Image *,const QuantumInfo *,const QuantumType),
177  const unsigned char *magick_restrict,ExceptionInfo *);
178 
179 extern MagickExport unsigned char
180  *GetQuantumPixels(const QuantumInfo *);
181 
182 extern MagickExport void
188  SetQuantumQuantum(QuantumInfo *,const size_t),
189  SetQuantumScale(QuantumInfo *,const double);
190 
191 #if defined(__cplusplus) || defined(c_plusplus)
192 }
193 #endif
194 
195 #endif
#define magick_restrict
Definition: MagickCore.h:41
MagickDoubleType MagickRealType
Definition: magick-type.h:124
QuantumFormatType
Definition: quantum.h:43
MagickExport EndianType GetQuantumEndian(const QuantumInfo *quantum_info)
Definition: quantum.c:358
MagickExport MagickBooleanType SetQuantumFormat(const Image *image, QuantumInfo *quantum_info, const QuantumFormatType format)
Definition: quantum.c:769
#define MagickULLConstant(c)
Definition: magick-type.h:40
MagickExport MagickBooleanType SetQuantumEndian(const Image *image, QuantumInfo *quantum_info, const EndianType endian)
Definition: quantum.c:729
static Quantum ClampToQuantum(const MagickRealType quantum)
Definition: quantum.h:85
EndianType
Definition: quantum.h:29
Definition: image.h:151
MagickBooleanType
Definition: magick-type.h:169
MagickExport size_t ImportQuantumPixels(const Image *image, CacheView *image_view, QuantumInfo *quantum_info, const QuantumType quantum_type, const unsigned char *magick_restrict pixels, ExceptionInfo *exception)
MagickExport MagickBooleanType SetQuantumDepth(const Image *image, QuantumInfo *quantum_info, const size_t depth)
Definition: quantum.c:662
MagickExport MagickBooleanType SetQuantumPad(const Image *image, QuantumInfo *quantum_info, const size_t pad)
Definition: quantum.c:909
MagickExport void SetQuantumAlphaType(QuantumInfo *quantum_info, const QuantumAlphaType type)
Definition: quantum.c:627
MagickExport void SetQuantumScale(QuantumInfo *quantum_info, const double scale)
Definition: quantum.c:1012
MagickExport size_t ExportQuantumPixels(const Image *image, CacheView *image_view, QuantumInfo *quantum_info, const QuantumType quantum_type, unsigned char *magick_restrict pixels, ExceptionInfo *exception)
MagickExport unsigned char * GetQuantumPixels(const QuantumInfo *quantum_info)
Definition: quantum.c:489
MagickExport void SetQuantumMinIsWhite(QuantumInfo *quantum_info, const MagickBooleanType min_is_white)
Definition: quantum.c:947
MagickExport void SetQuantumImageType(Image *image, const QuantumType quantum_type)
Definition: quantum.c:808
#define IsNaN(a)
Definition: magick-type.h:192
MagickExport QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
Definition: quantum.c:387
unsigned short Quantum
Definition: magick-type.h:86
MagickExport void SetQuantumQuantum(QuantumInfo *quantum_info, const size_t quantum)
Definition: quantum.c:980
QuantumType
Definition: quantum.h:51
#define MagickExport
MagickExport void GetQuantumInfo(const ImageInfo *image_info, QuantumInfo *quantum_info)
Definition: quantum.c:418
MagickExport QuantumInfo * AcquireQuantumInfo(const ImageInfo *image_info, Image *image)
Definition: quantum.c:110
QuantumAlphaType
Definition: quantum.h:36
MagickExport void SetQuantumPack(QuantumInfo *quantum_info, const MagickBooleanType pack)
Definition: quantum.c:874
#define QuantumRange
Definition: magick-type.h:87
MagickExport QuantumInfo * DestroyQuantumInfo(QuantumInfo *quantum_info)
Definition: quantum.c:213
MagickExport size_t GetQuantumExtent(const Image *image, const QuantumInfo *quantum_info, const QuantumType quantum_type)
Definition: quantum.c:306
MagickExport QuantumType GetQuantumType(Image *image, ExceptionInfo *exception)
Definition: quantum.c:523