Наследование: IFFChunk
Пример #1
0
        private SPR2Frame GetSprite(int ID, PALT Palette)
        {
            FileReader Reader = new FileReader(new MemoryStream(m_Data), false);

            Reader.Seek(m_OffsetTable[ID]);

            return(new SPR2Frame(Reader, m_Device, Palette, Version));
        }
Пример #2
0
        /// <summary>
        /// Attempts to read an IFF file from a given stream.
        /// </summary>
        /// <param name="Data">The stream from which to open the IFF.</param>
        /// <param name="ThrowException">Should this method throw an exception if it couldn't open the file?</param>
        /// <returns>True if successful, false otherwise (if ThrowException is set to false).</returns>
        public bool Init(Stream Data, bool ThrowException)
        {
            m_Reader = new FileReader(Data, true);

            string MagicNumber = m_Reader.ReadString(60);

            if (!MagicNumber.Equals("IFF FILE 2.5:TYPE FOLLOWED BY SIZE\0 JAMIE DOORNBOS & MAXIS 1\0", StringComparison.InvariantCultureIgnoreCase))
            {
                if (ThrowException)
                {
                    throw new IFFException("MagicNumber was wrong - IFF.cs!");
                }
                else
                {
                    return(false);
                }
            }

            m_Reader.ReadUInt32(); //RSMP offset

            //Size of a chunk header is 76 bytes.
            while ((m_Reader.StreamLength - m_Reader.Position) > 76)
            {
                IFFChunk Chunk;

                if (m_Device != null)
                {
                    Chunk = new IFFChunk(m_Reader, m_Device, this);
                }
                else
                {
                    Chunk = new IFFChunk(m_Reader, this);
                }

                switch (Chunk.Type)
                {
                case IFFChunkTypes.FBMP:
                    FBMP FBMPChunk = new FBMP(Chunk);
                    m_FBMPChunks.Add(Chunk.ID, FBMPChunk);
                    break;

                case IFFChunkTypes.FWAV:
                    FWAV FWAVChunk = new FWAV(Chunk);
                    m_FWAVChunks.Add(Chunk.ID, FWAVChunk);
                    break;

                case IFFChunkTypes.BMP_:
                    BMP_ BMPChunk = new BMP_(Chunk);
                    m_BMP_Chunks.Add(Chunk.ID, BMPChunk);
                    break;

                case IFFChunkTypes.DGRP:
                    DGRP DGRPChunk = new DGRP(Chunk);
                    m_DGRPChunks.Add(Chunk.ID, DGRPChunk);
                    break;

                case IFFChunkTypes.BCON:
                    BCON BCONChunk = new BCON(Chunk);
                    m_BCONChunks.Add(Chunk.ID, BCONChunk);
                    break;

                case IFFChunkTypes.GLOB:
                    GLOB GlobChunk = new GLOB(Chunk);
                    m_GLOBChunks.Add(Chunk.ID, GlobChunk);
                    break;

                case IFFChunkTypes.OBJD:
                    OBJD OBJDChunk = new OBJD(Chunk);
                    m_OBJDs.Add(OBJDChunk);
                    break;

                case IFFChunkTypes.TTAs:
                    TTAs TTAsChunk = new TTAs(Chunk);
                    m_TTAsChunks.Add(Chunk.ID, TTAsChunk);
                    break;

                case IFFChunkTypes.TTAB:
                    TTAB TTABChunk = new TTAB(Chunk);
                    TTABChunk.Type = Chunk.Type;
                    TTABChunk.ID   = Chunk.ID;
                    m_TTABChunks.Add(Chunk.ID, TTABChunk);
                    break;

                case IFFChunkTypes.TPRP:
                    TPRP TPRPChunk = new TPRP(Chunk);
                    m_TPRPChunks.Add(Chunk.ID, TPRPChunk);
                    break;

                case IFFChunkTypes.STR:
                    STR STRChunk = new STR(Chunk);
                    m_STRChunks.Add(Chunk.ID, STRChunk);
                    break;

                case IFFChunkTypes.BHAV:
                    BHAV BHAVChunk = new BHAV(Chunk);
                    m_BHAVChunks.Add(Chunk.ID, BHAVChunk);
                    break;

                case IFFChunkTypes.OBJf:
                    OBJf OBJfChunk = new OBJf(Chunk);
                    m_OBJfChunks.Add(Chunk.ID, OBJfChunk);
                    break;

                case IFFChunkTypes.FCNS:
                    FCNS FCNSChunk = new FCNS(Chunk);
                    m_FCNSChunks.Add(Chunk.ID, FCNSChunk);
                    break;

                case IFFChunkTypes.SPR:
                    SPR SPRChunk = new SPR(Chunk);
                    m_SPRChunks.Add(Chunk.ID, SPRChunk);
                    break;

                case IFFChunkTypes.SPR2:
                    SPR2 SPR2Chunk = new SPR2(Chunk);
                    m_SPR2Chunks.Add(Chunk.ID, SPR2Chunk);
                    break;

                case IFFChunkTypes.PALT:
                    PALT PALTChunk = new PALT(Chunk);
                    m_PALTChunks.Add(Chunk.ID, PALTChunk);
                    break;

                case IFFChunkTypes.CTSS:
                    CTSS CTSSChunk = new CTSS(Chunk);
                    m_CTSSChunks.Add(Chunk.ID, CTSSChunk);
                    break;

                case IFFChunkTypes.CST:
                    CST CSTChunk = new CST(Chunk);
                    m_CSTChunks.Add(Chunk.ID, CSTChunk);
                    break;
                }
            }

            return(true);
        }
