Exemplo n.º 1
0
        public void read(Reader reader)
        {
            reader.ReadInt16(); // "BM"
            reader.ReadInt32(); // totalFileSize
            reader.ReadInt32(); // Unused
            int pixelPos = reader.ReadInt32();

            reader.seek(14 + 4, System.IO.SeekOrigin.Begin);

            width  = reader.ReadByte();
            width |= reader.ReadByte() << 8;
            width |= reader.ReadByte() << 16;
            width |= reader.ReadByte() << 24;

            height  = reader.ReadByte();
            height |= reader.ReadByte() << 8;
            height |= reader.ReadByte() << 16;
            height |= reader.ReadByte() << 24;

            reader.BaseStream.Position += sizeof(ushort);
            bool indexed = reader.ReadUInt16() <= 8; //bpp

            if (!indexed)
            {
                throw new Exception("RSDK-Formatted Bitmap files must be indexed!");
            }

            reader.BaseStream.Position += 4 * sizeof(int);
            int clrCount = reader.ReadInt32(); // how many colours used

            reader.seek(14 + 40, System.IO.SeekOrigin.Begin);

            for (int c = 0; c < clrCount; c++)
            {
                palette[c].B = reader.ReadByte();
                palette[c].G = reader.ReadByte();
                palette[c].R = reader.ReadByte();
                reader.ReadByte(); // unused
            }

            long expectedPixelPos = (reader.BaseStream.Length - height * width);

            if (pixelPos != expectedPixelPos)
            {
                throw new Exception("RSDK-Formatted Bitmap files must end with the pixel data!");
            }

            // This is how RSDK does it but there's a small chance it could maybe be wrong
            reader.seek(expectedPixelPos, System.IO.SeekOrigin.Begin);

            pixels = new byte[width * height];
            int gfxPos = width * (height - 1);

            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    pixels[gfxPos++] = reader.ReadByte();
                }
                gfxPos -= 2 * width;
            }

            reader.Close();
        }
