Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:11:44

0001 /*
0002   Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization
0003   dedicated to making software imaging solutions freely available.
0004 
0005   You may not use this file except in compliance with the License.  You may
0006   obtain a copy of the License at
0007 
0008     https://imagemagick.org/script/license.php
0009 
0010   Unless required by applicable law or agreed to in writing, software
0011   distributed under the License is distributed on an "AS IS" BASIS,
0012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013   See the License for the specific language governing permissions and
0014   limitations under the License.
0015 
0016   MagickCore quantum inline methods.
0017 */
0018 #ifndef MAGICKCORE_QUANTUM_H
0019 #define MAGICKCORE_QUANTUM_H
0020 
0021 #include <float.h>
0022 #include "MagickCore/image.h"
0023 #include "MagickCore/semaphore.h"
0024 
0025 #if defined(__cplusplus) || defined(c_plusplus)
0026 extern "C" {
0027 #endif
0028 
0029 typedef enum
0030 {
0031   UndefinedEndian,
0032   LSBEndian,
0033   MSBEndian
0034 } EndianType;
0035 
0036 typedef enum
0037 {
0038   UndefinedQuantumAlpha,
0039   AssociatedQuantumAlpha,
0040   DisassociatedQuantumAlpha
0041 } QuantumAlphaType;
0042 
0043 typedef enum
0044 {
0045   UndefinedQuantumFormat,
0046   FloatingPointQuantumFormat,
0047   SignedQuantumFormat,
0048   UnsignedQuantumFormat
0049 } QuantumFormatType;
0050 
0051 typedef enum
0052 {
0053   UndefinedQuantum,
0054   AlphaQuantum,
0055   BGRAQuantum,
0056   BGROQuantum,
0057   BGRQuantum,
0058   BlackQuantum,
0059   BlueQuantum,
0060   CbYCrAQuantum,
0061   CbYCrQuantum,
0062   CbYCrYQuantum,
0063   CMYKAQuantum,
0064   CMYKOQuantum,
0065   CMYKQuantum,
0066   CyanQuantum,
0067   GrayAlphaQuantum,
0068   GrayQuantum,
0069   GreenQuantum,
0070   IndexAlphaQuantum,
0071   IndexQuantum,
0072   MagentaQuantum,
0073   OpacityQuantum,
0074   RedQuantum,
0075   RGBAQuantum,
0076   RGBOQuantum,
0077   RGBPadQuantum,
0078   RGBQuantum,
0079   YellowQuantum,
0080   MultispectralQuantum
0081 } QuantumType;
0082 
0083 typedef struct _QuantumInfo
0084   QuantumInfo;
0085 
0086 static inline Quantum ClampToQuantum(const MagickRealType quantum)
0087 {
0088 #if defined(MAGICKCORE_HDRI_SUPPORT)
0089   return((Quantum) quantum);
0090 #else
0091   if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
0092     return((Quantum) 0);
0093   if (quantum >= (MagickRealType) QuantumRange)
0094     return(QuantumRange);
0095   return((Quantum) (quantum+0.5));
0096 #endif
0097 }
0098 
0099 #if (MAGICKCORE_QUANTUM_DEPTH == 8)
0100 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
0101 {
0102 #if !defined(MAGICKCORE_HDRI_SUPPORT)
0103   return((unsigned char) quantum);
0104 #else
0105   if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
0106     return(0);
0107   if (quantum >= 255.0)
0108     return(255);
0109   return((unsigned char) (quantum+0.5));
0110 #endif
0111 }
0112 #elif (MAGICKCORE_QUANTUM_DEPTH == 16)
0113 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
0114 {
0115 #if !defined(MAGICKCORE_HDRI_SUPPORT)
0116   return((unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8));
0117 #else
0118   if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
0119     return(0);
0120   if ((quantum/257.0) >= 255.0)
0121     return(255);
0122   return((unsigned char) (quantum/257.0+0.5));
0123 #endif
0124 }
0125 #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
0126 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
0127 {
0128 #if !defined(MAGICKCORE_HDRI_SUPPORT)
0129   return((unsigned char) ((quantum+MagickULLConstant(8421504))/
0130     MagickULLConstant(16843009)));
0131 #else
0132   if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
0133     return(0);
0134   if ((quantum/16843009.0) >= 255.0)
0135     return(255);
0136   return((unsigned char) (quantum/16843009.0+0.5));
0137 #endif
0138 }
0139 #elif (MAGICKCORE_QUANTUM_DEPTH == 64)
0140 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
0141 {
0142 #if !defined(MAGICKCORE_HDRI_SUPPORT)
0143   return((unsigned char) (quantum/72340172838076673.0+0.5));
0144 #else
0145   if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
0146     return(0);
0147   if ((quantum/72340172838076673.0) >= 255.0)
0148     return(255);
0149   return((unsigned char) (quantum/72340172838076673.0+0.5));
0150 #endif
0151 }
0152 #endif
0153 
0154 extern MagickExport EndianType
0155   GetQuantumEndian(const QuantumInfo *);
0156 
0157 extern MagickExport MagickBooleanType
0158   SetQuantumDepth(const Image *,QuantumInfo *,const size_t),
0159   SetQuantumEndian(const Image *,QuantumInfo *,const EndianType),
0160   SetQuantumFormat(const Image *,QuantumInfo *,const QuantumFormatType),
0161   SetQuantumPad(const Image *,QuantumInfo *,const size_t);
0162 
0163 extern MagickExport QuantumFormatType
0164   GetQuantumFormat(const QuantumInfo *);
0165 
0166 extern MagickExport QuantumInfo
0167   *AcquireQuantumInfo(const ImageInfo *,Image *),
0168   *DestroyQuantumInfo(QuantumInfo *);
0169 
0170 extern MagickExport QuantumType
0171   GetQuantumType(Image *,ExceptionInfo *);
0172 
0173 extern MagickExport size_t
0174   ExportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType,
0175     unsigned char *magick_restrict,ExceptionInfo *),
0176   GetQuantumExtent(const Image *,const QuantumInfo *,const QuantumType),
0177   ImportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType,
0178     const unsigned char *magick_restrict,ExceptionInfo *);
0179 
0180 extern MagickExport unsigned char
0181   *GetQuantumPixels(const QuantumInfo *);
0182 
0183 extern MagickExport void
0184   GetQuantumInfo(const ImageInfo *,QuantumInfo *),
0185   SetQuantumAlphaType(QuantumInfo *,const QuantumAlphaType),
0186   SetQuantumImageType(Image *,const QuantumType),
0187   SetQuantumMinIsWhite(QuantumInfo *,const MagickBooleanType),
0188   SetQuantumPack(QuantumInfo *,const MagickBooleanType),
0189   SetQuantumQuantum(QuantumInfo *,const size_t),
0190   SetQuantumScale(QuantumInfo *,const double);
0191 
0192 #if defined(__cplusplus) || defined(c_plusplus)
0193 }
0194 #endif
0195 
0196 #endif