00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _MAGICKCORE_QUANTUM_PRIVATE_H
00019 #define _MAGICKCORE_QUANTUM_PRIVATE_H
00020
00021 #if defined(__cplusplus) || defined(c_plusplus)
00022 extern "C" {
00023 #endif
00024
00025 #include "magick/cache.h"
00026
00027 typedef struct _QuantumState
00028 {
00029 EndianType
00030 endian;
00031
00032 double
00033 minimum,
00034 scale,
00035 inverse_scale;
00036
00037 unsigned long
00038 pixel,
00039 bits;
00040
00041 const unsigned long
00042 *mask;
00043 } QuantumState;
00044
00045 struct _QuantumInfo
00046 {
00047 unsigned long
00048 depth,
00049 quantum;
00050
00051 QuantumFormatType
00052 format;
00053
00054 double
00055 minimum,
00056 maximum,
00057 scale;
00058
00059 size_t
00060 pad;
00061
00062 MagickBooleanType
00063 min_is_white,
00064 pack;
00065
00066 QuantumAlphaType
00067 alpha_type;
00068
00069 unsigned long
00070 number_threads;
00071
00072 unsigned char
00073 **pixels;
00074
00075 size_t
00076 extent;
00077
00078 SemaphoreInfo
00079 *semaphore;
00080
00081 unsigned long
00082 signature;
00083 };
00084
00085 static inline MagickSizeType GetQuantumRange(const unsigned long depth)
00086 {
00087 return((MagickSizeType) ((MagickULLConstant(1) << (depth-1))+
00088 ((MagickULLConstant(1) << (depth-1))-1)));
00089 }
00090
00091 static inline void InitializeQuantumState(const QuantumInfo *quantum_info,
00092 const EndianType endian,QuantumState *quantum_state)
00093 {
00094 static const unsigned long mask[32] =
00095 {
00096 0x00000000UL, 0x00000001UL, 0x00000003UL, 0x00000007UL, 0x0000000fUL,
00097 0x0000001fUL, 0x0000003fUL, 0x0000007fUL, 0x000000ffUL, 0x000001ffUL,
00098 0x000003ffUL, 0x000007ffUL, 0x00000fffUL, 0x00001fffUL, 0x00003fffUL,
00099 0x00007fffUL, 0x0000ffffUL, 0x0001ffffUL, 0x0003ffffUL, 0x0007ffffUL,
00100 0x000fffffUL, 0x001fffffUL, 0x003fffffUL, 0x007fffffUL, 0x00ffffffUL,
00101 0x01ffffffUL, 0x03ffffffUL, 0x07ffffffUL, 0x0fffffffUL, 0x1fffffffUL,
00102 0x3fffffffUL, 0x7fffffffUL
00103 };
00104
00105 (void) ResetMagickMemory(quantum_state,0,sizeof(&quantum_state));
00106 quantum_state->endian=endian;
00107 quantum_state->minimum=quantum_info->minimum;
00108 quantum_state->scale=quantum_info->scale;
00109 quantum_state->inverse_scale=0.0;
00110 if (quantum_state->scale != 0.0)
00111 quantum_state->inverse_scale=1.0/quantum_state->scale;
00112 quantum_state->bits=0;
00113 quantum_state->mask=mask;
00114 }
00115
00116 static inline unsigned char *PopCharPixel(const unsigned char pixel,
00117 unsigned char *pixels)
00118 {
00119 *pixels++=pixel;
00120 return(pixels);
00121 }
00122
00123 static inline unsigned char *PopLongPixel(const EndianType endian,
00124 const unsigned long pixel,unsigned char *pixels)
00125 {
00126 register unsigned int
00127 quantum;
00128
00129 quantum=(unsigned int) pixel;
00130 if (endian != LSBEndian)
00131 {
00132 *pixels++=(unsigned char) (quantum >> 24);
00133 *pixels++=(unsigned char) (quantum >> 16);
00134 *pixels++=(unsigned char) (quantum >> 8);
00135 *pixels++=(unsigned char) (quantum);
00136 return(pixels);
00137 }
00138 *pixels++=(unsigned char) (quantum);
00139 *pixels++=(unsigned char) (quantum >> 8);
00140 *pixels++=(unsigned char) (quantum >> 16);
00141 *pixels++=(unsigned char) (quantum >> 24);
00142 return(pixels);
00143 }
00144
00145 static inline unsigned char *PopShortPixel(const EndianType endian,
00146 const unsigned short pixel,unsigned char *pixels)
00147 {
00148 register unsigned int
00149 quantum;
00150
00151 quantum=pixel;
00152 if (endian != LSBEndian)
00153 {
00154 *pixels++=(unsigned char) (quantum >> 8);
00155 *pixels++=(unsigned char) (quantum);
00156 return(pixels);
00157 }
00158 *pixels++=(unsigned char) (quantum);
00159 *pixels++=(unsigned char) (quantum >> 8);
00160 return(pixels);
00161 }
00162
00163 static inline const unsigned char *PushCharPixel(const unsigned char *pixels,
00164 unsigned char *pixel)
00165 {
00166 *pixel=(*pixels++);
00167 return(pixels);
00168 }
00169
00170 static inline const unsigned char *PushLongPixel(const EndianType endian,
00171 const unsigned char *pixels,unsigned long *pixel)
00172 {
00173 register unsigned int
00174 quantum;
00175
00176 if (endian != LSBEndian)
00177 {
00178 quantum=(unsigned int) (*pixels++ << 24);
00179 quantum|=(unsigned int) (*pixels++ << 16);
00180 quantum|=(unsigned int) (*pixels++ << 8);
00181 quantum|=(unsigned int) (*pixels++);
00182 }
00183 else
00184 {
00185 quantum=(unsigned int) (*pixels++);
00186 quantum|=(unsigned int) (*pixels++ << 8);
00187 quantum|=(unsigned int) (*pixels++ << 16);
00188 quantum|=(unsigned int) (*pixels++ << 24);
00189 }
00190 *pixel=(unsigned long) (quantum & 0xffffffff);
00191 return(pixels);
00192 }
00193
00194 static inline const unsigned char *PushShortPixel(const EndianType endian,
00195 const unsigned char *pixels,unsigned short *pixel)
00196 {
00197 register unsigned int
00198 quantum;
00199
00200 if (endian != LSBEndian)
00201 {
00202 quantum=(unsigned int) (*pixels++ << 8);
00203 quantum|=(unsigned int) *pixels++;
00204 }
00205 else
00206 {
00207 quantum=(unsigned int) *pixels++;
00208 quantum|=(unsigned int) (*pixels++ << 8);
00209 }
00210 *pixel=(unsigned short) (quantum & 0xffff);
00211 return(pixels);
00212 }
00213
00214 static inline Quantum ScaleAnyToQuantum(const QuantumAny quantum,
00215 const QuantumAny range)
00216 {
00217 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00218 return((Quantum) (((MagickRealType) QuantumRange*quantum)/range+0.5));
00219 #else
00220 return((Quantum) (((MagickRealType) QuantumRange*quantum)/range));
00221 #endif
00222 }
00223
00224 static inline QuantumAny ScaleQuantumToAny(const Quantum quantum,
00225 const QuantumAny range)
00226 {
00227 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00228 return((QuantumAny) (((MagickRealType) range*quantum)/QuantumRange+0.5));
00229 #else
00230 return((QuantumAny) (((MagickRealType) range*quantum)/QuantumRange));
00231 #endif
00232 }
00233
00234 #if (MAGICKCORE_QUANTUM_DEPTH == 8)
00235 static inline Quantum ScaleCharToQuantum(const unsigned char value)
00236 {
00237 return((Quantum) value);
00238 }
00239
00240 static inline Quantum ScaleLongToQuantum(const unsigned long value)
00241 {
00242 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00243 return((Quantum) ((value+8421504UL)/16843009UL));
00244 #else
00245 return((Quantum) (value/16843009.0));
00246 #endif
00247 }
00248
00249 static inline Quantum ScaleMapToQuantum(const MagickRealType value)
00250 {
00251 #if defined(MAGICKCORE_HDRI_SUPPORT)
00252 return((Quantum) value);
00253 #else
00254 if (value <= 0.0)
00255 return(0);
00256 if ((value+0.5) >= MaxMap)
00257 return((Quantum) QuantumRange);
00258 return((Quantum) (value+0.5));
00259 #endif
00260 }
00261
00262 static inline unsigned long ScaleQuantumToLong(const Quantum quantum)
00263 {
00264 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00265 return((unsigned long) (16843009UL*quantum));
00266 #else
00267 if (quantum <= 0.0)
00268 return(0UL);
00269 if ((16843009.0*quantum) >= 4294967295.0)
00270 return(4294967295UL);
00271 return((unsigned long) (16843009.0*quantum+0.5));
00272 #endif
00273 }
00274
00275 static inline unsigned long ScaleQuantumToMap(const Quantum quantum)
00276 {
00277 if (quantum >= (Quantum) MaxMap)
00278 return((unsigned long) MaxMap);
00279 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00280 return((unsigned long) quantum);
00281 #else
00282 if (quantum < 0.0)
00283 return(0UL);
00284 return((unsigned long) (quantum+0.5));
00285 #endif
00286 }
00287
00288 static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
00289 {
00290 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00291 return((unsigned short) (257UL*quantum));
00292 #else
00293 if (quantum <= 0.0)
00294 return(0);
00295 if ((257.0*quantum) >= 65535.0)
00296 return(65535);
00297 return((unsigned short) (257.0*quantum+0.5));
00298 #endif
00299 }
00300
00301 static inline Quantum ScaleShortToQuantum(const unsigned short value)
00302 {
00303 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00304 return((Quantum) ((value+128UL)/257UL));
00305 #else
00306 return((Quantum) (value/257.0));
00307 #endif
00308 }
00309 #elif (MAGICKCORE_QUANTUM_DEPTH == 16)
00310 static inline Quantum ScaleCharToQuantum(const unsigned char value)
00311 {
00312 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00313 return((Quantum) (257UL*value));
00314 #else
00315 return((Quantum) (257.0*value));
00316 #endif
00317 }
00318
00319 static inline Quantum ScaleLongToQuantum(const unsigned long value)
00320 {
00321 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00322 return((Quantum) ((value+MagickULLConstant(32768))/
00323 MagickULLConstant(65537)));
00324 #else
00325 return((Quantum) (value/65537.0));
00326 #endif
00327 }
00328
00329 static inline Quantum ScaleMapToQuantum(const MagickRealType value)
00330 {
00331 #if defined(MAGICKCORE_HDRI_SUPPORT)
00332 return((Quantum) value);
00333 #else
00334 if (value <= 0.0)
00335 return(0);
00336 if ((value+0.5) >= MaxMap)
00337 return((Quantum) QuantumRange);
00338 return((Quantum) (value+0.5));
00339 #endif
00340 }
00341
00342 static inline unsigned long ScaleQuantumToLong(const Quantum quantum)
00343 {
00344 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00345 return((unsigned long) (65537UL*quantum));
00346 #else
00347 if (quantum <= 0.0)
00348 return(0UL);
00349 if ((65537.0*quantum) >= 4294967295.0)
00350 return(4294967295UL);
00351 return((unsigned long) (65537.0*quantum+0.5));
00352 #endif
00353 }
00354
00355 static inline unsigned long ScaleQuantumToMap(const Quantum quantum)
00356 {
00357 if (quantum >= (Quantum) MaxMap)
00358 return((unsigned long) MaxMap);
00359 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00360 return((unsigned long) quantum);
00361 #else
00362 if (quantum < 0.0)
00363 return(0UL);
00364 return((unsigned long) (quantum+0.5));
00365 #endif
00366 }
00367
00368 static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
00369 {
00370 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00371 return((unsigned short) quantum);
00372 #else
00373 if (quantum <= 0.0)
00374 return(0);
00375 if (quantum >= 65535.0)
00376 return(65535);
00377 return((unsigned short) (quantum+0.5));
00378 #endif
00379 }
00380
00381 static inline Quantum ScaleShortToQuantum(const unsigned short value)
00382 {
00383 return((Quantum) value);
00384 }
00385 #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
00386 static inline Quantum ScaleCharToQuantum(const unsigned char value)
00387 {
00388 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00389 return((Quantum) (16843009UL*value));
00390 #else
00391 return((Quantum) (16843009.0*value));
00392 #endif
00393 }
00394
00395 static inline Quantum ScaleLongToQuantum(const unsigned long value)
00396 {
00397 return((Quantum) value);
00398 }
00399
00400 static inline Quantum ScaleMapToQuantum(const MagickRealType value)
00401 {
00402 #if defined(MAGICKCORE_HDRI_SUPPORT)
00403 return((Quantum) (65537.0*value));
00404 #else
00405 if (value <= 0.0)
00406 return(0);
00407 if ((value+0.5) >= MaxMap)
00408 return(QuantumRange);
00409 return((Quantum) (65537UL*value));
00410 #endif
00411 }
00412
00413 static inline unsigned long ScaleQuantumToLong(const Quantum quantum)
00414 {
00415 return((unsigned long) quantum);
00416 }
00417
00418 static inline unsigned long ScaleQuantumToMap(const Quantum quantum)
00419 {
00420 if ((quantum/65537) >= MaxMap)
00421 return((unsigned long) MaxMap);
00422 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00423 return((unsigned long) ((quantum+MagickULLConstant(32768))/
00424 MagickULLConstant(65537)));
00425 #else
00426 if (quantum < 0.0)
00427 return(0UL);
00428 return((unsigned long) (quantum/65537.0)+0.5);
00429 #endif
00430 }
00431
00432 static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
00433 {
00434 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00435 return((unsigned short) ((quantum+MagickULLConstant(32768))/
00436 MagickULLConstant(65537)));
00437 #else
00438 if (quantum <= 0.0)
00439 return(0);
00440 if ((quantum/65537.0) >= 65535.0)
00441 return(65535);
00442 return((unsigned short) (quantum/65537.0+0.5));
00443 #endif
00444 }
00445
00446 static inline Quantum ScaleShortToQuantum(const unsigned short value)
00447 {
00448 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00449 return((Quantum) (65537UL*value));
00450 #else
00451 return((Quantum) (65537.0*value));
00452 #endif
00453 }
00454 #elif (MAGICKCORE_QUANTUM_DEPTH == 64)
00455 static inline Quantum ScaleCharToQuantum(const unsigned char value)
00456 {
00457 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00458 return((Quantum) (MagickULLConstant(71777214294589695)*value));
00459 #else
00460 return((Quantum) (71777214294589695.0*value));
00461 #endif
00462 }
00463
00464 static inline Quantum ScaleLongToQuantum(const unsigned long value)
00465 {
00466 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00467 return((Quantum) (4294967295UL*value));
00468 #else
00469 return((Quantum) (4294967295.0*value));
00470 #endif
00471 }
00472
00473 static inline Quantum ScaleMapToQuantum(const MagickRealType value)
00474 {
00475 #if defined(MAGICKCORE_HDRI_SUPPORT)
00476 return((Quantum) (281479271612415.0*value));
00477 #else
00478 if (value <= 0.0)
00479 return(0);
00480 if ((value+0.5) >= MaxMap)
00481 return(QuantumRange);
00482 return((Quantum) (MagickULLConstant(281479271612415)*value));
00483 #endif
00484 }
00485
00486 static inline unsigned long ScaleQuantumToLong(const Quantum quantum)
00487 {
00488 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00489 return((unsigned long) ((quantum+2147483648.0)/4294967297.0));
00490 #else
00491 return((unsigned long) (quantum/4294967297.0+0.5));
00492 #endif
00493 }
00494
00495 static inline unsigned long ScaleQuantumToMap(const Quantum quantum)
00496 {
00497 if ((quantum/281479271612415.0) >= MaxMap)
00498 return((unsigned long) MaxMap);
00499 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00500 return((unsigned long) ((quantum+2147450879.0)/281479271612415.0));
00501 #else
00502 if (quantum < 0.0)
00503 return(0UL);
00504 return((unsigned long) (quantum/281479271612415.0)+0.5);
00505 #endif
00506 }
00507
00508 static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
00509 {
00510 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00511 return((unsigned short) ((quantum+2147450879.0)/281479271612415.0));
00512 #else
00513 return((unsigned short) (quantum/281479271612415.0+0.5));
00514 #endif
00515 }
00516
00517 static inline Quantum ScaleShortToQuantum(const unsigned short value)
00518 {
00519 #if !defined(MAGICKCORE_HDRI_SUPPORT)
00520 return((Quantum) (MagickULLConstant(281479271612415)*value));
00521 #else
00522 return((Quantum) (281479271612415.0*value));
00523 #endif
00524 }
00525 #endif
00526
00527 #if defined(__cplusplus) || defined(c_plusplus)
00528 }
00529 #endif
00530
00531 #endif