Exemplo n.º 2
0
            public void ReadGIFData(Reader reader)
            {
                int eighthHeight  = Height >> 3;
                int quarterHeight = Height >> 2;
                int halfHeight    = Height >> 1;
                int bitsWidth     = 0;
                int width         = 0;

                Entry[] codeTable = new Entry[0x10000];
                ImageData = new byte[Width * Height + 1];

                for (int i = 0; i < 0x10000; i++)
                {
                    codeTable[i] = new Entry();
                }

                // Get frame
                byte type, subtype, temp;

                type = reader.ReadByte();

                while (type != 0)
                {
                    bool tableFull, interlaced;
                    int  codeSize, initCodeSize;
                    int  clearCode, eoiCode, emptyCode;
                    int  codeToAddFrom, mark, str_len = 0, frm_off = 0;
                    uint currentCode;

                    switch (type)
                    {
                    // Extension
                    case 0x21:
                        subtype = reader.ReadByte();
                        switch (subtype)
                        {
                        // Graphics Control Extension
                        case 0xF9:
                            reader.ReadBytes(0x06);
                            // temp = reader.ReadByte();  // Block Size [byte] (always 0x04)
                            // temp = reader.ReadByte();  // Packed Field [byte] //
                            // temp16 = reader.ReadUInt16(); // Delay Time [short] //
                            // temp = reader.ReadByte();  // Transparent Color Index? [byte] //
                            // temp = reader.ReadByte();  // Block Terminator [byte] //
                            break;

                        // Plain Text Extension
                        case 0x01:
                        // Comment Extension
                        case 0xFE:
                        // Application Extension
                        case 0xFF:
                            temp = reader.ReadByte();         // Block Size
                                                              // Continue until we run out of blocks
                            while (temp != 0)
                            {
                                // Read block
                                reader.ReadBytes(temp);
                                temp = reader.ReadByte();         // next block Size
                            }
                            break;

                        default:
                            Console.WriteLine("GIF LOAD FAILED");
                            return;
                        }
                        break;

                    // Image descriptor
                    case 0x2C:
                        // temp16 = reader.ReadUInt16(); // Destination X
                        // temp16 = reader.ReadUInt16(); // Destination Y
                        // temp16 = reader.ReadUInt16(); // Destination Width
                        // temp16 = reader.ReadUInt16(); // Destination Height
                        reader.ReadBytes(8);
                        temp = reader.ReadByte();        // Packed Field [byte]

                        // If a local color table exists,
                        if ((temp & 0x80) != 0)
                        {
                            int size = 2 << (temp & 0x07);
                            // Load all colors
                            for (int i = 0; i < size; i++)
                            {
                                byte r = reader.ReadByte();
                                byte g = reader.ReadByte();
                                byte b = reader.ReadByte();
                                FramePalette.Add(Color.FromArgb(r, g, b));
                            }
                        }

                        interlaced = (temp & 0x40) == 0x40;
                        if (interlaced)
                        {
                            bitsWidth = 0;
                            while (width != 0)
                            {
                                width >>= 1;
                                bitsWidth++;
                            }
                            width = Width - 1;
                        }

                        codeSize = reader.ReadByte();

                        clearCode = 1 << codeSize;
                        eoiCode   = clearCode + 1;
                        emptyCode = eoiCode + 1;

                        codeSize++;
                        initCodeSize = codeSize;

                        // Init table
                        for (int i = 0; i <= eoiCode; i++)
                        {
                            codeTable[i].Length = 1;
                            codeTable[i].Prefix = 0xFFF;
                            codeTable[i].Suffix = (byte)i;
                        }

                        blockLength    = 0;
                        bitCache       = 0b00000000;
                        bitCacheLength = 0;
                        tableFull      = false;

                        currentCode = ReadCode(reader, codeSize);

                        codeSize  = initCodeSize;
                        emptyCode = eoiCode + 1;
                        tableFull = false;

                        Entry entry = new Entry();
                        entry.Suffix = 0;

                        while (blockLength != 0)
                        {
                            codeToAddFrom = -1;
                            mark          = 0;

                            if (currentCode == clearCode)
                            {
                                codeSize  = initCodeSize;
                                emptyCode = eoiCode + 1;
                                tableFull = false;
                            }
                            else if (!tableFull)
                            {
                                codeTable[emptyCode].Length = (ushort)(str_len + 1);
                                codeTable[emptyCode].Prefix = (ushort)currentCode;
                                codeTable[emptyCode].Suffix = entry.Suffix;
                                emptyCode++;

                                // Once we reach highest code, increase code size
                                if ((emptyCode & (emptyCode - 1)) == 0)
                                {
                                    mark = 1;
                                }
                                else
                                {
                                    mark = 0;
                                }

                                if (emptyCode >= 0x1000)
                                {
                                    mark      = 0;
                                    tableFull = true;
                                }
                            }

                            currentCode = ReadCode(reader, codeSize);

                            if (currentCode == clearCode)
                            {
                                continue;
                            }
                            if (currentCode == eoiCode)
                            {
                                return;
                            }
                            if (mark == 1)
                            {
                                codeSize++;
                            }

                            entry   = codeTable[currentCode];
                            str_len = entry.Length;

                            while (true)
                            {
                                int p = frm_off + entry.Length - 1;
                                if (interlaced)
                                {
                                    int row = p >> bitsWidth;
                                    if (row < eighthHeight)
                                    {
                                        p = (p & width) + ((((row) << 3) + 0) << bitsWidth);
                                    }
                                    else if (row < quarterHeight)
                                    {
                                        p = (p & width) + ((((row - eighthHeight) << 3) + 4) << bitsWidth);
                                    }
                                    else if (row < halfHeight)
                                    {
                                        p = (p & width) + ((((row - quarterHeight) << 2) + 2) << bitsWidth);
                                    }
                                    else
                                    {
                                        p = (p & width) + ((((row - halfHeight) << 1) + 1) << bitsWidth);
                                    }
                                }

                                ImageData[p] = entry.Suffix;
                                if (entry.Prefix != 0xFFF)
                                {
                                    entry = codeTable[entry.Prefix];
                                }
                                else
                                {
                                    break;
                                }
                            }
                            frm_off += str_len;
                            if (currentCode < emptyCode - 1 && !tableFull)
                            {
                                codeTable[emptyCode - 1].Suffix = entry.Suffix;
                            }
                        }
                        break;
                    }

                    type = reader.ReadByte();

                    if (type == 0x3B)
                    {
                        break;
                    }
                }
            }
