Skip to content

Commit

Permalink
Adding palette import from non-indexed color images.
Browse files Browse the repository at this point in the history
  • Loading branch information
MainMemory committed Nov 24, 2015
1 parent 34568b5 commit a0b3d88
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions SonLVL/MainForm.cs
Expand Up @@ -3958,22 +3958,40 @@ private void importToolStripMenuItem1_Click(object sender, EventArgs e)
case ".png":
case ".jpg":
case ".gif":
Bitmap bmp = new Bitmap(a.FileName);
if ((bmp.PixelFormat & System.Drawing.Imaging.PixelFormat.Indexed) == System.Drawing.Imaging.PixelFormat.Indexed)
using (Bitmap bmp = new Bitmap(a.FileName))
{
Color[] pal = bmp.Palette.Entries;
for (int i = 0; i < pal.Length; i++)
if ((bmp.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed)
{
LevelData.ColorToPalette(l, x, pal[i]);
x++;
if (x == 16)
Color[] pal = bmp.Palette.Entries;
for (int i = 0; i < pal.Length; i++)
{
x = 0;
l++;
LevelData.ColorToPalette(l, x++, pal[i]);
if (x == 16)
{
x = 0;
l++;
if (l == 4)
break;
}
}
}
else
for (int y = 0; y < bmp.Height; y += 8)
{
for (int ix = 0; ix < bmp.Width; ix += 8)
{
LevelData.ColorToPalette(l, x++, bmp.GetPixel(ix, y));
if (x == 16)
{
x = 0;
l++;
if (l == 4)
break;
}
}
if (l == 4)
break;
}
}
}
break;
}
Expand Down

0 comments on commit a0b3d88

Please sign in to comment.