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 "magick/semaphore.h"
00026 
00027 typedef enum
00028 {
00029   UndefinedEndian,
00030   LSBEndian,
00031   MSBEndian
00032 } EndianType;
00033 
00034 typedef enum
00035 {
00036   UndefinedQuantumAlpha,
00037   AssociatedQuantumAlpha,
00038   DisassociatedQuantumAlpha
00039 } QuantumAlphaType;
00040 
00041 typedef enum
00042 {
00043   UndefinedQuantumFormat,
00044   FloatingPointQuantumFormat,
00045   SignedQuantumFormat,
00046   UnsignedQuantumFormat
00047 } QuantumFormatType;
00048 
00049 typedef enum
00050 {
00051   UndefinedQuantum,
00052   AlphaQuantum,
00053   BlackQuantum,
00054   BlueQuantum,
00055   CMYKAQuantum,
00056   CMYKQuantum,
00057   CyanQuantum,
00058   GrayAlphaQuantum,
00059   GrayQuantum,
00060   GreenQuantum,
00061   IndexAlphaQuantum,
00062   IndexQuantum,
00063   MagentaQuantum,
00064   OpacityQuantum,
00065   RedQuantum,
00066   RGBAQuantum,
00067   RGBOQuantum,
00068   RGBQuantum,
00069   YellowQuantum,
00070   GrayPadQuantum,  /* deprecated */
00071   RGBPadQuantum,
00072   CbYCrYQuantum,
00073   CbYCrQuantum,
00074   CbYCrAQuantum,
00075   CMYKOQuantum
00076 } QuantumType;
00077 
00078 typedef struct _QuantumInfo
00079   QuantumInfo;
00080 
00081 static inline Quantum RoundToQuantum(const MagickRealType value)
00082 {
00083 #if defined(MAGICKCORE_HDRI_SUPPORT)
00084   return((Quantum) value);
00085 #else
00086   if (value <= 0.0)
00087     return((Quantum) 0);
00088   if (value >= QuantumRange)
00089     return((Quantum) QuantumRange);
00090   return((Quantum) (value+0.5));
00091 #endif
00092 }
00093 
00094 #if (MAGICKCORE_QUANTUM_DEPTH == 8)
00095 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
00096 {
00097 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00098   return((unsigned char) quantum);
00099 #else
00100   if (quantum <= 0.0)
00101     return(0UL);
00102   if (quantum >= 255.0)
00103     return(255);
00104   return((unsigned char) (quantum+0.5));
00105 #endif
00106 }
00107 #elif (MAGICKCORE_QUANTUM_DEPTH == 16)
00108 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
00109 {
00110 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00111   return((unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8));
00112 #else
00113   if (quantum <= 0.0)
00114     return(0);
00115   if ((quantum/257.0) >= 255.0)
00116     return(255);
00117   return((unsigned char) (quantum/257.0+0.5));
00118 #endif
00119 }
00120 #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
00121 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
00122 {
00123 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00124   return((unsigned char) ((quantum+MagickULLConstant(8421504))/
00125     MagickULLConstant(16843009)));
00126 #else
00127   if (quantum <= 0.0)
00128     return(0);
00129   if ((quantum/16843009.0) >= 255.0)
00130     return(255);
00131   return((unsigned char) (quantum/16843009.0+0.5));
00132 #endif
00133 }
00134 #elif (MAGICKCORE_QUANTUM_DEPTH == 64)
00135 static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
00136 {
00137 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00138   return((unsigned char) ((quantum+2155839615.0)/71777214294589695.0));
00139 #else
00140   return((unsigned char) (quantum/71777214294589695.0+0.5));
00141 #endif
00142 }
00143 #endif
00144 
00145 extern MagickExport MagickBooleanType
00146   SetQuantumDepth(const Image *,QuantumInfo *,const unsigned long),
00147   SetQuantumFormat(const Image *,QuantumInfo *,const QuantumFormatType),
00148   SetQuantumPad(const Image *,QuantumInfo *,const unsigned long);
00149 
00150 extern MagickExport QuantumInfo
00151   *AcquireQuantumInfo(const ImageInfo *,Image *),
00152   *DestroyQuantumInfo(QuantumInfo *);
00153 
00154 extern MagickExport QuantumType
00155   GetQuantumType(Image *,ExceptionInfo *);
00156 
00157 extern MagickExport size_t
00158   ExportQuantumPixels(const Image *,const CacheView *,const QuantumInfo *,
00159     const QuantumType,unsigned char *,ExceptionInfo *),
00160   GetQuantumExtent(const Image *,const QuantumInfo *,const QuantumType),
00161   ImportQuantumPixels(Image *,CacheView *,const QuantumInfo *,const QuantumType,
00162     const unsigned char *,ExceptionInfo *);
00163 
00164 extern MagickExport unsigned char
00165   *GetQuantumPixels(const QuantumInfo *);
00166 
00167 extern MagickExport void
00168   GetQuantumInfo(const ImageInfo *,QuantumInfo *),
00169   SetQuantumAlphaType(QuantumInfo *,const QuantumAlphaType),
00170   SetQuantumImageType(Image *,const QuantumType),
00171   SetQuantumMinIsWhite(QuantumInfo *,const MagickBooleanType),
00172   SetQuantumPack(QuantumInfo *,const MagickBooleanType),
00173   SetQuantumQuantum(QuantumInfo *,const unsigned long),
00174   SetQuantumScale(QuantumInfo *,const double);
00175 
00176 #if defined(__cplusplus) || defined(c_plusplus)
00177 }
00178 #endif
00179 
00180 #endif

Generated on 19 Nov 2009 for MagickCore by  doxygen 1.6.1