MagickCore  6.7.5
quantum.h
Go to the documentation of this file.
00001 /*
00002   Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization
00003   dedicated to making software imaging solutions freely available.
00004 
00005   You may not use this file except in compliance with the License.
00006   obtain a copy of the License at
00007 
00008     http://www.imagemagick.org/script/license.php
00009 
00010   Unless required by applicable law or agreed to in writing, software
00011   distributed under the License is distributed on an "AS IS" BASIS,
00012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013   See the License for the specific language governing permissions and
00014   limitations under the License.
00015 
00016   MagickCore quantum inline methods.
00017 */
00018 #ifndef _MAGICKCORE_QUANTUM_H
00019 #define _MAGICKCORE_QUANTUM_H
00020 
00021 #if defined(__cplusplus) || defined(c_plusplus)
00022 extern "C" {
00023 #endif
00024 
00025 #include "MagickCore/semaphore.h"
00026 
00027 #define RoundToQuantum(quantum)  ClampToQuantum(quantum)
00028 
00029 typedef enum
00030 {
00031   UndefinedEndian,
00032   LSBEndian,
00033   MSBEndian
00034 } EndianType;
00035 
00036 typedef enum
00037 {
00038   UndefinedQuantumAlpha,
00039   AssociatedQuantumAlpha,
00040   DisassociatedQuantumAlpha
00041 } QuantumAlphaType;
00042 
00043 typedef enum
00044 {
00045   UndefinedQuantumFormat,
00046   FloatingPointQuantumFormat,
00047   SignedQuantumFormat,
00048   UnsignedQuantumFormat
00049 } QuantumFormatType;
00050 
00051 typedef enum
00052 {
00053   UndefinedQuantum,
00054   AlphaQuantum,
00055   BGRAQuantum,
00056   BGROQuantum,
00057   BGRQuantum,
00058   BlackQuantum,
00059   BlueQuantum,
00060   CbYCrAQuantum,
00061   CbYCrQuantum,
00062   CbYCrYQuantum,
00063   CMYKAQuantum,
00064   CMYKOQuantum,
00065   CMYKQuantum,
00066   CyanQuantum,
00067   GrayAlphaQuantum,
00068   GrayQuantum,
00069   GreenQuantum,
00070   IndexAlphaQuantum,
00071   IndexQuantum,
00072   MagentaQuantum,
00073   OpacityQuantum,
00074   RedQuantum,
00075   RGBAQuantum,
00076   RGBOQuantum,
00077   RGBPadQuantum,
00078   RGBQuantum,
00079   YellowQuantum
00080 } QuantumType;
00081 
00082 typedef struct _QuantumInfo
00083   QuantumInfo;
00084 
00085 static inline Quantum ClampToQuantum(const MagickRealType value)
00086 {
00087 #if defined(MAGICKCORE_HDRI_SUPPORT)
00088   return((Quantum) value);
00089 #else
00090   if (value <= 0.0)
00091     return((Quantum) 0);
00092   if (value >= (MagickRealType) QuantumRange)
00093     return((Quantum) QuantumRange);
00094   return((Quantum) (value+0.5));
00095 #endif
00096 }
00097 
00098 #if (MAGICKCORE_QUANTUM_DEPTH == 8)
00099 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
00100 {
00101 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00102   return((unsigned char) quantum);
00103 #else
00104   if (quantum <= 0.0)
00105     return(0);
00106   if (quantum >= 255.0)
00107     return(255);
00108   return((unsigned char) (quantum+0.5));
00109 #endif
00110 }
00111 #elif (MAGICKCORE_QUANTUM_DEPTH == 16)
00112 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
00113 {
00114 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00115   return((unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8));
00116 #else
00117   if (quantum <= 0.0)
00118     return(0);
00119   if ((quantum/257.0) >= 255.0)
00120     return(255);
00121   return((unsigned char) (quantum/257.0+0.5));
00122 #endif
00123 }
00124 #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
00125 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
00126 {
00127 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00128   return((unsigned char) ((quantum+MagickULLConstant(8421504))/
00129     MagickULLConstant(16843009)));
00130 #else
00131   if (quantum <= 0.0)
00132     return(0);
00133   if ((quantum/16843009.0) >= 255.0)
00134     return(255);
00135   return((unsigned char) (quantum/16843009.0+0.5));
00136 #endif
00137 }
00138 #elif (MAGICKCORE_QUANTUM_DEPTH == 64)
00139 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
00140 {
00141 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00142   return((unsigned char) (quantum/72340172838076673.0+0.5));
00143 #else
00144   if (quantum <= 0.0)
00145     return(0);
00146   if ((quantum/72340172838076673.0) >= 255.0)
00147     return(255);
00148   return((unsigned char) (quantum/72340172838076673.0+0.5));
00149 #endif
00150 }
00151 #endif
00152 
00153 extern MagickExport MagickBooleanType
00154   SetQuantumDepth(const Image *,QuantumInfo *,const size_t),
00155   SetQuantumFormat(const Image *,QuantumInfo *,const QuantumFormatType),
00156   SetQuantumPad(const Image *,QuantumInfo *,const size_t);
00157 
00158 extern MagickExport QuantumFormatType
00159   GetQuantumFormat(const QuantumInfo *);
00160 
00161 extern MagickExport QuantumInfo
00162   *AcquireQuantumInfo(const ImageInfo *,Image *),
00163   *DestroyQuantumInfo(QuantumInfo *);
00164 
00165 extern MagickExport QuantumType
00166   GetQuantumType(Image *,ExceptionInfo *);
00167 
00168 extern MagickExport size_t
00169   ExportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType,
00170     unsigned char *,ExceptionInfo *),
00171   GetQuantumExtent(const Image *,const QuantumInfo *,const QuantumType),
00172   ImportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType,
00173     const unsigned char *,ExceptionInfo *);
00174 
00175 extern MagickExport unsigned char
00176   *GetQuantumPixels(const QuantumInfo *);
00177 
00178 extern MagickExport void
00179   GetQuantumInfo(const ImageInfo *,QuantumInfo *),
00180   SetQuantumAlphaType(QuantumInfo *,const QuantumAlphaType),
00181   SetQuantumImageType(Image *,const QuantumType),
00182   SetQuantumMinIsWhite(QuantumInfo *,const MagickBooleanType),
00183   SetQuantumPack(QuantumInfo *,const MagickBooleanType),
00184   SetQuantumQuantum(QuantumInfo *,const size_t),
00185   SetQuantumScale(QuantumInfo *,const double);
00186 
00187 #if defined(__cplusplus) || defined(c_plusplus)
00188 }
00189 #endif
00190 
00191 #endif