mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-25 04:14:13 +08:00
split indexed image reader into separate method.
This commit is contained in:
parent
8111f52541
commit
2b973c0bd6
@ -91,13 +91,19 @@ namespace GameRes.Formats.DRS
|
|||||||
|
|
||||||
public override ImageData Read (Stream file, ImageMetaData info)
|
public override ImageData Read (Stream file, ImageMetaData info)
|
||||||
{
|
{
|
||||||
PixelFormat format;
|
BitmapSource bitmap;
|
||||||
BitmapPalette bitmap_palette = null;
|
|
||||||
int stride = (int)info.Width*((info.BPP+7)/8);
|
|
||||||
if (8 == info.BPP)
|
if (8 == info.BPP)
|
||||||
|
bitmap = ReadIndexed (file, info);
|
||||||
|
else
|
||||||
|
bitmap = ReadTrue (file, info);
|
||||||
|
bitmap.Freeze();
|
||||||
|
return new ImageData (bitmap, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BitmapSource ReadIndexed (Stream file, ImageMetaData info)
|
||||||
{
|
{
|
||||||
file.Position = 44;
|
file.Position = 44;
|
||||||
format = PixelFormats.Indexed8;
|
PixelFormat format = PixelFormats.Indexed8;
|
||||||
var palette_data = new byte[0x400];
|
var palette_data = new byte[0x400];
|
||||||
if (palette_data.Length != file.Read (palette_data, 0, palette_data.Length))
|
if (palette_data.Length != file.Read (palette_data, 0, palette_data.Length))
|
||||||
throw new InvalidFormatException();
|
throw new InvalidFormatException();
|
||||||
@ -106,26 +112,30 @@ namespace GameRes.Formats.DRS
|
|||||||
{
|
{
|
||||||
palette[i] = Color.FromRgb (palette_data[i*4+2], palette_data[i*4+1], palette_data[i*4]);
|
palette[i] = Color.FromRgb (palette_data[i*4+2], palette_data[i*4+1], palette_data[i*4]);
|
||||||
}
|
}
|
||||||
bitmap_palette = new BitmapPalette (palette);
|
var bitmap_palette = new BitmapPalette (palette);
|
||||||
file.Position += 4;
|
file.Position += 4;
|
||||||
|
int stride = (int)info.Width*((info.BPP+7)/8);
|
||||||
|
|
||||||
/* indexed GGD image is a LZSS-compressed stream */
|
/* indexed GGD image is a LZSS-compressed stream */
|
||||||
/* currently not implemented */
|
/* currently not implemented */
|
||||||
|
throw new NotImplementedException ("DrgFormat.ReadIndexed not implemented");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
private BitmapSource ReadTrue (Stream file, ImageMetaData info)
|
||||||
{
|
{
|
||||||
file.Position = 8;
|
file.Position = 8;
|
||||||
|
PixelFormat format;
|
||||||
if (24 == info.BPP)
|
if (24 == info.BPP)
|
||||||
format = PixelFormats.Bgr24;
|
format = PixelFormats.Bgr24;
|
||||||
else
|
else
|
||||||
format = PixelFormats.Bgr565;
|
format = PixelFormats.Bgr565;
|
||||||
}
|
|
||||||
|
int stride = (int)info.Width*((info.BPP+7)/8);
|
||||||
var pixel_data = DecodeStream (file, stride*(int)info.Height);
|
var pixel_data = DecodeStream (file, stride*(int)info.Height);
|
||||||
if (null == pixel_data)
|
if (null == pixel_data)
|
||||||
throw new InvalidFormatException();
|
throw new InvalidFormatException();
|
||||||
var bitmap = BitmapSource.Create ((int)info.Width, (int)info.Height, 96, 96,
|
return BitmapSource.Create ((int)info.Width, (int)info.Height, 96, 96,
|
||||||
format, bitmap_palette, pixel_data, (int)stride);
|
format, null, pixel_data, stride);
|
||||||
bitmap.Freeze();
|
|
||||||
return new ImageData (bitmap, info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] DecodeStream (Stream input, int pixel_count)
|
byte[] DecodeStream (Stream input, int pixel_count)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user