public static ImmutablePalette PaletteFromStream(Stream s, PaletteFromDrFileInfo info)
        {
            var colors        = new uint[Palette.Size];
            var headerName    = s.ReadASCII(4);
            var headerVersion = s.ReadInt32();

            if (headerName != "PALS")
            {
                throw new InvalidDataException("Palette header was not PALS");
            }

            if (headerVersion != 0x0102)
            {
                throw new InvalidDataException("Palette version `{0}` was incorrect (expected `0x0102`)".F(headerVersion));
            }

            // Data is made up of 3x256 bytes, each ranging 0-63. Data is grouped by channel.
            var list = new List <byte>();

            for (int i = 0; i < Palette.Size * 6; i++)
            {
                list.Add(s.ReadUInt8());
            }

            var rList = list.Take(256).ToList();
            var gList = list.Skip(256).Take(256).ToList();
            var bList = list.Skip(512).Take(256).ToList();

            for (int i = 0; i < Palette.Size; i++)
            {
                // Index 0 should always be completely transparent/background color
                if (i == 0)
                {
                    colors[i] = 0;
                }
                else if (i < 160 || i == 255)
                {
                    colors[i] = (uint)Color.FromArgb(
                        Math.Min((rList[i] * info.StandardPaletteMultiplier) + info.Gamma, 255),
                        Math.Min((gList[i] * info.StandardPaletteMultiplier) + info.Gamma, 255),
                        Math.Min((bList[i] * info.StandardPaletteMultiplier) + info.Gamma, 255)).ToArgb();
                }
                else
                {
                    colors[i] = (uint)Color.FromArgb(
                        Math.Min((rList[i] * info.TerrainPaletteMultiplier) + info.Gamma, 255),
                        Math.Min((gList[i] * info.TerrainPaletteMultiplier) + info.Gamma, 255),
                        Math.Min((bList[i] * info.TerrainPaletteMultiplier) + info.Gamma, 255)).ToArgb();
                }
            }

            // Shadow hack
            colors[info.ShadowIndex] = (uint)Color.FromArgb(112, 0, 0, 0).ToArgb();

            return(new ImmutablePalette(colors));
        }
 public PaletteFromDrFile(World world, PaletteFromDrFileInfo info)
 {
     this.world = world;
     this.info  = info;
 }