コード例 #1
0
        public void Read(Reader reader, int Columns)
        {
            int palColumns = Columns;

            Colors = new PaletteColour[palColumns][];
            for (int i = 0; i < palColumns; i++)
            {
                Colors[i] = new PaletteColour[COLORS_PER_COLUMN];
                for (int j = 0; j < COLORS_PER_COLUMN; ++j)
                {
                    Colors[i][j] = new PaletteColour(reader);
                }                                            //Console.WriteLine(Colors[i][j].R + Colors[i][j].G + Colors[i][j].B); }
            }
        }
コード例 #2
0
        public void Read(Reader reader)
        {
            int palColumns = ((int)reader.BaseStream.Length / 8) / 6;

            Colors = new PaletteColour[palColumns][];
            for (int i = 0; i < palColumns; i++)
            {
                Colors[i] = new PaletteColour[COLORS_PER_COLUMN];
                for (int j = 0; j < COLORS_PER_COLUMN; ++j)
                {
                    Colors[i][j] = new PaletteColour(reader);
                }
            }
        }
コード例 #3
0
        public Palette(int pc = 2)
        {
            int palColumns = pc;

            Colors = new PaletteColour[palColumns][];
            for (int i = 0; i < palColumns; i++)
            {
                Colors[i] = new PaletteColour[COLORS_PER_COLUMN];
                for (int j = 0; j < COLORS_PER_COLUMN; ++j)
                {
                    Colors[i][j] = new PaletteColour();
                }
            }
        }
コード例 #4
0
        public gfx(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]     = new PaletteColour();
                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();
        }