Exemplo n.º 1
0
        public override Color[] GetPalette(BinaryReader source, miptex_t tex)
        {
            var p = source.BaseStream.Position;
            int offset = (((int)tex.width * (int)tex.height) * 85) >> 6;

            source.BaseStream.Seek(2+offset, SeekOrigin.Current);
            var b = source.ReadBytes(256*3);
            var c = new Color[256];
            for (int i = 0; i < 256; ++i)
            {
                c[i] = Color.FromArgb(255, b[i * 3], b[i * 3 + 1], b[i * 3 + 2]);
            }
            source.BaseStream.Seek(p, SeekOrigin.Begin);
            return c;
        }
Exemplo n.º 2
0
 public virtual Color[] GetPalette(BinaryReader source, miptex_t tex)
 {
     return q1palette.palette;
 }
Exemplo n.º 3
0
        protected virtual void ReadTextures(BinaryReader source)
        {
            if (header.miptex.size == 0)
                return;
            SeekDir(source, header.miptex);
            mipheader_t hdr = new mipheader_t();
            hdr.Read(source);
            textures = new List<BspEmbeddedTexture>(hdr.offset.Length);

            foreach (var offset in hdr.offset)
            {
                source.BaseStream.Seek(startOfTheFile + header.miptex.offset + offset, SeekOrigin.Begin);
                miptex_t miptex = new miptex_t();
                var texPos = source.BaseStream.Position;
                miptex.Read(source);

                var tex = new BspEmbeddedTexture() {
                    Name = miptex.name, Width = (int)miptex.width, Height = (int)miptex.height,
                    Sky = miptex.name == "sky",
                    Transparent = (miptex.name[0] == '{' || miptex.name[0] == '#') };
                if (miptex.offset1 > 0)
                {
                    tex.mipMaps = new Bitmap[4];
                    int w = (int)miptex.width;
                    int h = (int)miptex.height;
                    source.BaseStream.Seek(texPos + miptex.offset1, SeekOrigin.Begin);
                    var palette = GetPalette(source, miptex);
                    tex.mipMaps[0] = ReadBitmapData(source, miptex.alphaTest, w,h,palette);
                    w /= 2; h /= 2;
                    source.BaseStream.Seek(texPos + miptex.offset2, SeekOrigin.Begin);
                    tex.mipMaps[1] = ReadBitmapData(source, miptex.alphaTest, w, h, palette);
                    w /= 2; h /= 2;
                    source.BaseStream.Seek(texPos + miptex.offset4, SeekOrigin.Begin);
                    tex.mipMaps[2] = ReadBitmapData(source, miptex.alphaTest, w, h, palette);
                    w /= 2; h /= 2;
                    source.BaseStream.Seek(texPos + miptex.offset8, SeekOrigin.Begin);
                    tex.mipMaps[3] = ReadBitmapData(source, miptex.alphaTest, w, h, palette);
                }
                textures.Add(tex);
            }
        }