AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2004.01.14 12:01 "[Tiff] COLORMAP and byte padding", by Stephan Assmus
2004.01.14 15:07 "Re: [Tiff] COLORMAP and byte padding", by Frank Warmerdam
2004.01.14 16:18 "Re: [Tiff] COLORMAP and byte padding", by Gerben Vos
2004.01.14 16:43 "Re: [Tiff] COLORMAP and byte padding", by Joris Van Damme
2004.01.14 17:13 "Re: [Tiff] COLORMAP and byte padding", by Gerben Vos
2004.01.14 17:17 "Re: [Tiff] COLORMAP and byte padding", by Joris Van Damme
2004.01.14 17:26 "Re: [Tiff] COLORMAP and byte padding", by Andy Cave
2004.01.14 17:36 "Re: [Tiff] COLORMAP and byte padding", by Joris Van Damme
2004.01.14 17:24 "Re: [Tiff] COLORMAP and byte padding", by Phillip Crews
2004.01.14 18:18 "Re: [Tiff] COLORMAP and byte padding", by Marti Maria
2004.01.14 19:02 "Re: [Tiff] COLORMAP and byte padding", by Andy Cave
2004.01.14 19:36 "Re: [Tiff] COLORMAP and byte padding", by Marti Maria
2004.01.14 19:48 "Re: [Tiff] COLORMAP and byte padding", by Andy Cave
2004.01.15 17:24 "Re: [Tiff] COLORMAP and byte padding", by Marti Maria
2004.01.15 17:37 "Re: [Tiff] COLORMAP and byte padding", by Andy Cave
2004.01.15 00:05 "Re: [Tiff] COLORMAP and byte padding", by Chris Cox

2004.01.14 16:18 "Re: [Tiff] COLORMAP and byte padding", by Gerben Vos

I have typically computed the 16bit value by multiplying the 8bit value by 256, but that isn't really the most precise approach as 255 would not quite become the maximum 16bit value (65535).

For the perfectionists who are wondering: multiplying by 257 works perfectly. In effect, it makes the least significant byte a copy of the most significant byte of the 16-bit value. In C:

        uint16val = ((uint8val << 8) | uint8val);

Note that when reducing the 16-bit value to 8-bit, you could divide by 257 and round, but it's way faster to simply take the upper byte (the same as an integer division by 256, truncating everything after the decimal point). Don't divide by 256 and round, because you will end up 1 too high in 50% of the cases. In C:

        uint8val = (uint16val >> 8);

Gerben.