Пример #3
0
        public SPR2Frame(FileReader Reader, GraphicsDevice Device, PALT Palette, uint SpriteVersion)
        {
            if (SpriteVersion == 1001)
            {
                Reader.ReadUInt32(); //Version
                Reader.ReadUInt32(); //Size
            }

            Width   = Reader.ReadUShort();
            Height  = Reader.ReadUShort();
            Texture = new Texture2D(Device, Width, Height);
            ZBuffer = new byte[Width * Height];

            uint Flags = Reader.ReadUInt32();

            Reader.ReadUShort(); //Palette.

            TransparentColor = Palette[Reader.ReadUShort()];

            HasZBuffer      = (Flags & 0x02) == 0x02;
            HasAlphaChannel = (Flags & 0x04) == 0x04;

            XLocation = Reader.ReadUShort();
            YLocation = Reader.ReadUShort();

            bool EndMarker = false;

            while (!EndMarker)
            {
                ushort Marker  = Reader.ReadUShort();
                var    Command = Marker >> 13;
                var    Count   = Marker & 0x1FFF;

                switch (Command)
                {
                //Fill this row with pixel data that directly follows; the count byte of the row command denotes
                //the size in bytes of the row's command/count bytes together with the supplied pixel data. In
                //the pixel data, each pixel command consists of a 3-bit/13-bit command/count header followed by a
                //block of pixel data padded to a multiple of 2 bytes. If the row is not filled completely, the
                //remainder is transparent. The pixel commands are:
                case 0x00:
                    for (int i = 0; i < Count; i++)
                    {
                        ushort PxMarker  = Reader.ReadUShort();
                        var    PxCommand = PxMarker >> 13;
                        var    PxCount   = PxMarker & 0x1FFF;

                        Color[] Colors;

                        switch (PxCommand)
                        {
                        //Set the next pixel count pixels in the z-buffer and color channels to the values defined
                        //by the pixel data provided directly after this command. Every group of 2 bytes in the pixel
                        //data provides a luminosity (z-buffer) or color index (color) value to be copied to the row
                        //for the z-buffer channel and color channel, respectively, in that order, using the full
                        //opacity value of 255 for each pixel that is not the transparent color.
                        case 0x01:
                            Colors = new Color[PxCount];

                            for (int j = 0; j < PxCount; j++)
                            {
                                byte Luminosity = Reader.ReadByte();
                                byte ColorIndex = Reader.ReadByte();
                                Colors[j]  = Palette[ColorIndex];
                                ZBuffer[j] = Luminosity;
                            }
                            Texture.SetData <Color>(Colors, 0, Colors.Length);
                            break;

                        //Set the next pixel count pixels in the z-buffer, color, and alpha channels to the values
                        //defined by the pixel data provided directly after this command. Every group of 3 bytes in
                        //the pixel data, minus the padding byte at the very end (if it exists), provides a luminosity
                        //(z-buffer and alpha) or color index (color) value to be copied to the row for the z-buffer,
                        //color, and alpha channels, respectively, in that order. The alpha channel data is grayscale
                        //in the range 0-31, and the z buffer is in range 0-255.
                        case 0x02:
                            Colors = new Color[PxCount];

                            for (int j = 0; j < PxCount; j++)
                            {
                                byte Luminosity = Reader.ReadByte();
                                byte ColorIndex = Reader.ReadByte();
                                byte Alpha      = (byte)(Reader.ReadByte() * 8.2258064516129032258064516129032);
                                Colors[j]   = Palette[ColorIndex];
                                Colors[j].A = Alpha;
                                ZBuffer[j]  = Luminosity;
                            }
                            Texture.SetData <Color>(Colors, 0, Colors.Length);
                            break;

                        //Leave the next pixel count pixels in the color channel filled with the transparent color,
                        //in the z-buffer channel filled with 255, and in the alpha channel filled with 0. This pixel
                        //command has no pixel data.
                        case 0x03:
                            Colors = new Color[PxCount];

                            for (int j = 0; j < PxCount; j++)
                            {
                                Colors[j]   = Color.Transparent;
                                Colors[j].A = 0;
                                ZBuffer[j]  = 255;
                            }
                            Texture.SetData <Color>(Colors, 0, Colors.Length);
                            break;

                        //Set the next pixel count pixels in the color channel to the palette color indices defined by
                        //the pixel data provided directly after this command.Every byte in the pixel data, minus the
                        //padding byte at the very end(if it exists), provides a color index value to be copied to the
                        //row for the color channel using the full opacity value of 255 and the closest z-buffer value
                        //of 0 if the pixel is not the transparent color, or otherwise the no opacity value of 0 and the
                        //farthest z-buffer value of 255.
                        case 0x06:
                            Colors = new Color[PxCount];

                            for (int j = 0; j < PxCount; j++)
                            {
                                byte ColorIndex = Reader.ReadByte();
                                Colors[j] = Palette[ColorIndex];

                                Colors[j].A = (Palette[ColorIndex] != Color.Transparent) ? (byte)255 : (byte)0;
                                ZBuffer[j]  = (Palette[ColorIndex] != Color.Transparent) ? (byte)0 : (byte)255;
                            }
                            Texture.SetData <Color>(Colors, 0, Colors.Length);
                            break;
                        }
                    }
                    break;

                //Leave the next count rows in the color channel filled with the transparent color,
                //in the z-buffer channel filled with 255, and in the alpha channel filled with 0.
                case 0x04:
                    for (int j = 0; j < Count; j++)
                    {
                        Color[] Colors = new Color[Width];

                        for (int k = 0; k < Width; k++)
                        {
                            Colors[k]   = Color.Transparent;
                            Colors[k].A = 0;
                            ZBuffer[k]  = 255;
                        }

                        Texture.SetData <Color>(Colors, 0, Colors.Length);
                    }
                    break;

                case 0x05:
                    EndMarker = true;
                    break;
                }
            }
        }
