private bool setupMap()
{
int range = (1 << bitspersample) - 1;
// treat 16 bit the same as eight bit
if (bitspersample == 16)
range = 255;
Map = new byte[range + 1];
if (photometric == Photometric.MINISWHITE)
{
for (int x = 0; x <= range; x++)
Map[x] = (byte)(((range - x) * 255) / range);
}
else
{
for (int x = 0; x <= range; x++)
Map[x] = (byte)((x * 255) / range);
}
if (bitspersample <= 16 && (photometric == Photometric.MINISBLACK || photometric == Photometric.MINISWHITE))
{
// Use photometric mapping table to construct unpacking tables for samples <= 8 bits.
if (!makebwmap())
return false;
// no longer need Map
Map = null;
}
return true;
}