Exemplo n.º 3
0
 public ParallaxValues(Reader reader)
 {
     RHSpeed = reader.ReadByte();
     CHSpeed = reader.ReadByte();
     Deform  = reader.ReadByte();
 }
Exemplo n.º 4
0
 public UnknownValues(Reader reader)
 {
     Value1 = reader.ReadByte();
     Value2 = reader.ReadByte();
     Value3 = reader.ReadByte();
 }
Exemplo n.º 5
0
        public Level(Reader reader)
        {
            Title = reader.ReadRSDKString();
            Console.WriteLine(Title);
            byte[] buffer = new byte[5];
            reader.Read(displayBytes, 0, 5); //Waste 5 bytes, I don't care about them right now.
            //The first 4 bytes are loaded into StageSystem.ActiveTileLayers. 5th byte is tLayerMidPoint.
            //If you want to know the values then look at the values for "DisplayBytes"
            reader.Read(buffer, 0, 2); //Read size

            width = 0; height = 0;


            // Map width in 128 pixel units
            // In RSDKv2, it's one byte long
            width  = buffer[0];
            height = buffer[1];

            MapLayout = new ushort[height][];
            for (int i = 0; i < height; i++)
            {
                MapLayout[i] = new ushort[width];
            }

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    // 128x128 Block number is 16-bit
                    // Big-Endian in RSDKv2 and RSDKv3
                    reader.Read(buffer, 0, 2); //Read size
                    MapLayout[y][x] = (ushort)(buffer[1] + (buffer[0] << 8));
                }
            }


            // Read number of object types, Only RSDKv2 and RSDKv3 support this feature
            int ObjTypeCount = reader.ReadByte();

            for (int n = 0; n < ObjTypeCount; n++)
            {
                string name = reader.ReadRSDKString();

                objectTypeNames.Add(name);
                Console.WriteLine(name);
            }
            // Read object data

            int ObjCount = 0;

            // 2 bytes, big-endian, unsigned
            ObjCount  = reader.ReadByte() << 8;
            ObjCount |= reader.ReadByte();

            int obj_type    = 0;
            int obj_subtype = 0;
            int obj_xPos    = 0;
            int obj_yPos    = 0;

            for (int n = 0; n < ObjCount; n++)
            {
                // Object type, 1 byte, unsigned
                obj_type = reader.ReadByte();
                // Object subtype, 1 byte, unsigned
                obj_subtype = reader.ReadByte();

                // X Position, 2 bytes, big-endian, signed
                obj_xPos  = reader.ReadSByte() << 8;
                obj_xPos |= reader.ReadByte();

                // Y Position, 2 bytes, big-endian, signed
                obj_yPos  = reader.ReadSByte() << 8;
                obj_yPos |= reader.ReadByte();

                // Add object
                objects.Add(new Object(obj_type, obj_subtype, obj_xPos, obj_yPos));
            }
            reader.Close();
        }
