コード例 #1
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();
        }
コード例 #2
0
 public void importFromBitmap(Bitmap IMG)
 {
     gfxImage = IMG;
     width    = (ushort)IMG.Width;
     height   = (ushort)IMG.Height;
 }