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 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 25 | #include "MagickCore/semaphore.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 55 | BGRAQuantum, |
| 56 | BGROQuantum, |
| 57 | BGRQuantum, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 58 | BlackQuantum, |
| 59 | BlueQuantum, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 60 | CbYCrAQuantum, |
| 61 | CbYCrQuantum, |
| 62 | CbYCrYQuantum, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 63 | CMYKAQuantum, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 64 | CMYKOQuantum, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 65 | CMYKQuantum, |
| 66 | CyanQuantum, |
| 67 | GrayAlphaQuantum, |
| 68 | GrayQuantum, |
| 69 | GreenQuantum, |
| 70 | IndexAlphaQuantum, |
| 71 | IndexQuantum, |
| 72 | MagentaQuantum, |
| 73 | OpacityQuantum, |
| 74 | RedQuantum, |
| 75 | RGBAQuantum, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 76 | RGBOQuantum, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 77 | RGBPadQuantum, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 78 | RGBQuantum, |
| 79 | YellowQuantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 80 | } QuantumType; |
| 81 | |
| 82 | typedef struct _QuantumInfo |
| 83 | QuantumInfo; |
| 84 | |
cristy | 610b5aa | 2012-04-06 18:09:16 +0000 | [diff] [blame] | 85 | static inline Quantum ClampToQuantum(const double value) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 86 | { |
cristy | e85007d | 2010-06-06 22:51:36 +0000 | [diff] [blame] | 87 | #if defined(MAGICKCORE_HDRI_SUPPORT) |
| 88 | return((Quantum) value); |
| 89 | #else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 90 | if (value <= 0.0) |
| 91 | return((Quantum) 0); |
cristy | 610b5aa | 2012-04-06 18:09:16 +0000 | [diff] [blame] | 92 | if (value >= (double) QuantumRange) |
cristy | 6e963d8 | 2012-06-19 15:23:24 +0000 | [diff] [blame^] | 93 | return(QuantumRange); |
cristy | ed5f002 | 2010-05-10 00:28:28 +0000 | [diff] [blame] | 94 | return((Quantum) (value+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 95 | #endif |
| 96 | } |
| 97 | |
| 98 | #if (MAGICKCORE_QUANTUM_DEPTH == 8) |
| 99 | static inline unsigned char ScaleQuantumToChar(const Quantum quantum) |
| 100 | { |
| 101 | #if !defined(MAGICKCORE_HDRI_SUPPORT) |
| 102 | return((unsigned char) quantum); |
| 103 | #else |
| 104 | if (quantum <= 0.0) |
cristy | 4cfbb3f | 2010-03-14 20:40:23 +0000 | [diff] [blame] | 105 | return(0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 106 | if (quantum >= 255.0) |
| 107 | return(255); |
| 108 | return((unsigned char) (quantum+0.5)); |
| 109 | #endif |
| 110 | } |
| 111 | #elif (MAGICKCORE_QUANTUM_DEPTH == 16) |
| 112 | static inline unsigned char ScaleQuantumToChar(const Quantum quantum) |
| 113 | { |
| 114 | #if !defined(MAGICKCORE_HDRI_SUPPORT) |
cristy | 45410e2 | 2010-06-09 02:43:31 +0000 | [diff] [blame] | 115 | return((unsigned char) (((quantum+128UL)-((quantum+128UL) >> 8)) >> 8)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 116 | #else |
| 117 | if (quantum <= 0.0) |
| 118 | return(0); |
cristy | cd817db | 2010-05-09 03:05:41 +0000 | [diff] [blame] | 119 | if ((quantum/257.0) >= 255.0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 120 | return(255); |
cristy | cd817db | 2010-05-09 03:05:41 +0000 | [diff] [blame] | 121 | return((unsigned char) (quantum/257.0+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 122 | #endif |
| 123 | } |
| 124 | #elif (MAGICKCORE_QUANTUM_DEPTH == 32) |
| 125 | static inline unsigned char ScaleQuantumToChar(const Quantum quantum) |
| 126 | { |
| 127 | #if !defined(MAGICKCORE_HDRI_SUPPORT) |
| 128 | return((unsigned char) ((quantum+MagickULLConstant(8421504))/ |
| 129 | MagickULLConstant(16843009))); |
| 130 | #else |
| 131 | if (quantum <= 0.0) |
| 132 | return(0); |
cristy | cd817db | 2010-05-09 03:05:41 +0000 | [diff] [blame] | 133 | if ((quantum/16843009.0) >= 255.0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 134 | return(255); |
cristy | cd817db | 2010-05-09 03:05:41 +0000 | [diff] [blame] | 135 | return((unsigned char) (quantum/16843009.0+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 136 | #endif |
| 137 | } |
| 138 | #elif (MAGICKCORE_QUANTUM_DEPTH == 64) |
| 139 | static inline unsigned char ScaleQuantumToChar(const Quantum quantum) |
| 140 | { |
cristy | 8949e8e | 2010-05-11 01:46:22 +0000 | [diff] [blame] | 141 | #if !defined(MAGICKCORE_HDRI_SUPPORT) |
cristy | 4351352 | 2010-05-11 13:46:36 +0000 | [diff] [blame] | 142 | return((unsigned char) (quantum/72340172838076673.0+0.5)); |
cristy | 8949e8e | 2010-05-11 01:46:22 +0000 | [diff] [blame] | 143 | #else |
| 144 | if (quantum <= 0.0) |
| 145 | return(0); |
cristy | 4351352 | 2010-05-11 13:46:36 +0000 | [diff] [blame] | 146 | if ((quantum/72340172838076673.0) >= 255.0) |
cristy | 8949e8e | 2010-05-11 01:46:22 +0000 | [diff] [blame] | 147 | return(255); |
cristy | 4351352 | 2010-05-11 13:46:36 +0000 | [diff] [blame] | 148 | return((unsigned char) (quantum/72340172838076673.0+0.5)); |
cristy | 8949e8e | 2010-05-11 01:46:22 +0000 | [diff] [blame] | 149 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 150 | } |
| 151 | #endif |
| 152 | |
| 153 | extern MagickExport MagickBooleanType |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 154 | SetQuantumDepth(const Image *,QuantumInfo *,const size_t), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 155 | SetQuantumFormat(const Image *,QuantumInfo *,const QuantumFormatType), |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 156 | SetQuantumPad(const Image *,QuantumInfo *,const size_t); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 157 | |
cristy | e11d00a | 2011-12-06 18:03:25 +0000 | [diff] [blame] | 158 | extern MagickExport QuantumFormatType |
| 159 | GetQuantumFormat(const QuantumInfo *); |
| 160 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 161 | extern MagickExport QuantumInfo |
| 162 | *AcquireQuantumInfo(const ImageInfo *,Image *), |
| 163 | *DestroyQuantumInfo(QuantumInfo *); |
| 164 | |
| 165 | extern MagickExport QuantumType |
| 166 | GetQuantumType(Image *,ExceptionInfo *); |
| 167 | |
| 168 | extern MagickExport size_t |
cristy | 71b2717 | 2012-01-13 00:21:44 +0000 | [diff] [blame] | 169 | ExportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 170 | unsigned char *,ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 171 | GetQuantumExtent(const Image *,const QuantumInfo *,const QuantumType), |
cristy | 71b2717 | 2012-01-13 00:21:44 +0000 | [diff] [blame] | 172 | ImportQuantumPixels(const Image *,CacheView *,QuantumInfo *,const QuantumType, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 173 | const unsigned char *,ExceptionInfo *); |
| 174 | |
| 175 | extern MagickExport unsigned char |
| 176 | *GetQuantumPixels(const QuantumInfo *); |
| 177 | |
| 178 | extern MagickExport void |
| 179 | GetQuantumInfo(const ImageInfo *,QuantumInfo *), |
| 180 | SetQuantumAlphaType(QuantumInfo *,const QuantumAlphaType), |
| 181 | SetQuantumImageType(Image *,const QuantumType), |
| 182 | SetQuantumMinIsWhite(QuantumInfo *,const MagickBooleanType), |
| 183 | SetQuantumPack(QuantumInfo *,const MagickBooleanType), |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 184 | SetQuantumQuantum(QuantumInfo *,const size_t), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 185 | SetQuantumScale(QuantumInfo *,const double); |
| 186 | |
| 187 | #if defined(__cplusplus) || defined(c_plusplus) |
| 188 | } |
| 189 | #endif |
| 190 | |
| 191 | #endif |