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