Example #1
0
        /// <summary>
        /// Loads the default palettes from the specified archive.
        /// </summary>
        /// <param name="pattern">Pattern to check for (prefix string).</param>
        /// <param name="archive">Data archive.</param>
        /// <returns>Number of palettes loaded.</returns>
        public int LoadPalettes(string pattern, DATArchive archive)
        {
            palettes.Clear();
            foreach (DATFileEntry file in archive.Files)
            {
                // Check for Palette
                if (file.Name.ToUpper().EndsWith(".PAL") && file.Name.ToUpper().StartsWith(pattern.ToUpper()))
                {
                    // Get Index
                    int index = Convert.ToInt32(
                        Path.GetFileNameWithoutExtension(file.Name).Remove(0, pattern.Length));

                    // Get File from Archive
                    Palette256 palette = Palette256.FromArchive(file.Name, archive);

                    // Add Palette
                    palettes.Add(index, palette);
                }
            }
            return(palettes.Count);
        }
Example #2
0
 public int LoadPalettes(string pattern, DATArchive archive)
 {
     this.palettes.Clear();
     foreach (DATFileEntry file in archive.Files)
     {
         if (file.Name.ToUpper().EndsWith(".PAL") && file.Name.ToUpper().StartsWith(pattern.ToUpper()))
         {
             this.palettes.Add(Convert.ToInt32(Path.GetFileNameWithoutExtension(file.Name).Remove(0, pattern.Length)), Palette256.FromArchive(file.Name, archive));
         }
     }
     return(this.palettes.Count);
 }
Example #3
0
        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);
        }