Пример #4
0
        public SPR2Frame(FileReader Reader, GraphicsDevice Device, PALT Palette, uint SpriteVersion)
        {
            if (SpriteVersion == 1001)
            {
                Reader.ReadUInt32(); //Version
                Reader.ReadUInt32(); //Size
            }

            Width  = Reader.ReadUShort();
            Height = Reader.ReadUShort();

            m_Texture = new Texture2D(Device, Width, Height);

            ZBuffer = new byte[Width, Height];

            uint Flags = Reader.ReadUInt32();

            Reader.ReadUShort(); //Palette.

            TransparentColor = Palette[Reader.ReadUShort()];

            HasZBuffer      = (Flags & 0x02) == 0x02;
            HasAlphaChannel = (Flags & 0x04) == 0x04;

            YLocation = Reader.ReadUShort();
            XLocation = Reader.ReadUShort();

            bool EndMarker = false;

            int   CurrentRow = 0, CurrentColumn = 0;
            int   Padding = 0;
            Color Clr; //The current color.

            while (!EndMarker)
            {
                ushort Marker  = Reader.ReadUShort();
                int    Command = Marker >> 13;
                int    Count   = Marker & 0x1FFF;

                switch (Command)
                {
                //Fill this row with pixel data that directly follows; the count byte of the row command denotes
                //the size in bytes of the row's command/count bytes together with the supplied pixel data. In
                //the pixel data, each pixel command consists of a 3-bit/13-bit command/count header followed by a
                //block of pixel data padded to a multiple of 2 bytes. If the row is not filled completely, the
                //remainder is transparent. The pixel commands are:
                case 0x00:
                    Count -= 2;     //Row command + count bytes.

                    while (Count > 0)
                    {
                        ushort PxMarker  = Reader.ReadUShort();
                        var    PxCommand = PxMarker >> 13;
                        var    PxCount   = PxMarker & 0x1FFF;
                        Count -= 2;

                        switch (PxCommand)
                        {
                        //Set the next pixel count pixels in the z-buffer and color channels to the values defined
                        //by the pixel data provided directly after this command. Every group of 2 bytes in the pixel
                        //data provides a luminosity (z-buffer) or color index (color) value to be copied to the row
                        //for the z-buffer channel and color channel, respectively, in that order, using the full
                        //opacity value of 255 for each pixel that is not the transparent color.
                        case 0x01:
                            Count -= PxCount * 2;

                            while (PxCount > 0)
                            {
                                ZBuffer[CurrentColumn, CurrentRow] = Reader.ReadByte();

                                Clr = Palette[Reader.ReadByte()];
                                if (Clr != Color.Transparent)
                                {
                                    SetPixel(CurrentColumn, CurrentRow, Clr);
                                }
                                else
                                {
                                    SetPixel(CurrentColumn, CurrentRow, Color.Transparent);
                                }

                                PxCount--;
                                CurrentColumn++;
                            }

                            break;

                        //Set the next pixel count pixels in the z-buffer, color, and alpha channels to the values
                        //defined by the pixel data provided directly after this command. Every group of 3 bytes in
                        //the pixel data, minus the padding byte at the very end (if it exists), provides a luminosity
                        //(z-buffer and alpha) or color index (color) value to be copied to the row for the z-buffer,
                        //color, and alpha channels, respectively, in that order. The alpha channel data is grayscale
                        //in the range 0-31, and the z buffer is in range 0-255.
                        case 0x02:
                            Padding = PxCount % 2;
                            Count  -= (PxCount * 3) + Padding;

                            while (PxCount > 0)
                            {
                                ZBuffer[CurrentColumn, CurrentRow] = Reader.ReadByte();
                                Clr = Palette[Reader.ReadByte()];

                                //Read the alpha.
                                Clr.A = Reader.ReadByte();

                                SetPixel(CurrentColumn, CurrentRow, Clr);

                                PxCount--;
                                CurrentColumn++;
                            }

                            if (Padding != 0)
                            {
                                Reader.ReadByte();
                            }
                            break;

                        //Leave the next pixel count pixels in the color channel filled with the transparent color,
                        //in the z-buffer channel filled with 255, and in the alpha channel filled with 0. This pixel
                        //command has no pixel data.
                        case 0x03:
                            while (PxCount > 0)
                            {
                                //This is completely transparent regardless of whether the frame
                                //supports alpha.
                                SetPixel(CurrentColumn, CurrentRow, new Color(0, 0, 0, 0));

                                if (HasZBuffer)
                                {
                                    ZBuffer[CurrentColumn, CurrentRow] = 255;
                                }

                                PxCount--;
                                CurrentColumn++;
                            }
                            break;

                        //Set the next pixel count pixels in the color channel to the palette color indices defined by
                        //the pixel data provided directly after this command. Every byte in the pixel data, minus the
                        //padding byte at the very end(if it exists), provides a color index value to be copied to the
                        //row for the color channel using the full opacity value of 255 and the closest z-buffer value
                        //of 0 if the pixel is not the transparent color, or otherwise the no opacity value of 0 and the
                        //farthest z-buffer value of 255.
                        case 0x06:
                            Padding = PxCount % 2;
                            Count  -= PxCount + Padding;

                            while (PxCount > 0)
                            {
                                Clr = Palette[Reader.ReadByte()];
                                if (Clr != Color.Transparent)
                                {
                                    SetPixel(CurrentColumn, CurrentRow, Clr);
                                }
                                else
                                {
                                    SetPixel(CurrentColumn, CurrentRow, Color.Transparent);
                                }

                                /*if (HasZBuffer)
                                 * {
                                 *  if (Clr != Color.Transparent)
                                 *      Frame.ZBuffer.SetPixel(new Point(CurrentColumn, CurrentRow),
                                 *          Color.FromArgb(255, 1, 1, 1));
                                 *  else
                                 *      Frame.BitmapData.SetPixel(new Point(CurrentColumn, CurrentRow),
                                 *          Color.FromArgb(255, 255, 255, 255));
                                 * }*/

                                PxCount--;
                                CurrentColumn++;
                            }

                            if (Padding != 0)
                            {
                                Reader.ReadByte();
                            }
                            break;
                        }
                    }

                    CurrentRow++;
                    CurrentColumn = 0;

                    break;

                //Leave the next count rows in the color channel filled with the transparent color,
                //in the z-buffer channel filled with 255, and in the alpha channel filled with 0.
                case 0x04:
                    for (int i = 0; i < Count; i++)
                    {
                        for (int j = 0; j < Width - 1; j++)
                        {
                            SetPixel(CurrentColumn, CurrentRow, new Color(0, 0, 0, 0));

                            if (HasZBuffer)
                            {
                                ZBuffer[CurrentColumn, CurrentRow] = 255;
                            }

                            CurrentColumn++;
                        }

                        CurrentColumn = 0;
                        CurrentRow++;
                    }

                    CurrentColumn = 0;
                    break;

                case 0x05:
                    EndMarker = true;
                    break;
                }
            }
        }