Exemplo n.º 6
0
            public void read(Reader reader, ushort width, ushort height)
            {
                int frameSize = reader.ReadInt32();

                byte[] gifData = new byte[frameSize + 13];

                // Write Header
                gifData[0] = (byte)'G';
                gifData[1] = (byte)'I';
                gifData[2] = (byte)'F';
                gifData[3] = (byte)'8';
                gifData[4] = (byte)'9';
                gifData[5] = (byte)'a';

                byte[] bytes = BitConverter.GetBytes(width);
                gifData[6] = bytes[0];
                gifData[7] = bytes[1];

                bytes      = BitConverter.GetBytes(height);
                gifData[8] = bytes[0];
                gifData[9] = bytes[1];

                // 1 == hasColours, 6 == paletteSize of 128, 7 == 8bpp
                gifData[10] = (1 << 7) | (6 << 4) | 6;
                gifData[11] = 0;
                gifData[12] = 0;

                // Read Data
                reader.Read(gifData, 13, (int)frameSize);

                List <Color> globalPalette = new List <Color>();
                List <Color> localPalette  = new List <Color>();

                using (var gifStream = new System.IO.MemoryStream(gifData))
                {
                    using (var gifReader = new Reader(gifStream))
                    {
                        reader.BaseStream.Position = 13;
                        for (int i = 0; i < 0x80; ++i)
                        {
                            byte r = reader.ReadByte();
                            byte g = reader.ReadByte();
                            byte b = reader.ReadByte();
                            globalPalette.Add(Color.FromArgb(r, g, b));
                        }

                        byte buffer = reader.ReadByte();
                        while (buffer != (byte)',')
                        {
                            buffer = reader.ReadByte();
                        }
                        reader.ReadUInt16();
                        reader.ReadUInt16();
                        reader.ReadUInt16();
                        reader.ReadUInt16();
                        byte info = reader.ReadByte();
                        if (info >> 7 == 1)
                        {
                            for (int i = 0; i < 0x80; ++i)
                            {
                                byte r = reader.ReadByte();
                                byte g = reader.ReadByte();
                                byte b = reader.ReadByte();
                                localPalette.Add(Color.FromArgb(r, g, b));
                            }
                        }
                    }
                }

                using (var gifStream = new System.IO.MemoryStream(gifData))
                    image = Image.FromStream(gifStream);

                // ColorPalette pal = new ColorPalette();
                // pal.Entries[0]]

                // image.Palette = pal;

                videoFilePos += frameSize;
                reader.BaseStream.Position = videoFilePos;
            }
