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