Пример #5
0
        public SPRFrame(FileReader Reader, GraphicsDevice Device, PALT Palette, uint SPRVersion)
        {
            if (Version == 1001)
            {
                Version = Reader.ReadUInt32();
                Size    = Reader.ReadUInt32();
            }

            Reader.ReadUInt32(); //Reserved
            Height = Reader.ReadUShort();
            Width  = Reader.ReadUShort();

            Texture = new Texture2D(Device, Width, Height);

            for (ushort i = 0; i < Height; i++)
            {
                byte Cmd   = Reader.ReadByte();
                byte Count = Reader.ReadByte();

                switch (Cmd)
                {
                case 0x04:
                    for (byte j = 0; j < Count; j++)
                    {
                        byte    PxCmd   = Reader.ReadByte();
                        byte    PxCount = Reader.ReadByte();
                        Color[] Pixels;

                        switch (PxCmd)
                        {
                        case 0x01:
                            //Leave the next pixel count pixels as transparent. This pixel command has no pixel data.
                            Pixels = new Color[Count];
                            for (int k = 0; k < Count; k++)
                            {
                                Pixels[k] = Color.Transparent;
                            }

                            Texture.SetData <Color>(Pixels, 0, Count);
                            break;

                        case 0x02:
                            //Fill the next pixel count pixels with a single palette color.
                            //The pixel data is two bytes: the first byte denotes the palette color
                            //index, and the second byte is padding (which is always equal to the
                            //first byte but is ignored).
                            Pixels = new Color[Count];
                            byte ColorIndex = Reader.ReadByte();

                            for (int k = 0; k < Count; k++)
                            {
                                Pixels[k] = Palette[ColorIndex];
                            }

                            Texture.SetData <Color>(Pixels, 0, Count);
                            break;

                        case 0x03:
                            //Set the next pixel count pixels to the palette color indices defined by
                            //the pixel data provided directly after this command. Each byte in the pixel data,
                            //minus the padding byte at the very end (if it exists), is a color index value to
                            //be copied to the row.
                            Pixels = new Color[Count];

                            for (int k = 0; k < Count; k++)
                            {
                                Pixels[k] = Palette[Reader.ReadByte()];
                            }

                            Texture.SetData <Color>(Pixels, 0, Count);
                            break;

                        case 0x09:
                            //Leave the next count rows as transparent.
                            for (int k = 0; k < Count; k++)
                            {
                                Pixels = new Color[Width];
                                for (int l = 0; l < Width; l++)
                                {
                                    Pixels[l] = Color.Transparent;
                                }

                                Texture.SetData <Color>(Pixels, 0, Width);
                            }
                            break;
                        }
                    }
                    break;
                }
            }
        }
