(ImageFormat.ReadPalette): new static methods.

Generalized image palette deserializations.
This commit is contained in:
morkt
2017-01-14 16:27:11 +04:00
parent 832a1a3ff0
commit 13cf289bae
25 changed files with 87 additions and 331 deletions

View File

@@ -239,7 +239,7 @@ namespace GameRes.Formats.Ivory
m_output = new byte[m_width * m_height];
Format = PixelFormats.Indexed8;
Palette = new BitmapPalette (ReadPalette());
Palette = ImageFormat.ReadPalette (m_input.AsStream);
var index = new int[m_height];
for (int i = 0; i < m_height; ++i)
index[i] = m_input.ReadInt32();
@@ -278,7 +278,7 @@ namespace GameRes.Formats.Ivory
m_output = new byte[m_stride * m_height];
Format = PixelFormats.Bgra32;
var palette = ReadPalette();
var palette = ImageFormat.ReadColorMap (m_input.AsStream);
var index = new int[m_height];
for (int i = 0; i < m_height; ++i)
index[i] = m_input.ReadInt32();
@@ -343,20 +343,6 @@ namespace GameRes.Formats.Ivory
}
}
Color[] ReadPalette ()
{
var palette_data = m_input.ReadBytes (0x400);
if (palette_data.Length != 0x400)
throw new EndOfStreamException();
var palette = new Color[0x100];
for (int i = 0; i < 0x100; ++i)
{
int c = i * 4;
palette[i] = Color.FromRgb (palette_data[c+2], palette_data[c+1], palette_data[c]);
}
return palette;
}
#region IDisposable Members
public void Dispose ()
{