cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 1999-2008 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. |
| 6 | obtain a copy of the License at |
| 7 | |
| 8 | http://www.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 | #if defined(__cplusplus) || defined(c_plusplus) |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | #include "magick/semaphore.h" |
| 26 | |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 27 | #define RoundToQuantum(quantum) ClampToQuantum(quantum) |
| 28 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 29 | typedef enum |
| 30 | { |
| 31 | UndefinedEndian, |
| 32 | LSBEndian, |
| 33 | MSBEndian |
| 34 | } EndianType; |
| 35 | |
| 36 | typedef enum |
| 37 | { |
| 38 | UndefinedQuantumAlpha, |
| 39 | AssociatedQuantumAlpha, |
| 40 | DisassociatedQuantumAlpha |
| 41 | } QuantumAlphaType; |
| 42 | |
| 43 | typedef enum |
| 44 | { |
| 45 | UndefinedQuantumFormat, |
| 46 | FloatingPointQuantumFormat, |
| 47 | SignedQuantumFormat, |
cristy | c9672a9 | 2010-01-06 00:57:45 +0000 | [diff] [blame] | 48 | UnsignedQuantumFormat |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 49 | } QuantumFormatType; |
| 50 | |
| 51 | typedef enum |
| 52 | { |
| 53 | UndefinedQuantum, |
| 54 | AlphaQuantum, |
| 55 | BlackQuantum, |
| 56 | BlueQuantum, |
| 57 | CMYKAQuantum, |
| 58 | CMYKQuantum, |
| 59 | CyanQuantum, |
| 60 | GrayAlphaQuantum, |
| 61 | GrayQuantum, |
| 62 | GreenQuantum, |
| 63 | IndexAlphaQuantum, |
| 64 | IndexQuantum, |
| 65 | MagentaQuantum, |
| 66 | OpacityQuantum, |
| 67 | RedQuantum, |
| 68 | RGBAQuantum, |
cristy | 4a16cd5 | 2010-01-05 14:04:01 +0000 | [diff] [blame] | 69 | BGRAQuantum, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 70 | RGBOQuantum, |
| 71 | RGBQuantum, |
| 72 | YellowQuantum, |
| 73 | GrayPadQuantum, /* deprecated */ |
| 74 | RGBPadQuantum, |
| 75 | CbYCrYQuantum, |
| 76 | CbYCrQuantum, |
| 77 | CbYCrAQuantum, |
| 78 | CMYKOQuantum |
| 79 | } QuantumType; |
| 80 | |
| 81 | typedef struct _QuantumInfo |
| 82 | QuantumInfo; |
| 83 | |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 84 | static inline Quantum ClampToQuantum(const MagickRealType value) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 85 | { |
| 86 | #if defined(MAGICKCORE_HDRI_SUPPORT) |
| 87 | return((Quantum) value); |
| 88 | #else |
| 89 | if (value <= 0.0) |
| 90 | return((Quantum) 0); |
cristy | eaa7533 | 2010-01-09 16:47:14 +0000 | [diff] [blame^] | 91 | if (value >= (MagickRealType) QuantumRange) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 92 | return((Quantum) QuantumRange); |
| 93 | return((Quantum) (value+0.5)); |
| 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(0UL); |
| 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+2155839615.0)/71777214294589695.0)); |
| 142 | #else |
| 143 | return((unsigned char) (quantum/71777214294589695.0+0.5)); |
| 144 | #endif |
| 145 | } |
| 146 | #endif |
| 147 | |
| 148 | extern MagickExport MagickBooleanType |
| 149 | SetQuantumDepth(const Image *,QuantumInfo *,const unsigned long), |
| 150 | SetQuantumFormat(const Image *,QuantumInfo *,const QuantumFormatType), |
| 151 | SetQuantumPad(const Image *,QuantumInfo *,const unsigned long); |
| 152 | |
| 153 | extern MagickExport QuantumInfo |
| 154 | *AcquireQuantumInfo(const ImageInfo *,Image *), |
| 155 | *DestroyQuantumInfo(QuantumInfo *); |
| 156 | |
| 157 | extern MagickExport QuantumType |
| 158 | GetQuantumType(Image *,ExceptionInfo *); |
| 159 | |
| 160 | extern MagickExport size_t |
| 161 | ExportQuantumPixels(const Image *,const CacheView *,const QuantumInfo *, |
| 162 | const QuantumType,unsigned char *,ExceptionInfo *), |
| 163 | GetQuantumExtent(const Image *,const QuantumInfo *,const QuantumType), |
| 164 | ImportQuantumPixels(Image *,CacheView *,const QuantumInfo *,const QuantumType, |
| 165 | const unsigned char *,ExceptionInfo *); |
| 166 | |
| 167 | extern MagickExport unsigned char |
| 168 | *GetQuantumPixels(const QuantumInfo *); |
| 169 | |
| 170 | extern MagickExport void |
| 171 | GetQuantumInfo(const ImageInfo *,QuantumInfo *), |
| 172 | SetQuantumAlphaType(QuantumInfo *,const QuantumAlphaType), |
| 173 | SetQuantumImageType(Image *,const QuantumType), |
| 174 | SetQuantumMinIsWhite(QuantumInfo *,const MagickBooleanType), |
| 175 | SetQuantumPack(QuantumInfo *,const MagickBooleanType), |
| 176 | SetQuantumQuantum(QuantumInfo *,const unsigned long), |
| 177 | SetQuantumScale(QuantumInfo *,const double); |
| 178 | |
| 179 | #if defined(__cplusplus) || defined(c_plusplus) |
| 180 | } |
| 181 | #endif |
| 182 | |
| 183 | #endif |