MagickCore  7.0.3
quantum.h
Go to the documentation of this file.
1 /*
2  Copyright 1999-2019 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 "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 
153  GetQuantumEndian(const QuantumInfo *);
154 
156  SetQuantumDepth(const Image *,QuantumInfo *,const size_t),
157  SetQuantumEndian(const Image *,QuantumInfo *,const EndianType),
159  SetQuantumPad(const Image *,QuantumInfo *,const size_t);
160 
162  GetQuantumFormat(const QuantumInfo *);
163 
165  *AcquireQuantumInfo(const ImageInfo *,Image *),
167 
170 
171 extern MagickExport size_t
173  unsigned char *magick_restrict,ExceptionInfo *),
174  GetQuantumExtent(const Image *,const 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
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:120
QuantumFormatType
Definition: quantum.h:42
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:766
#define MagickULLConstant(c)
Definition: magick-type.h:36
MagickExport MagickBooleanType SetQuantumEndian(const Image *image, QuantumInfo *quantum_info, const EndianType endian)
Definition: quantum.c:726
EndianType
Definition: quantum.h:28
Definition: image.h:151
MagickBooleanType
Definition: magick-type.h:158
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:906
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:1009
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:944
MagickExport void SetQuantumImageType(Image *image, const QuantumType quantum_type)
Definition: quantum.c:805
static Quantum ClampToQuantum(const MagickRealType value)
Definition: quantum.h:84
MagickExport QuantumFormatType GetQuantumFormat(const QuantumInfo *quantum_info)
Definition: quantum.c:387
unsigned short Quantum
Definition: magick-type.h:82
MagickExport void SetQuantumQuantum(QuantumInfo *quantum_info, const size_t quantum)
Definition: quantum.c:977
QuantumType
Definition: quantum.h:50
#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:35
MagickExport void SetQuantumPack(QuantumInfo *quantum_info, const MagickBooleanType pack)
Definition: quantum.c:871
#define QuantumRange
Definition: magick-type.h:83
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