Exemplo n.º 7
0
        public GraphicsImage(Reader reader, bool dcGFX = false)
        {
            if (dcGFX)
            {
                reader.ReadByte();
            }

            width  = (ushort)(reader.ReadByte() << 8);
            width |= reader.ReadByte();

            height  = (ushort)(reader.ReadByte() << 8);
            height |= reader.ReadByte();

            // Create image
            gfxImage = new Bitmap(width, height, PixelFormat.Format8bppIndexed);

            ColorPalette cp = gfxImage.Palette;

            // Read & Process palette
            for (int i = 0; i < 255; i++)
            {
                GFXpal[i].R   = reader.ReadByte();
                GFXpal[i].G   = reader.ReadByte();
                GFXpal[i].B   = reader.ReadByte();
                cp.Entries[i] = Color.FromArgb(255, GFXpal[i].R, GFXpal[i].G, GFXpal[i].B);
            }
            gfxImage.Palette = cp;

            //Read Image Data
            byte[] buf      = new byte[3];
            bool   finished = false;
            int    cnt      = 0;
            int    loop     = 0;

            data = new byte[(width * height) + 1];

            while (!finished)
            {
                buf[0] = reader.ReadByte();
                if (buf[0] == 255)
                {
                    buf[1] = reader.ReadByte();
                    if (buf[1] == 255)
                    {
                        finished = true;
                        break;
                    }
                    else
                    {
                        buf[2] = reader.ReadByte();
                        loop   = 0;

                        // Repeat value needs to decreased by one to decode
                        // the graphics from the Dreamcast demo
                        if (dcGFX)
                        {
                            buf[2]--;
                        }

                        while (loop < buf[2] && !reader.IsEof)
                        {
                            data[cnt++] = buf[1];
                            loop++;
                        }
                    }
                }
                else
                {
                    data[cnt++] = buf[0];
                }
            }

            //Console.Write("file Length = " + reader.BaseStream.Length + " file pos = " + reader.Pos + " data remaining = " + (reader.BaseStream.Length - reader.Pos));

            // Write data to image
            int pixel = 0;

            for (int h = 0; h < height; h++)
            {
                for (int w = 0; w < width; w++)
                {
                    BitmapData ImgData = gfxImage.LockBits(new Rectangle(new Point(w, h), new Size(1, 1)), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
                    byte       b       = System.Runtime.InteropServices.Marshal.ReadByte(ImgData.Scan0);
                    System.Runtime.InteropServices.Marshal.WriteByte(ImgData.Scan0, (data[pixel]));
                    gfxImage.UnlockBits(ImgData);
                    pixel++;
                }
            }

            reader.Close();
        }
Exemplo n.º 8
0
        public void read(Reader reader, bool skipHeader = false, int clrCnt = 0x80)
        {
            #region Header
            if (!skipHeader)
            {
                reader.seek(6, System.IO.SeekOrigin.Begin); // GIF89a

                width  = reader.ReadByte();
                width |= (ushort)(reader.ReadByte() << 8);

                height  = reader.ReadByte();
                height |= (ushort)(reader.ReadByte() << 8);

                byte info = reader.ReadByte(); // Palette Size
                clrCnt = (info & 0x7) + 1;
                if (clrCnt > 0)
                {
                    clrCnt = 1 << clrCnt;
                }
                reader.ReadByte(); // background colour index
                reader.ReadByte(); // unused

                if (clrCnt != 0x100)
                {
                    throw new Exception("RSDK-Formatted Gif files must use 256 colours!");
                }
            }

            for (int c = 0; c < clrCnt; ++c)
            {
                palette[c].R = reader.ReadByte();
                palette[c].G = reader.ReadByte();
                palette[c].B = reader.ReadByte();
            }
            #endregion

            #region Blocks
            byte blockType = reader.ReadByte();
            while (blockType != 0 && blockType != ';')
            {
                switch (blockType)
                {
                default:     // Unknown
                    Console.WriteLine($"Unknown Block Type ({blockType})");
                    break;

                case (byte)'!':     // Extension
                {
                    byte extensionType = reader.ReadByte();
                    switch (extensionType)
                    {
                    case 0xF9:             // Graphics Control Extension
                    {
                        int    blockSize        = reader.ReadByte();
                        byte   disposalFlag     = reader.ReadByte();
                        ushort frameDelay       = reader.ReadUInt16();
                        byte   transparentIndex = reader.ReadByte();
                        reader.ReadByte();                 // terminator
                    }
                    break;

                    case 0x01:             // Plain Text Extension
                    case 0xFE:             // Comment Extension
                    case 0xFF:             // Application Extension
                    {
                        int blockSize = reader.ReadByte();
                        while (blockSize != 0)
                        {
                            // Read block
                            reader.BaseStream.Position += blockSize;
                            blockSize = reader.ReadByte();                 // next block Size, if its 0 we know its the end of block
                        }
                    }
                    break;

                    default:             // Unknown
                        Console.WriteLine($"Unknown Extension Type ({extensionType})");
                        return;
                    }
                }
                break;

                case (byte)',':     // Image descriptor
                {
                    int left   = reader.ReadUInt16();
                    int top    = reader.ReadUInt16();
                    int right  = reader.ReadUInt16();
                    int bottom = reader.ReadUInt16();

                    byte info2      = reader.ReadByte();
                    bool interlaced = (info2 & 0x40) != 0;
                    if (info2 >> 7 == 1)
                    {
                        for (int c = 0x80; c < 0x100; ++c)
                        {
                            palette[c].R = reader.ReadByte();
                            palette[c].G = reader.ReadByte();
                            palette[c].B = reader.ReadByte();
                        }
                    }

                    readPictureData(width, height, interlaced, reader);
                }
                break;
                }

                blockType = reader.ReadByte();
            }
            #endregion

            if (!skipHeader)
            {
                reader.Close();
            }
        }
Exemplo n.º 9
0
            public BGLayer(Reader reader)
            {
                width         = reader.ReadByte();
                height        = reader.ReadByte();
                DrawLayer     = reader.ReadByte();
                Behaviour     = reader.ReadByte();
                ConstantSpeed = reader.ReadByte();
                RelativeSpeed = reader.ReadByte();

                byte[] buf      = new byte[3];
                bool   finished = false;
                int    cnt      = 0;
                int    loop     = 0;

                LineIndexes = new byte[height * 128];

                while (!finished)
                {
                    buf[0] = reader.ReadByte();
                    if (buf[0] == 255)
                    {
                        buf[1] = reader.ReadByte();
                        if (buf[1] == 255)
                        {
                            finished = true;
                            break;
                        }
                        else
                        {
                            buf[2] = (byte)(reader.ReadByte() - 1);
                            loop   = 0;

                            while (loop < buf[2] && !reader.IsEof)
                            {
                                LineIndexes[cnt++] = buf[1];
                                loop++;
                            }
                        }
                    }
                    else
                    {
                        LineIndexes[cnt++] = buf[0];
                    }
                }

                byte[] buffer = new byte[2];

                MapLayout = new ushort[height][];
                for (int m = 0; m < height; m++)
                {
                    MapLayout[m] = new ushort[width];
                }
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        reader.Read(buffer, 0, 2); //Read size
                        MapLayout[y][x] = (ushort)(buffer[1] + (buffer[0] << 8));
                    }
                }
            }
