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