MagickCore: quantum-private.h Source File

# quantum-private.h

Go to the documentation of this file.

    00001 /*
    00002   Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization
    00003   dedicated to making software imaging solutions freely available.
    00004
    00005   You may not use this file except in compliance with the License.
    00006   obtain a copy of the License at
    00007
    00008     http://www.imagemagick.org/script/license.php
    00009
    00010   Unless required by applicable law or agreed to in writing, software
    00011   distributed under the License is distributed on an "AS IS" BASIS,
    00012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00013   See the License for the specific language governing permissions and
    00014   limitations under the License.
    00015
    00016   MagickCore quantum inline methods.
    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 typedef struct _QuantumState
    00026 {
    00027   EndianType
    00028     endian;
    00029
    00030   double
    00031     minimum,
    00032     scale;
    00033
    00034   unsigned long
    00035     pixel,
    00036     bits;
    00037
    00038   const unsigned long
    00039     *mask;
    00040 } QuantumState;
    00041
    00042 static inline MagickRealType ClipToQuantum(const MagickRealType value)
    00043 {
    00044   if (value <= 0.0)
    00045     return(0.0);
    00046   if (value >= QuantumRange)
    00047     return((MagickRealType) QuantumRange);
    00048   return(value);
    00049 }
    00050
    00051 static inline void InitializeQuantumState(const QuantumInfo *quantum_info,
    00052   const EndianType endian,QuantumState *quantum_state)
    00053 {
    00054   static const unsigned long mask[32] =
    00055   {
    00056     0x00000000UL, 0x00000001UL, 0x00000003UL, 0x00000007UL, 0x0000000fUL,
    00057     0x0000001fUL, 0x0000003fUL, 0x0000007fUL, 0x000000ffUL, 0x000001ffUL,
    00058     0x000003ffUL, 0x000007ffUL, 0x00000fffUL, 0x00001fffUL, 0x00003fffUL,
    00059     0x00007fffUL, 0x0000ffffUL, 0x0001ffffUL, 0x0003ffffUL, 0x0007ffffUL,
    00060     0x000fffffUL, 0x001fffffUL, 0x003fffffUL, 0x007fffffUL, 0x00ffffffUL,
    00061     0x01ffffffUL, 0x03ffffffUL, 0x07ffffffUL, 0x0fffffffUL, 0x1fffffffUL,
    00062     0x3fffffffUL, 0x7fffffffUL
    00063   };
    00064
    00065   (void) ResetMagickMemory(quantum_state,0,sizeof(&quantum_state));
    00066   quantum_state->endian=endian;
    00067   quantum_state->minimum=quantum_info->minimum;
    00068   quantum_state->scale=quantum_info->scale;
    00069   quantum_state->bits=0;
    00070   quantum_state->mask=mask;
    00071 }
    00072
    00073 static inline void PopCharPixel(const unsigned char pixel,
    00074   unsigned char **pixels)
    00075 {
    00076   *(*pixels)++=(unsigned char) (pixel);
    00077 }
    00078
    00079 static inline void PopDoublePixel(const QuantumState *quantum_state,
    00080   const double pixel,unsigned char **pixels)
    00081 {
    00082   unsigned char
    00083     quantum[8];
    00084
    00085   *((double *) quantum)=(double) (pixel*quantum_state->scale+
    00086     quantum_state->minimum);
    00087   if (quantum_state->endian != LSBEndian)
    00088     {
    00089       *(*pixels)++=quantum[7];
    00090       *(*pixels)++=quantum[6];
    00091       *(*pixels)++=quantum[5];
    00092       *(*pixels)++=quantum[4];
    00093       *(*pixels)++=quantum[3];
    00094       *(*pixels)++=quantum[2];
    00095       *(*pixels)++=quantum[1];
    00096       *(*pixels)++=quantum[0];
    00097       return;
    00098     }
    00099   *(*pixels)++=quantum[0];
    00100   *(*pixels)++=quantum[1];
    00101   *(*pixels)++=quantum[2];
    00102   *(*pixels)++=quantum[3];
    00103   *(*pixels)++=quantum[4];
    00104   *(*pixels)++=quantum[5];
    00105   *(*pixels)++=quantum[6];
    00106   *(*pixels)++=quantum[7];
    00107 }
    00108
    00109 static inline void PopFloatPixel(const QuantumState *quantum_state,
    00110   const float pixel,unsigned char **pixels)
    00111 {
    00112   unsigned char
    00113     quantum[4];
    00114
    00115   *((float *) quantum)=(float) ((double) pixel*quantum_state->scale+
    00116     quantum_state->minimum);
    00117   if (quantum_state->endian != LSBEndian)
    00118     {
    00119       *(*pixels)++=quantum[3];
    00120       *(*pixels)++=quantum[2];
    00121       *(*pixels)++=quantum[1];
    00122       *(*pixels)++=quantum[0];
    00123       return;
    00124     }
    00125   *(*pixels)++=quantum[0];
    00126   *(*pixels)++=quantum[1];
    00127   *(*pixels)++=quantum[2];
    00128   *(*pixels)++=quantum[3];
    00129 }
    00130
    00131 static inline void PopLongPixel(const QuantumState *quantum_state,
    00132   const unsigned long pixel,unsigned char **pixels)
    00133 {
    00134   if (quantum_state->endian != LSBEndian)
    00135     {
    00136       *(*pixels)++=(unsigned char) ((pixel) >> 24);
    00137       *(*pixels)++=(unsigned char) ((pixel) >> 16);
    00138       *(*pixels)++=(unsigned char) ((pixel) >> 8);
    00139       *(*pixels)++=(unsigned char) (pixel);
    00140       return;
    00141     }
    00142   *(*pixels)++=(unsigned char) (pixel);
    00143   *(*pixels)++=(unsigned char) ((pixel) >> 8);
    00144   *(*pixels)++=(unsigned char) ((pixel) >> 16);
    00145   *(*pixels)++=(unsigned char) ((pixel) >> 24);
    00146 }
    00147
    00148 static inline void PopQuantumPixel(QuantumState *quantum_state,
    00149   const unsigned long depth,const unsigned long pixel,unsigned char **pixels)
    00150 {
    00151   register long
    00152     i;
    00153
    00154   register unsigned long
    00155     quantum_bits;
    00156
    00157   if (quantum_state->bits == 0UL)
    00158     quantum_state->bits=8UL;
    00159   for (i=(long) depth; i > 0L; )
    00160   {
    00161     quantum_bits=(unsigned long) i;
    00162     if (quantum_bits > quantum_state->bits)
    00163       quantum_bits=quantum_state->bits;
    00164     i-=quantum_bits;
    00165     if (quantum_state->bits == 8)
    00166       *(*pixels)='\0';
    00167     quantum_state->bits-=quantum_bits;
    00168     *(*pixels)|=(((pixel >> i) &~ ((~0UL) << quantum_bits)) <<
    00169       quantum_state->bits);
    00170     if (quantum_state->bits == 0UL)
    00171       {
    00172         (*pixels)++;
    00173         quantum_state->bits=8UL;
    00174       }
    00175   }
    00176 }
    00177
    00178 static inline void PopQuantumLongPixel(QuantumState *quantum_state,
    00179   const unsigned long depth,const unsigned long pixel,unsigned char **pixels)
    00180 {
    00181   register long
    00182     i;
    00183
    00184   unsigned long
    00185     quantum_bits;
    00186
    00187   if (quantum_state->bits == 0UL)
    00188     quantum_state->bits=32UL;
    00189   for (i=(long) depth; i > 0; )
    00190   {
    00191     quantum_bits=(unsigned long) i;
    00192     if (quantum_bits > quantum_state->bits)
    00193       quantum_bits=quantum_state->bits;
    00194     quantum_state->pixel|=(((pixel >> (depth-i)) &
    00195       quantum_state->mask[quantum_bits]) << (32UL-quantum_state->bits));
    00196     i-=quantum_bits;
    00197     quantum_state->bits-=quantum_bits;
    00198     if (quantum_state->bits == 0U)
    00199       {
    00200         PopLongPixel(quantum_state,quantum_state->pixel,pixels);
    00201         quantum_state->pixel=0U;
    00202         quantum_state->bits=32UL;
    00203       }
    00204   }
    00205 }
    00206
    00207 static inline void PopShortPixel(const QuantumState *quantum_state,
    00208   const unsigned short pixel,unsigned char **pixels)
    00209 {
    00210   if (quantum_state->endian != LSBEndian)
    00211     {
    00212       *(*pixels)++=(unsigned char) ((pixel) >> 8);
    00213       *(*pixels)++=(unsigned char) (pixel);
    00214       return;
    00215     }
    00216   *(*pixels)++=(unsigned char) (pixel);
    00217   *(*pixels)++=(unsigned char) ((pixel) >> 8);
    00218 }
    00219
    00220 static inline unsigned char PushCharPixel(const unsigned char **pixels)
    00221 {
    00222   unsigned char
    00223     pixel;
    00224
    00225   pixel=(unsigned char) *(*pixels)++;
    00226   return(pixel);
    00227 }
    00228
    00229 static inline IndexPacket PushColormapIndex(Image *image,
    00230   const unsigned long index)
    00231 {
    00232   assert(image != (Image *) NULL);
    00233   assert(image->signature == MagickSignature);
    00234   if (index < image->colors)
    00235     return((IndexPacket) index);
    00236   (void) ThrowMagickException(&image->exception,GetMagickModule(),
    00237     CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
    00238   return((IndexPacket) 0);
    00239 }
    00240
    00241 static inline double PushDoublePixel(const QuantumState *quantum_state,
    00242   const unsigned char **pixels)
    00243 {
    00244   double
    00245     pixel;
    00246
    00247   unsigned char
    00248     quantum[8];
    00249
    00250   if (quantum_state->endian != LSBEndian)
    00251     {
    00252       quantum[7]=(*(*pixels)++);
    00253       quantum[6]=(*(*pixels)++);
    00254       quantum[5]=(*(*pixels)++);
    00255       quantum[5]=(*(*pixels)++);
    00256       quantum[3]=(*(*pixels)++);
    00257       quantum[2]=(*(*pixels)++);
    00258       quantum[1]=(*(*pixels)++);
    00259       quantum[0]=(*(*pixels)++);
    00260       pixel=(*((double *) quantum));
    00261       pixel-=quantum_state->minimum;
    00262       pixel*=quantum_state->scale;
    00263       return(pixel);
    00264     }
    00265   quantum[0]=(*(*pixels)++);
    00266   quantum[1]=(*(*pixels)++);
    00267   quantum[2]=(*(*pixels)++);
    00268   quantum[3]=(*(*pixels)++);
    00269   quantum[4]=(*(*pixels)++);
    00270   quantum[5]=(*(*pixels)++);
    00271   quantum[6]=(*(*pixels)++);
    00272   quantum[7]=(*(*pixels)++);
    00273   pixel=(*((double *) quantum));
    00274   pixel-=quantum_state->minimum;
    00275   pixel*=quantum_state->scale;
    00276   return(pixel);
    00277 }
    00278
    00279 static inline float PushFloatPixel(const QuantumState *quantum_state,
    00280   const unsigned char **pixels)
    00281 {
    00282   float
    00283     pixel;
    00284
    00285   unsigned char
    00286     quantum[4];
    00287
    00288   if (quantum_state->endian != LSBEndian)
    00289     {
    00290       quantum[3]=(*(*pixels)++);
    00291       quantum[2]=(*(*pixels)++);
    00292       quantum[1]=(*(*pixels)++);
    00293       quantum[0]=(*(*pixels)++);
    00294       pixel=(*((float *) quantum));
    00295       pixel-=quantum_state->minimum;
    00296       pixel*=quantum_state->scale;
    00297       return(pixel);
    00298     }
    00299   quantum[0]=(*(*pixels)++);
    00300   quantum[1]=(*(*pixels)++);
    00301   quantum[2]=(*(*pixels)++);
    00302   quantum[3]=(*(*pixels)++);
    00303   pixel=(*((float *) quantum));
    00304   pixel-=quantum_state->minimum;
    00305   pixel*=quantum_state->scale;
    00306   return(pixel);
    00307 }
    00308
    00309 static inline unsigned long PushLongPixel(const QuantumState *quantum_state,
    00310   const unsigned char **pixels)
    00311 {
    00312   unsigned long
    00313     pixel;
    00314
    00315   if (quantum_state->endian != LSBEndian)
    00316     {
    00317       pixel=(unsigned long) (*(*pixels)++ << 24);
    00318       pixel|=(unsigned long) (*(*pixels)++ << 16);
    00319       pixel|=(unsigned long) (*(*pixels)++ << 8);
    00320       pixel|=(unsigned long) (*(*pixels)++);
    00321       return(pixel);
    00322     }
    00323   pixel=(unsigned long) (*(*pixels)++);
    00324   pixel|=(unsigned long) (*(*pixels)++ << 8);
    00325   pixel|=(unsigned long) (*(*pixels)++ << 16);
    00326   pixel|=(unsigned long) (*(*pixels)++ << 24);
    00327   return(pixel);
    00328 }
    00329
    00330 static inline unsigned long PushQuantumPixel(QuantumState *quantum_state,
    00331   const unsigned long depth,const unsigned char **pixels)
    00332 {
    00333   register long
    00334     i;
    00335
    00336   register unsigned long
    00337     quantum_bits,
    00338     quantum;
    00339
    00340   quantum=0UL;
    00341   for (i=(long) depth; i > 0L; )
    00342   {
    00343     if (quantum_state->bits == 0UL)
    00344       {
    00345         quantum_state->pixel=(*(*pixels)++);
    00346         quantum_state->bits=8UL;
    00347       }
    00348     quantum_bits=(unsigned long) i;
    00349     if (quantum_bits > quantum_state->bits)
    00350       quantum_bits=quantum_state->bits;
    00351     i-=quantum_bits;
    00352     quantum_state->bits-=quantum_bits;
    00353     quantum=(quantum << quantum_bits) | ((quantum_state->pixel >>
    00354       quantum_state->bits) &~ ((~0UL) << quantum_bits));
    00355   }
    00356   return(quantum);
    00357 }
    00358
    00359 static inline unsigned long PushQuantumLongPixel(QuantumState *quantum_state,
    00360   const unsigned long depth,const unsigned char **pixels)
    00361 {
    00362   register long
    00363     i;
    00364
    00365   register unsigned long
    00366     quantum,
    00367     quantum_bits;
    00368
    00369   quantum=0UL;
    00370   for (i=(long) depth; i > 0; )
    00371   {
    00372     if (quantum_state->bits == 0)
    00373       {
    00374         quantum_state->pixel=PushLongPixel(quantum_state,pixels);
    00375         quantum_state->bits=32UL;
    00376       }
    00377     quantum_bits=(unsigned long) i;
    00378     if (quantum_bits > quantum_state->bits)
    00379       quantum_bits=quantum_state->bits;
    00380     quantum|=(((quantum_state->pixel >> (32UL-quantum_state->bits)) &
    00381       quantum_state->mask[quantum_bits]) << (depth-i));
    00382     i-=quantum_bits;
    00383     quantum_state->bits-=quantum_bits;
    00384   }
    00385   return(quantum);
    00386 }
    00387
    00388 static inline unsigned short PushShortPixel(const QuantumState *quantum_state,
    00389   const unsigned char **pixels)
    00390 {
    00391   unsigned short
    00392     pixel;
    00393
    00394   if (quantum_state->endian != LSBEndian)
    00395     {
    00396       pixel=(unsigned short) (*(*pixels)++ << 8);
    00397       pixel|=(unsigned short) (*(*pixels)++);
    00398       return(pixel);
    00399     }
    00400   pixel=(unsigned short) (*(*pixels)++);
    00401   pixel|=(unsigned short) (*(*pixels)++ << 8);
    00402   return(pixel);
    00403 }
    00404
    00405 static inline Quantum ScaleAnyToQuantum(const QuantumAny quantum,
    00406   const unsigned long depth)
    00407 {
    00408   QuantumAny
    00409     scale;
    00410
    00411   if ((depth == 0) || (depth > MAGICKCORE_QUANTUM_DEPTH))
    00412     return(0);
    00413   scale=(QuantumAny) QuantumRange/((QuantumAny) QuantumRange >>
    00414     (QuantumAny) (MAGICKCORE_QUANTUM_DEPTH-depth));
    00415   return((Quantum) (scale*quantum));
    00416 }
    00417
    00418 static inline QuantumAny ScaleQuantumToAny(const Quantum quantum,
    00419   const unsigned long depth)
    00420 {
    00421   QuantumAny
    00422     scale;
    00423
    00424   if ((depth == 0) || (depth > MAGICKCORE_QUANTUM_DEPTH))
    00425     return(0);
    00426   scale=(QuantumAny) QuantumRange/((QuantumAny) QuantumRange >>
    00427     (QuantumAny) (MAGICKCORE_QUANTUM_DEPTH-depth));
    00428   return((QuantumAny) quantum/scale);
    00429 }
    00430
    00431 #if (MAGICKCORE_QUANTUM_DEPTH == 8)
    00432 static inline Quantum ScaleCharToQuantum(const unsigned char value)
    00433 {
    00434   return((Quantum) value);
    00435 }
    00436
    00437 static inline Quantum ScaleLongToQuantum(const unsigned long value)
    00438 {
    00439 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00440   return((Quantum) ((value+8421504UL)/16843009UL));
    00441 #else
    00442   return((Quantum) (value/16843008.0));
    00443 #endif
    00444 }
    00445
    00446 static inline Quantum ScaleMapToQuantum(const MagickRealType value)
    00447 {
    00448 #if defined(MAGICKCORE_HDRI_SUPPORT)
    00449   return((Quantum) value);
    00450 #else
    00451   if (value <= 0.0)
    00452     return(0);
    00453   if (value >= MaxMap)
    00454     return((Quantum) QuantumRange);
    00455   return((Quantum) (value+0.5));
    00456 #endif
    00457 }
    00458
    00459 static inline unsigned long ScaleQuantumToLong(const Quantum quantum)
    00460 {
    00461 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00462   return((unsigned long) (16843009UL*quantum));
    00463 #else
    00464   if (quantum <= 0.0)
    00465     return(0UL);
    00466   if ((16843008.0*quantum) >= 4294967295.0)
    00467     return(4294967295UL);
    00468   return((unsigned long) (16843008.0*quantum));
    00469 #endif
    00470 }
    00471
    00472 static inline unsigned long ScaleQuantumToMap(const Quantum quantum)
    00473 {
    00474   if (quantum <= 0)
    00475     return(0UL);
    00476   if (quantum >= (Quantum) MaxMap)
    00477     return((unsigned long) MaxMap);
    00478 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00479   return((unsigned long) quantum);
    00480 #else
    00481   return((unsigned long) (quantum+0.5));
    00482 #endif
    00483 }
    00484
    00485 static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
    00486 {
    00487 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00488   return((unsigned short) (257UL*quantum));
    00489 #else
    00490   if (quantum <= 0.0)
    00491     return(0);
    00492   if ((257.0*quantum) >= 65535.0)
    00493     return(65535);
    00494   return((unsigned short) (257.0*quantum));
    00495 #endif
    00496 }
    00497
    00498 static inline Quantum ScaleShortToQuantum(const unsigned short value)
    00499 {
    00500 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00501   return((Quantum) ((value+128UL)/257UL));
    00502 #else
    00503   return((Quantum) (value/257.0));
    00504 #endif
    00505 }
    00506 #elif (MAGICKCORE_QUANTUM_DEPTH == 16)
    00507 static inline Quantum ScaleCharToQuantum(const unsigned char value)
    00508 {
    00509 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00510   return((Quantum) (257UL*value));
    00511 #else
    00512   return((Quantum) (257.0*value));
    00513 #endif
    00514 }
    00515
    00516 static inline Quantum ScaleLongToQuantum(const unsigned long value)
    00517 {
    00518 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00519   return((Quantum) ((value+32768UL)/65537UL));
    00520 #else
    00521   return((Quantum) (value/65537.0));
    00522 #endif
    00523 }
    00524
    00525 static inline Quantum ScaleMapToQuantum(const MagickRealType value)
    00526 {
    00527 #if defined(MAGICKCORE_HDRI_SUPPORT)
    00528   return((Quantum) value);
    00529 #else
    00530   if (value <= 0.0)
    00531     return(0);
    00532   if (value >= MaxMap)
    00533     return((Quantum) QuantumRange);
    00534   return((Quantum) (value+0.5));
    00535 #endif
    00536 }
    00537
    00538 static inline unsigned long ScaleQuantumToLong(const Quantum quantum)
    00539 {
    00540 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00541   return((unsigned long) (65537UL*quantum));
    00542 #else
    00543   if (quantum <= 0.0)
    00544     return(0UL);
    00545   if ((65537.0*quantum) >= 4294967295.0)
    00546     return(4294967295UL);
    00547   return((unsigned long) (65537.0*quantum));
    00548 #endif
    00549 }
    00550
    00551 static inline unsigned long ScaleQuantumToMap(const Quantum quantum)
    00552 {
    00553   if (quantum <= 0)
    00554     return(0);
    00555   if ((1UL*quantum) >= MaxMap)
    00556     return((unsigned long) MaxMap);
    00557 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00558   return((unsigned long) quantum);
    00559 #else
    00560   return((unsigned long) (quantum+0.5));
    00561 #endif
    00562 }
    00563
    00564 static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
    00565 {
    00566 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00567   return((unsigned short) quantum);
    00568 #else
    00569   if (quantum <= 0.0)
    00570     return(0);
    00571   if (quantum >= 65535.0)
    00572     return(65535);
    00573   return((unsigned short) (quantum+0.5));
    00574 #endif
    00575 }
    00576
    00577 static inline Quantum ScaleShortToQuantum(const unsigned short value)
    00578 {
    00579   return((Quantum) value);
    00580 }
    00581 #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
    00582 static inline Quantum ScaleCharToQuantum(const unsigned char value)
    00583 {
    00584 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00585   return((Quantum) (16843009UL*value));
    00586 #else
    00587   return((Quantum) (16843009.0*value));
    00588 #endif
    00589 }
    00590
    00591 static inline Quantum ScaleLongToQuantum(const unsigned long value)
    00592 {
    00593   return((Quantum) value);
    00594 }
    00595
    00596 static inline Quantum ScaleMapToQuantum(const MagickRealType value)
    00597 {
    00598 #if defined(MAGICKCORE_HDRI_SUPPORT)
    00599   return((Quantum) (65537.0*value));
    00600 #else
    00601   if (value <= 0.0)
    00602     return(0);
    00603   if (value >= MaxMap)
    00604     return(QuantumRange);
    00605   return((Quantum) (65537UL*value));
    00606 #endif
    00607 }
    00608
    00609 static inline unsigned long ScaleQuantumToLong(const Quantum quantum)
    00610 {
    00611   return((unsigned long) quantum);
    00612 }
    00613
    00614 static inline unsigned long ScaleQuantumToMap(const Quantum quantum)
    00615 {
    00616   if (quantum <= 0.0)
    00617     return(0);
    00618   if ((quantum/65537.0) >= (MagickRealType) MaxMap)
    00619     return((unsigned long) MaxMap);
    00620 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00621   {
    00622     unsigned long
    00623       pixel;
    00624
    00625     pixel=(unsigned long) ((quantum+MagickULLConstant(32768))/
    00626       MagickULLConstant(65537));
    00627     return(pixel);
    00628   }
    00629 #else
    00630   return((unsigned long) (quantum/65537.0));
    00631 #endif
    00632 }
    00633
    00634 static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
    00635 {
    00636 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00637   unsigned short
    00638     pixel;
    00639
    00640   pixel=(unsigned short) ((quantum+MagickULLConstant(32768))/
    00641     MagickULLConstant(65537));
    00642   return(pixel);
    00643 #else
    00644   if (quantum <= 0.0)
    00645     return(0);
    00646   if ((quantum/65537.0) >= 65535.0)
    00647     return(65535);
    00648   return((unsigned short) (quantum/65537.0));
    00649 #endif
    00650 }
    00651
    00652 static inline Quantum ScaleShortToQuantum(const unsigned short value)
    00653 {
    00654 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00655   return((Quantum) (65537UL*value));
    00656 #else
    00657   return((Quantum) (65537.0*value));
    00658 #endif
    00659 }
    00660 #elif (MAGICKCORE_QUANTUM_DEPTH == 64)
    00661 static inline Quantum ScaleCharToQuantum(const unsigned char value)
    00662 {
    00663 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00664   return((Quantum) (MagickULLConstant(71777214294589695)*value));
    00665 #else
    00666   return((Quantum) (71777214294589695.0*value));
    00667 #endif
    00668 }
    00669
    00670 static inline Quantum ScaleLongToQuantum(const unsigned long value)
    00671 {
    00672 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00673   return((Quantum) (4294967295UL*value));
    00674 #else
    00675   return((Quantum) (4294967295.0*value));
    00676 #endif
    00677 }
    00678
    00679 static inline Quantum ScaleMapToQuantum(const MagickRealType value)
    00680 {
    00681 #if defined(MAGICKCORE_HDRI_SUPPORT)
    00682   return((Quantum) (281479271612415.0*value));
    00683 #else
    00684   if (value <= 0.0)
    00685     return(0);
    00686   if (value >= MaxMap)
    00687     return(QuantumRange);
    00688   return((Quantum) (MagickULLConstant(281479271612415)*value));
    00689 #endif
    00690 }
    00691
    00692 static inline unsigned long ScaleQuantumToLong(const Quantum quantum)
    00693 {
    00694 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00695   return((unsigned long) ((quantum+2147483648.0)/4294967297.0));
    00696 #else
    00697   return((unsigned long) (quantum/4294967297.0));
    00698 #endif
    00699 }
    00700
    00701 static inline unsigned long ScaleQuantumToMap(const Quantum quantum)
    00702 {
    00703   if (quantum <= 0.0)
    00704     return(0);
    00705   if ((quantum/281479271612415.0) >= (MagickRealType) MaxMap)
    00706     return((unsigned long) MaxMap);
    00707 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00708   return((unsigned long) ((quantum+2147450879.0)/281479271612415.0));
    00709 #else
    00710   return((unsigned long) (quantum/281479271612415.0));
    00711 #endif
    00712 }
    00713
    00714 static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
    00715 {
    00716 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00717   return((unsigned short) ((quantum+2147450879.0)/281479271612415.0));
    00718 #else
    00719   return((unsigned short) (quantum/281479271612415.0));
    00720 #endif
    00721 }
    00722
    00723 static inline Quantum ScaleShortToQuantum(const unsigned short value)
    00724 {
    00725 #if !defined(MAGICKCORE_HDRI_SUPPORT)
    00726   return((Quantum) (MagickULLConstant(281479271612415)*value));
    00727 #else
    00728   return((Quantum) (281479271612415.0*value));
    00729 #endif
    00730 }
    00731 #endif
    00732
    00733 #if defined(__cplusplus) || defined(c_plusplus)
    00734 }
    00735 #endif
    00736
    00737 #endif