Пример #6
0
        private SPR2Frame GetSprite(int ID, PALT Palette)
        {
            FileReader Reader = new FileReader(new MemoryStream(m_Data), false);

            Reader.Seek(m_OffsetTable[ID]);

            return new SPR2Frame(Reader, m_Device, Palette, Version);
        }
Пример #7
0
        public SPR2Frame(FileReader Reader, GraphicsDevice Device, PALT Palette, uint SpriteVersion)
        {
            if(SpriteVersion == 1001)
            {
                Reader.ReadUInt32(); //Version
                Reader.ReadUInt32(); //Size
            }

            Width = Reader.ReadUShort();
            Height = Reader.ReadUShort();
            Texture = new Texture2D(Device, Width, Height);
            ZBuffer = new byte[Width * Height];

            uint Flags = Reader.ReadUInt32();
            Reader.ReadUShort(); //Palette.

            TransparentColor = Palette[Reader.ReadUShort()];

            HasZBuffer = (Flags & 0x02) == 0x02;
            HasAlphaChannel = (Flags & 0x04) == 0x04;

            XLocation = Reader.ReadUShort();
            YLocation = Reader.ReadUShort();

            bool EndMarker = false;

            while(!EndMarker)
            {
                ushort Marker = Reader.ReadUShort();
                var Command = Marker >> 13;
                var Count = Marker & 0x1FFF;

                switch(Command)
                {
                    //Fill this row with pixel data that directly follows; the count byte of the row command denotes
                    //the size in bytes of the row's command/count bytes together with the supplied pixel data. In
                    //the pixel data, each pixel command consists of a 3-bit/13-bit command/count header followed by a
                    //block of pixel data padded to a multiple of 2 bytes. If the row is not filled completely, the
                    //remainder is transparent. The pixel commands are:
                    case 0x00:
                        for(int i = 0; i < Count; i++)
                        {
                            ushort PxMarker = Reader.ReadUShort();
                            var PxCommand = PxMarker >> 13;
                            var PxCount = PxMarker & 0x1FFF;

                            Color[] Colors;

                            switch(PxCommand)
                            {
                                //Set the next pixel count pixels in the z-buffer and color channels to the values defined
                                //by the pixel data provided directly after this command. Every group of 2 bytes in the pixel
                                //data provides a luminosity (z-buffer) or color index (color) value to be copied to the row
                                //for the z-buffer channel and color channel, respectively, in that order, using the full
                                //opacity value of 255 for each pixel that is not the transparent color.
                                case 0x01:
                                    Colors = new Color[PxCount];

                                    for(int j = 0; j < PxCount; j++)
                                    {
                                        byte Luminosity = Reader.ReadByte();
                                        byte ColorIndex = Reader.ReadByte();
                                        Colors[j] = Palette[ColorIndex];
                                        ZBuffer[j] = Luminosity;
                                    }
                                    Texture.SetData<Color>(Colors, 0, Colors.Length);
                                    break;
                                    //Set the next pixel count pixels in the z-buffer, color, and alpha channels to the values
                                    //defined by the pixel data provided directly after this command. Every group of 3 bytes in
                                    //the pixel data, minus the padding byte at the very end (if it exists), provides a luminosity
                                    //(z-buffer and alpha) or color index (color) value to be copied to the row for the z-buffer,
                                    //color, and alpha channels, respectively, in that order. The alpha channel data is grayscale
                                    //in the range 0-31, and the z buffer is in range 0-255.
                                case 0x02:
                                    Colors = new Color[PxCount];

                                    for (int j = 0; j < PxCount; j++)
                                    {
                                        byte Luminosity = Reader.ReadByte();
                                        byte ColorIndex = Reader.ReadByte();
                                        byte Alpha = (byte)(Reader.ReadByte() * 8.2258064516129032258064516129032);
                                        Colors[j] = Palette[ColorIndex];
                                        Colors[j].A = Alpha;
                                        ZBuffer[j] = Luminosity;
                                    }
                                    Texture.SetData<Color>(Colors, 0, Colors.Length);
                                    break;
                                //Leave the next pixel count pixels in the color channel filled with the transparent color,
                                //in the z-buffer channel filled with 255, and in the alpha channel filled with 0. This pixel
                                //command has no pixel data.
                                case 0x03:
                                    Colors = new Color[PxCount];

                                    for (int j = 0; j < PxCount; j++)
                                    {
                                        Colors[j] = Color.Transparent;
                                        Colors[j].A = 0;
                                        ZBuffer[j] = 255;
                                    }
                                    Texture.SetData<Color>(Colors, 0, Colors.Length);
                                    break;
                                //Set the next pixel count pixels in the color channel to the palette color indices defined by
                                //the pixel data provided directly after this command.Every byte in the pixel data, minus the
                                //padding byte at the very end(if it exists), provides a color index value to be copied to the
                                //row for the color channel using the full opacity value of 255 and the closest z-buffer value
                                //of 0 if the pixel is not the transparent color, or otherwise the no opacity value of 0 and the
                                //farthest z-buffer value of 255.
                                case 0x06:
                                    Colors = new Color[PxCount];

                                    for (int j = 0; j < PxCount; j++)
                                    {
                                        byte ColorIndex = Reader.ReadByte();
                                        Colors[j] = Palette[ColorIndex];

                                        Colors[j].A = (Palette[ColorIndex] != Color.Transparent) ? (byte)255 : (byte)0;
                                        ZBuffer[j] = (Palette[ColorIndex] != Color.Transparent) ? (byte)0 : (byte)255;
                                    }
                                    Texture.SetData<Color>(Colors, 0, Colors.Length);
                                    break;
                            }
                        }
                        break;
                    //Leave the next count rows in the color channel filled with the transparent color,
                    //in the z-buffer channel filled with 255, and in the alpha channel filled with 0.
                    case 0x04:
                        for (int j = 0; j < Count; j++)
                        {
                            Color[] Colors = new Color[Width];

                            for (int k = 0; k < Width; k++)
                            {
                                Colors[k] = Color.Transparent;
                                Colors[k].A = 0;
                                ZBuffer[k] = 255;
                            }

                            Texture.SetData<Color>(Colors, 0, Colors.Length);
                        }
                        break;
                    case 0x05:
                        EndMarker = true;
                        break;
                }
            }
        }
