(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

@@ -69,7 +69,7 @@ namespace GameRes.Formats.FC01
BitmapPalette palette = null;
if (8 == bpp)
{
palette = ReadPalette (file, index_offset);
palette = ImageFormat.ReadPalette (file, index_offset);
index_offset += 0x400;
}
string base_name = Path.GetFileNameWithoutExtension (file.Name);
@@ -112,19 +112,6 @@ namespace GameRes.Formats.FC01
}
}
BitmapPalette ReadPalette (ArcView file, uint offset)
{
var palette = file.View.ReadBytes (offset, 0x400);
int src = 0;
var colors = new Color[0x100];
for (int i = 0; i < 0x100; ++i)
{
colors[i] = Color.FromRgb (palette[src+2], palette[src+1], palette[src]);
src += 4;
}
return new BitmapPalette (colors);
}
public override ResourceOptions GetDefaultOptions ()
{
return new McgOptions { Key = Settings.Default.MCGLastKey };

View File

@@ -92,20 +92,6 @@ namespace GameRes.Formats.FC01
}
}
BitmapPalette ReadPalette (Stream input)
{
var palette_data = new byte[0x400];
if (palette_data.Length != input.Read (palette_data, 0, palette_data.Length))
throw new InvalidFormatException();
var palette = new Color[0x100];
for (int i = 0; i < palette.Length; ++i)
{
int c = i * 4;
palette[i] = Color.FromRgb (palette_data[c+2], palette_data[c+1], palette_data[c]);
}
return new BitmapPalette (palette);
}
public override void Write (Stream file, ImageData image)
{
throw new System.NotImplementedException ("ClmFormat.Write not implemented");