예제 #1
0
 public unsafe static Bitmap RenderImage(MPFFrame mpf, Palette256 palette)
 {
     return(SimpleRender(mpf.Width, mpf.Height, mpf.RawData, palette, ImageType.MPF));
 }
예제 #2
0
파일: MPF.cs 프로젝트: moseleyc/editor
        public unsafe Bitmap Render(int frameIndex)
        {
            // Create Bitmap
            Bitmap image = new Bitmap(width, height);

            // Lock Bits
            BitmapData bmd = image.LockBits(
                new Rectangle(0, 0, image.Width, image.Height),
                ImageLockMode.WriteOnly,
                image.PixelFormat);

            MPFFrame   frame = frames[frameIndex];
            Palette256 pal   = Palette256.FromArchive(palette, DATArchive.Hades);

            // Render Image
            for (int y = 0; y < frame.Height; y++)
            {
                byte *row = (byte *)bmd.Scan0 + ((y + frame.Top) * bmd.Stride);

                for (int x = 0; x < frame.Width; x++)
                {
                    int xIndex     = x + frame.Left;
                    int colorIndex = frame.RawData[y * frame.Width + x];

                    if (colorIndex > 0)
                    {
                        #region 32 Bit Render
                        if (bmd.PixelFormat == PixelFormat.Format32bppArgb)
                        {
                            row[xIndex * 4]     = pal[colorIndex].B;
                            row[xIndex * 4 + 1] = pal[colorIndex].G;
                            row[xIndex * 4 + 2] = pal[colorIndex].R;
                            row[xIndex * 4 + 3] = pal[colorIndex].A;
                        }
                        #endregion

                        #region 24 Bit Render
                        else if (bmd.PixelFormat == PixelFormat.Format24bppRgb)
                        {
                            row[xIndex * 3]     = pal[colorIndex].B;
                            row[xIndex * 3 + 1] = pal[colorIndex].G;
                            row[xIndex * 3 + 2] = pal[colorIndex].R;
                        }
                        #endregion

                        #region 15 Bit Render
                        else if (bmd.PixelFormat == PixelFormat.Format16bppRgb555)
                        {
                            // Get 15-Bit Color
                            ushort colorWORD = (ushort)(((pal[colorIndex].R & 248) << 7) +
                                                        ((pal[colorIndex].G & 248) << 2) +
                                                        (pal[colorIndex].B >> 3));

                            row[xIndex * 2]     = (byte)(colorWORD % 256);
                            row[xIndex * 2 + 1] = (byte)(colorWORD / 256);
                        }
                        #endregion

                        #region 16 Bit Render
                        else if (bmd.PixelFormat == PixelFormat.Format16bppRgb565)
                        {
                            // Get 16-Bit Color
                            ushort colorWORD = (ushort)(((pal[colorIndex].R & 248) << 8)
                                                        + ((pal[colorIndex].G & 252) << 3) +
                                                        (pal[colorIndex].B >> 3));

                            row[xIndex * 2]     = (byte)(colorWORD % 256);
                            row[xIndex * 2 + 1] = (byte)(colorWORD / 256);
                        }
                        #endregion
                    }
                }
            }

            // Unlock Bits
            image.UnlockBits(bmd);

            // Return Bitmap
            return(image);
        }