Пример #8
0
        private void Init(Stream Data)
        {
            m_Reader = new FileReader(Data, true);

            string MagicNumber = m_Reader.ReadString(60);

            if (!MagicNumber.Equals("IFF FILE 2.5:TYPE FOLLOWED BY SIZE\0 JAMIE DOORNBOS & MAXIS 1\0", StringComparison.InvariantCultureIgnoreCase))
                throw new IFFException("MagicNumber was wrong - IFF.cs!");

            m_Reader.ReadUInt32(); //RSMP offset

            //Size of a chunk header is 76 bytes.
            while ((m_Reader.StreamLength - m_Reader.Position) > 76)
            {
                IFFChunk Chunk;

                if (m_Device != null)
                    Chunk = new IFFChunk(m_Reader, m_Device, this);
                else
                    Chunk = new IFFChunk(m_Reader, this);

                switch (Chunk.Type)
                {
                    case IFFChunkTypes.FBMP:
                        FBMP FBMPChunk = new FBMP(Chunk);
                        m_FBMPChunks.Add(Chunk.ID, FBMPChunk);
                        break;
                    case IFFChunkTypes.FWAV:
                        FWAV FWAVChunk = new FWAV(Chunk);
                        m_FWAVChunks.Add(Chunk.ID, FWAVChunk);
                        break;
                    case IFFChunkTypes.BMP_:
                        BMP_ BMPChunk = new BMP_(Chunk);
                        m_BMP_Chunks.Add(Chunk.ID, BMPChunk);
                        break;
                    case IFFChunkTypes.DGRP:
                        DGRP DGRPChunk = new DGRP(Chunk);
                        m_DGRPChunks.Add(Chunk.ID, DGRPChunk);
                        break;
                    case IFFChunkTypes.BCON:
                        BCON BCONChunk = new BCON(Chunk);
                        m_BCONChunks.Add(Chunk.ID, BCONChunk);
                        break;
                    case IFFChunkTypes.GLOB:
                        GLOB GlobChunk = new GLOB(Chunk);
                        m_GLOBChunks.Add(Chunk.ID, GlobChunk);
                        break;
                    case IFFChunkTypes.OBJD:
                        OBJD OBJDChunk = new OBJD(Chunk);
                        m_OBJDs.Add(OBJDChunk);
                        break;
                    case IFFChunkTypes.TTAs:
                        TTAs TTAsChunk = new TTAs(Chunk);
                        m_TTAsChunks.Add(Chunk.ID, TTAsChunk);
                        break;
                    case IFFChunkTypes.TTAB:
                        TTAB TTABChunk = new TTAB(Chunk);
                        TTABChunk.Type = Chunk.Type;
                        TTABChunk.ID = Chunk.ID;
                        m_TTABChunks.Add(Chunk.ID, TTABChunk);
                        break;
                    case IFFChunkTypes.TPRP:
                        TPRP TPRPChunk = new TPRP(Chunk);
                        m_TPRPChunks.Add(Chunk.ID, TPRPChunk);
                        break;
                    case IFFChunkTypes.STR:
                        STR STRChunk = new STR(Chunk);
                        m_STRChunks.Add(Chunk.ID, STRChunk);
                        break;
                    case IFFChunkTypes.BHAV:
                        BHAV BHAVChunk = new BHAV(Chunk);
                        m_BHAVChunks.Add(Chunk.ID, BHAVChunk);
                        break;
                    case IFFChunkTypes.OBJf:
                        OBJf OBJfChunk = new OBJf(Chunk);
                        m_OBJfChunks.Add(Chunk.ID, OBJfChunk);
                        break;
                    case IFFChunkTypes.FCNS:
                        FCNS FCNSChunk = new FCNS(Chunk);
                        m_FCNSChunks.Add(Chunk.ID, FCNSChunk);
                        break;
                    case IFFChunkTypes.SPR:
                        SPR SPRChunk = new SPR(Chunk);
                        m_SPRChunks.Add(Chunk.ID, SPRChunk);
                        break;
                    case IFFChunkTypes.SPR2:
                        SPR2 SPR2Chunk = new SPR2(Chunk);
                        m_SPR2Chunks.Add(Chunk.ID, SPR2Chunk);
                        break;
                    case IFFChunkTypes.PALT:
                        PALT PALTChunk = new PALT(Chunk);
                        m_PALTChunks.Add(Chunk.ID, PALTChunk);
                        break;
                    case IFFChunkTypes.CTSS:
                        CTSS CTSSChunk = new CTSS(Chunk);
                        m_CTSSChunks.Add(Chunk.ID, CTSSChunk);
                        break;
                    case IFFChunkTypes.CST:
                        CST CSTChunk = new CST(Chunk);
                        m_CSTChunks.Add(Chunk.ID, CSTChunk);
                        break;
                }
            }
        }
