By the current definition in
http://rnbc.dyndns.org/pub/imagemagick_quanta/001/ when I go from 8_bit_pgm to 16_bit_pgm, in a quantum=65535 version this should happen:
From magick/quantum-private.h
Code: Select all
static inline Quantum ScaleCharToQuantum(const unsigned char value)
{
#if !defined(MAGICKCORE_HDRI_SUPPORT)
return((Quantum) (257U*value));
#else
return((Quantum) (257.0*value+0.0));
#endif
}
From magick/quantum-private.h
Code: Select all
static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
{
#if !defined(MAGICKCORE_HDRI_SUPPORT)
return((unsigned short) quantum);
#else
if (quantum <= 0.0)
return(0);
if (quantum >= 65535.0)
return(65535);
return((unsigned short) (quantum+0.5));
#endif
}
(this seems to work as it should from the source code)
0 --> 0 --> 0 --> 0.5 --> 0
1 --> 257 --> 257.5 --> 257
254 --> 65278 --> 65278.5 --> 65278
255 --> 65535 --> 65535.5 --> 65535
And when going from 16bit_pgm to 8bit_pgm:
From magick/quantum-private.h
Code: Select all
static inline Quantum ScaleShortToQuantum(const unsigned short value)
{
return((Quantum) value);
}
From magick/quantum.h
Code: Select all
static inline unsigned char ScaleQuantumToChar(const Quantum quantum)
{
#if !defined(MAGICKCORE_HDRI_SUPPORT)
return((unsigned char) (quantum/257U));
#else
if (quantum <= 0.0)
return(0);
if ((quantum/257.0) >= 255.0)
return(255);
return((unsigned char) (quantum/257.0+0.5));
#endif
}
(in italics what I am seeing, and don't understand because it's not what's in the source!)
0 --> 0 --> 0 --> 0.5 --> 0
(0)
1 --> 1 --> .0038910505 --> .5038910505 --> 0
(0)
126 --> 126 --> .4902723735 --> .9902723735 --> 0
(0)
127 --> 127 --> .4941634241 --> .9941634241 --> 0
(0)
128 --> 128 --> .4980544747 --> .9980544747 --> 0
(0)
129 --> 129 --> .5019455252 --> 1.001945525 --> 1
(0)
254 --> 254 --> .9883268482 --> 1.488326848 --> 1
(0)
255 --> 255 --> .9922178988 --> 1.492217898 --> 1
(0)
256 --> 256 --> .9961089494 --> 1.496108949 --> 1
(0)
257 --> 257 --> 1.000000000 --> 1.500000000 --> 1
(1)
65406 --> 65406 --> 254.4980544 --> 254.9980544 --> 254
(254)
65407 --> 65407 --> 254.5019455 --> 255.0019455 --> 255
(254)
65408 --> 65408 --> ... 255
(254)
65409 --> 65409 --> ... 255
(254)
65534 --> 65534 --> ... 255
(254)
65535 --> 65535 --> ... 255
(255)
Could you shed some light over this?