Exemplo n.º 10
0
        public Scene(Reader reader)
        {
            Title = reader.ReadRSDKString();
            //Console.WriteLine(Title);
            byte[] buffer = new byte[5];

            ActiveLayer0 = reader.ReadByte();
            ActiveLayer1 = reader.ReadByte();
            ActiveLayer2 = reader.ReadByte();
            ActiveLayer3 = reader.ReadByte();
            Midpoint     = reader.ReadByte();

            reader.Read(buffer, 0, 2); //Read size

            width = 0; height = 0;


            // Map width in 128 pixel units
            // In RSDKv2, it's one byte long
            width  = buffer[0];
            height = buffer[1];

            MapLayout = new ushort[height][];
            for (int i = 0; i < height; i++)
            {
                MapLayout[i] = new ushort[width];
            }

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    // 128x128 Block number is 16-bit
                    // Big-Endian in RSDKv2 and RSDKv3
                    reader.Read(buffer, 0, 2); //Read size
                    MapLayout[y][x] = (ushort)(buffer[1] + (buffer[0] << 8));
                }
            }


            // Read number of object types, Only RSDKv1 and RSDKv2 support this feature
            int ObjTypeCount = reader.ReadByte();

            for (int n = 0; n < ObjTypeCount; n++)
            {
                string name = reader.ReadRSDKString();

                objectTypeNames.Add(name);
            }
            // Read object data

            int ObjCount = 0;

            // 2 bytes, big-endian, unsigned
            ObjCount  = reader.ReadByte() << 8;
            ObjCount |= reader.ReadByte();

            Object.cur_id = 0;

            for (int n = 0; n < ObjCount; n++)
            {
                // Add object
                objects.Add(new Object(reader));
            }
            reader.Close();
        }