Пример #9
0
        public SPRFrame(FileReader Reader, GraphicsDevice Device, PALT Palette, uint SPRVersion)
        {
            if (Version == 1001)
            {
                Version = Reader.ReadUInt32();
                Size    = Reader.ReadUInt32();
            }

            Reader.ReadUInt32(); //Reserved
            Height = Reader.ReadUShort();
            Width  = Reader.ReadUShort();

            m_Texture = new Texture2D(Device, Width, Height);

            bool  quit = false;
            byte  Clr  = 0;
            Color Transparent;
            int   CurrentRow = 0, CurrentColumn = 0;

            byte PixCommand, PixCount = 0;

            while (quit == false)
            {
                byte RowCommand = Reader.ReadByte();
                byte RowCount   = Reader.ReadByte();

                switch (RowCommand)
                {
                case 0x00:     //Start marker; the count byte is ignored.
                    break;

                //Fill this row with pixel data that directly follows; the count byte of the row command denotes the
                //size in bytes of the row and pixel data.
                case 0x04:
                    RowCount     -= 2;
                    CurrentColumn = 0;

                    while (RowCount > 0)
                    {
                        PixCommand = Reader.ReadByte();
                        PixCount   = Reader.ReadByte();
                        RowCount  -= 2;

                        switch (PixCommand)
                        {
                        case 1:         //Leave the next pixel count pixels as transparent.
                            for (int j = CurrentColumn; j < (CurrentColumn + PixCount); j++)
                            {
                                SetPixel(j, CurrentRow, Color.Transparent);
                            }

                            CurrentColumn += PixCount;

                            break;

                        case 2:         //Fill the next pixel count pixels with a palette color.
                            //The pixel data is two bytes: the first byte denotes the palette color index, and the
                            //second byte is padding (which is always equal to the first byte but is ignored).
                            Clr = Reader.ReadByte();
                            Reader.ReadByte();         //Padding
                            RowCount -= 2;

                            for (int j = CurrentColumn; j < (CurrentColumn + PixCount); j++)
                            {
                                SetPixel(j, CurrentRow, Palette[Clr]);
                            }

                            CurrentColumn += PixCount;

                            break;

                        case 3:         //Set the next pixel count pixels to the palette color indices defined by the
                            //pixel data provided directly after this command.

                            byte Padding = (byte)(PixCount % 2);

                            if (Padding != 0)
                            {
                                RowCount -= (byte)(PixCount + Padding);
                            }
                            else
                            {
                                RowCount -= PixCount;
                            }

                            for (int j = CurrentColumn; j < (CurrentColumn + PixCount); j++)
                            {
                                SetPixel(j, CurrentRow, Palette[Reader.ReadByte()]);
                            }

                            CurrentColumn += PixCount;

                            if (Padding != 0)
                            {
                                Reader.ReadByte();
                            }

                            break;
                        }
                    }

                    CurrentRow++;

                    break;

                case 0x05:     //End marker. The count byte is always 0, but may be ignored.

                    //Some sprites don't have these, so read them using ReadBytes(), which
                    //simply returns an empty array if the stream couldn't be read.
                    Reader.ReadBytes(2);     //PixCommand and PixCount.

                    quit = true;
                    break;

                case 0x09:     //Leave the next count rows as transparent.
                    PixCommand = Reader.ReadByte();
                    PixCount   = Reader.ReadByte();

                    for (int i = 0; i < RowCount; i++)
                    {
                        for (int j = CurrentColumn; j < Width; j++)
                        {
                            SetPixel(j, CurrentRow, Color.Transparent);
                        }

                        CurrentRow++;
                    }

                    break;

                case 0x10:     //Start marker, equivalent to 0x00; the count byte is ignored.
                    break;
                }
            }
        }
