BitMiracle.LibTiff.Classic.TiffRgbaImage.setupMap C# (CSharp) Method

setupMap() private method

Construct a mapping table to convert from the range of the data samples to [0, 255] - for display. This process also handles inverting B&W images when needed.
private setupMap ( ) : bool
return bool
        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;
        }