Exemplo n.º 11
0
        public void read(Reader reader, bool dcVer = false)
        {
            if (dcVer)
            {
                reader.ReadByte();
            }

            width  = (ushort)(reader.ReadByte() << 8);
            width |= reader.ReadByte();

            height  = (ushort)(reader.ReadByte() << 8);
            height |= reader.ReadByte();

            // Read & Process palette
            for (int i = 0; i < 255; i++)
            {
                palette[i].R = reader.ReadByte();
                palette[i].G = reader.ReadByte();
                palette[i].B = reader.ReadByte();
            }

            // Read Pixels
            pixels = new byte[width * height];
            byte[] buf = new byte[3];
            int    pos = 0;

            while (true)
            {
                buf[0] = reader.ReadByte();
                if (buf[0] == 0xFF)
                {
                    buf[1] = reader.ReadByte();
                    if (buf[1] != 0xFF)
                    {
                        buf[2] = reader.ReadByte();
                        byte val = buf[1];
                        int  cnt = buf[2];
                        if (dcVer)
                        {
                            cnt--;
                        }
                        for (int c = 0; c < cnt; ++c)
                        {
                            pixels[pos++] = val;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    pixels[pos++] = buf[0];
                }
            }


            reader.Close();
        }
Exemplo n.º 12
0
            public VideoFrame(Reader reader, ushort width, ushort height)
            {
                Width       = width;
                Height      = height;
                startOffset = (int)reader.Pos;
                ImageData   = new byte[Width * Height];

                FilePos = (uint)(reader.ReadByte() + (reader.ReadByte() << 8) + (reader.ReadByte() << 16) + (reader.ReadByte() << 24));//reader.ReadUInt32();

                for (int i = 0; i < 128; i++)
                {
                    Color c;
                    byte  r = reader.ReadByte(); //r
                    byte  g = reader.ReadByte(); //g
                    byte  b = reader.ReadByte(); //b
                    c = Color.FromArgb(255, r, g, b);
                    //Console.WriteLine("Colour " + i + " = " + c.R + " " + c.G + " " + c.B);
                    FramePalette.Add(c);
                }

                bool Next = false;

                while (!Next)
                {
                    byte tmp = reader.ReadByte();
                    idkMan.Add(tmp);
                    //Console.WriteLine("idk lol = " + tmp);
                    if (tmp == 44)
                    {
                        Next = true;
                    }                               // AKA ','
                }

                ImageLeft   = reader.ReadUInt16();
                ImageTop    = reader.ReadUInt16();
                ImageWidth  = reader.ReadUInt16();
                ImageHeight = reader.ReadUInt16();

                PaletteType = reader.ReadByte();

                //Console.WriteLine("Palette Type = " + PaletteType);

                isInterlaced = (uint)PaletteType << 25 >> 31;

                //Console.WriteLine("Interlaced? = " + isInterlaced);

                //Console.WriteLine("Use full Palette = " + (PaletteType >> 7));

                FullPallete = PaletteType >> 7 == 1;

                if (FullPallete) // Use extra colours?
                {
                    for (int i = 128; i < 256; i++)
                    {
                        Color c;
                        byte  r = reader.ReadByte(); //r
                        byte  g = reader.ReadByte(); //g
                        byte  b = reader.ReadByte(); //b
                        c = Color.FromArgb(255, r, g, b);
                        //Console.WriteLine("(Extra) Colour " + i + " = " + c.R + "," + c.G + "," + c.B);
                        FramePalette.Add(c);
                    }
                }

                ReadGIFData(reader);
                Console.WriteLine("Loaded Video Frame!");
                //reader.BaseStream.Position = FilePos + 6;
                endOffset = (int)reader.Pos;
            }
Exemplo n.º 13
0
        public void read(Reader reader)
        {
            title = reader.readRSDKString();

            activeLayer0  = (ActiveLayers)reader.ReadByte();
            activeLayer1  = (ActiveLayers)reader.ReadByte();
            activeLayer2  = (ActiveLayers)reader.ReadByte();
            activeLayer3  = (ActiveLayers)reader.ReadByte();
            layerMidpoint = (LayerMidpoints)reader.ReadByte();

            // Map width/height in 128 pixel units
            // In RSDKv2 it's one byte long

            width  = reader.ReadByte();
            height = reader.ReadByte();

            layout = new ushort[height][];
            for (int i = 0; i < height; i++)
            {
                layout[i] = new ushort[width];
            }

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    // 128x128 Block number is 16-bit
                    // Big-Endian in RSDKv2
                    layout[y][x]  = (ushort)(reader.ReadByte() << 8);
                    layout[y][x] |= reader.ReadByte();
                }
            }

            // Read number of object types
            int objectTypeCount = reader.ReadByte();

            objectTypeNames.Clear();
            for (int n = 0; n < objectTypeCount; n++)
            {
                objectTypeNames.Add(reader.readRSDKString());
            }

            // Read entities

            // 2 bytes, big-endian, unsigned
            int entityCount = reader.ReadByte() << 8;

            entityCount |= reader.ReadByte();

            entities.Clear();
            for (int n = 0; n < entityCount; n++)
            {
                entities.Add(new Entity(reader));
            }

            reader.Close();
        }