Пример #10
0
        public SPRFrame(FileReader Reader, GraphicsDevice Device, PALT Palette, uint SPRVersion)
        {
            if (Version == 1001)
            {
                Version = Reader.ReadUInt32();
                Size = Reader.ReadUInt32();
            }

            Reader.ReadUInt32(); //Reserved
            Height = Reader.ReadUShort();
            Width = Reader.ReadUShort();

            Texture = new Texture2D(Device, Width, Height);

            for(ushort i = 0; i < Height; i++)
            {
                byte Cmd = Reader.ReadByte();
                byte Count = Reader.ReadByte();

                switch(Cmd)
                {
                    case 0x04:
                        for(byte j = 0; j < Count; j++)
                        {
                            byte PxCmd = Reader.ReadByte();
                            byte PxCount = Reader.ReadByte();
                            Color[] Pixels;

                            switch(PxCmd)
                            {
                                case 0x01:
                                    //Leave the next pixel count pixels as transparent. This pixel command has no pixel data.
                                    Pixels = new Color[Count];
                                    for (int k = 0; k < Count; k++)
                                        Pixels[k] = Color.Transparent;

                                    Texture.SetData<Color>(Pixels, 0, Count);
                                    break;
                                case 0x02:
                                    //Fill the next pixel count pixels with a single palette color.
                                    //The pixel data is two bytes: the first byte denotes the palette color
                                    //index, and the second byte is padding (which is always equal to the
                                    //first byte but is ignored).
                                    Pixels = new Color[Count];
                                    byte ColorIndex = Reader.ReadByte();

                                    for (int k = 0; k < Count; k++)
                                        Pixels[k] = Palette[ColorIndex];

                                    Texture.SetData<Color>(Pixels, 0, Count);
                                    break;
                                case 0x03:
                                    //Set the next pixel count pixels to the palette color indices defined by
                                    //the pixel data provided directly after this command. Each byte in the pixel data,
                                    //minus the padding byte at the very end (if it exists), is a color index value to
                                    //be copied to the row.
                                    Pixels = new Color[Count];

                                    for (int k = 0; k < Count; k++)
                                        Pixels[k] = Palette[Reader.ReadByte()];

                                    Texture.SetData<Color>(Pixels, 0, Count);
                                    break;
                                case 0x09:
                                    //Leave the next count rows as transparent.
                                    for (int k = 0; k < Count; k++)
                                    {
                                        Pixels = new Color[Width];
                                        for (int l = 0; l < Width; l++)
                                            Pixels[l] = Color.Transparent;

                                        Texture.SetData<Color>(Pixels, 0, Width);
                                    }
                                    break;
                            }
                        }
                        break;
                }
            }
        }