(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

@@ -425,6 +425,9 @@ namespace GameRes.Formats.Entis
throw new InvalidFormatException();
DecodeType2Image (context);
return;
case 4:
DecodeType4Image (context);
return;
case 8:
if (nBitCount != 8)
throw new InvalidFormatException();
@@ -589,6 +592,11 @@ namespace GameRes.Formats.Entis
}
}
private void DecodeType4Image (RLEDecodeContext context)
{
throw new NotImplementedException ("Arithmetic compression not implemented");
}
private void DecodeLossyImage (HuffmanDecodeContext context)
{
context.FlushBuffer();

View File

@@ -246,17 +246,10 @@ namespace GameRes.Formats.Entis
internal static Color[] ReadPalette (Stream input, int palette_length)
{
var palette_data = new byte[0x400];
if (palette_length > palette_data.Length)
int colors = palette_length / 4;
if (colors <= 0 || colors > 0x100)
throw new InvalidFormatException();
if (palette_length != input.Read (palette_data, 0, palette_length))
throw new InvalidFormatException();
var colors = new Color[256];
for (int i = 0; i < 256; ++i)
{
colors[i] = Color.FromRgb (palette_data[i*4+2], palette_data[i*4+1], palette_data[i*4]);
}
return colors;
return ImageFormat.ReadColorMap (input, colors);
}
internal EriReader ReadImageData (IBinaryStream stream, EriMetaData meta)