Exemplo n.º 1
0
        /// <summary>
        /// Unserializes a BinaryStream into the Attributes of this Instance
        /// </summary>
        /// <param name="index">Index of this Map in the Block</param>
        /// <param name="mapcount">Number of Maps in the block (0 is the smallest map)</param>
        /// <param name="reader">The Stream that contains the FileData</param>
        public void Unserialize(System.IO.BinaryReader reader, int index, int mapcount)
        {
            this.index    = index;
            this.mapcount = mapcount;
            datatype      = (MipMapType)reader.ReadByte();

            switch (datatype)
            {
            case MipMapType.Texture:
            {
                int imgsize = reader.ReadInt32();
                //data = reader.ReadBytes(imgsize);
                long pos = reader.BaseStream.Position;
                //System.IO.BinaryReader br = new System.IO.BinaryReader(new System.IO.MemoryStream(data));


                if (!parent.Parent.Fast)
                {
                    try
                    {
                        data = reader.ReadBytes(imgsize);

                        /*if (!Helper.DebugMode)
                         * {
                         *      // this is derefered now, until application reads the Texture Property
                         *      reader.BaseStream.Seek(-imgsize, System.IO.SeekOrigin.Current);
                         *      img = ImageLoader.Load(parent.TextureSize, imgsize, parent.Format, reader, index, mapcount);
                         * }
                         * else*/
                        {
                            datatype = MipMapType.SimPE_PlainData;
                            img      = null;
                        }
                    }
                    catch (Exception ex)
                    {
                        Helper.ExceptionMessage("", ex);
                    }
                }

                byte[] over = reader.ReadBytes((int)Math.Max(0, pos + imgsize - reader.BaseStream.Position));
                reader.BaseStream.Seek(pos + imgsize, System.IO.SeekOrigin.Begin);

                break;
            }

            case MipMapType.LifoReference:
            {
                /*byte len = reader.ReadByte();
                 * lifofile = Helper.ToString(reader.ReadBytes(len));*/
                lifofile = reader.ReadString();
                break;
            }

            default:
            {
                throw new Exception("Unknown MipMap Datatype 0x" + Helper.HexString((byte)datatype));
            }
            }
        }
Exemplo n.º 2
0
        //Rcol parent;

        /*public Rcol Parent
         * {
         *      get { return parent; }
         * }*/

        /// <summary>
        /// Constructor
        /// </summary>
        public LevelInfo(Rcol parent) : base(parent)
        {
            texturesize = new Size(0, 0);
            zlevel      = 0;
            sgres       = new SGResource(null);
            BlockID     = 0xED534136;
            data        = new byte[0];
            datatype    = MipMapType.SimPE_PlainData;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Constructore
 /// </summary>
 public MipMap(ImageData parent)
 {
     this.parent   = parent;
     this.datatype = MipMapType.SimPE_PlainData;
     data          = new Byte[0];
 }
Exemplo n.º 4
0
        /// <summary>
        /// Unserializes a BinaryStream into the Attributes of this Instance
        /// </summary>
        /// <param name="reader">The Stream that contains the FileData</param>
        public override void Unserialize(System.IO.BinaryReader reader)
        {
            version = reader.ReadUInt32();
            string s = reader.ReadString();

            sgres.BlockID = reader.ReadUInt32();
            sgres.Unserialize(reader);



            int w = reader.ReadInt32();
            int h = reader.ReadInt32();

            texturesize = new Size(w, h);
            zlevel      = reader.ReadInt32();

            int size = reader.ReadInt32();

            if (Parent.Fast)
            {
                reader.BaseStream.Seek(size, System.IO.SeekOrigin.Current);
                texturesize = new Size(0, 0);
                img         = null;
                return;
            }

            /*if (size == w*h) format = ImageLoader.TxtrFormats.DXT3Format;
             * else*/format = ImageLoader.TxtrFormats.DXT1Format;
            //Pumckl Contribution
            //-- 8< --------------------------------------------- 8< -----
            if (size == 4 * w * h)
            {
                format = ImageLoader.TxtrFormats.Raw32Bit;
            }
            else if (size == 3 * w * h)
            {
                format = ImageLoader.TxtrFormats.Raw24Bit;
            }
            else if (size == w * h)              // could be RAW8, DXT3 or DXT5
            {
                // it seems to be difficult to determine the right format
                if (sgres.FileName.IndexOf("bump") > 0)
                {                 // its a bump-map
                    format = ImageLoader.TxtrFormats.Raw8Bit;
                }
                else
                {
                    // i expect the upper left 4x4 corner of the pichture have
                    // all the same alpha so i can determine if it's DXT5
                    // i guess, it's somewhat dirty but what can i do else?
                    long  pos   = reader.BaseStream.Position;
                    ulong alpha = reader.ReadUInt64();                     // read the first 8 byte of the image
                    reader.BaseStream.Position = pos;
                    // on DXT5 if all alpha are the same the bytes 0 or 1 are not zero
                    // and the bytes 2-7 (codebits) ara all zero
                    if (((alpha & 0xffffffffffff0000) == 0) && ((alpha & 0xffff) != 0))
                    {
                        format = ImageLoader.TxtrFormats.DXT5Format;
                    }
                    else
                    {
                        format = ImageLoader.TxtrFormats.DXT3Format;
                    }
                }
            }
            else
            {
                format = ImageLoader.TxtrFormats.DXT1Format;              // size < w*h
            }
            //-- 8< --------------------------------------------- 8< -----


            long p1 = reader.BaseStream.Position;

            size = (int)(reader.BaseStream.Length - p1);

            /*if (!Helper.DebugMode)
             * {
             *      datatype = MipMapType.Texture;
             *      img = ImageLoader.Load(texturesize, size, format, reader, -1, 1);
             *      reader.BaseStream.Seek(p1, System.IO.SeekOrigin.Begin);
             * }
             * else */
            {
                datatype = MipMapType.SimPE_PlainData;
            }

            data = reader.ReadBytes(size);
        }