fix support of 4 BPP

This commit is contained in:
ManicSteiner
2025-01-20 12:28:55 +08:00
parent 7971bd0d4d
commit dd7f1cc9ec
2 changed files with 18 additions and 10 deletions

View File

@@ -69,6 +69,7 @@ namespace GameRes.Formats.DigitalWorks
case 1: bpp = 16; break;
case 2: bpp = 24; break;
case 3: bpp = 32; break;
case 4: bpp = 4; break; //16color
case 5: bpp = 8; break;
default: return null;
}
@@ -118,25 +119,26 @@ namespace GameRes.Formats.DigitalWorks
m_info = info;
switch (info.BPP)
{
case 8: Format = PixelFormats.Indexed8; break;
case 16: Format = PixelFormats.Bgr555; break;
case 24: Format = PixelFormats.Bgr24; break;
case 32: Format = PixelFormats.Bgra32; break;
case 4: Format = PixelFormats.Indexed4; break;
case 8: Format = PixelFormats.Indexed8; break;
case 16: Format = PixelFormats.Bgr555; break;
case 24: Format = PixelFormats.Bgr24; break;
case 32: Format = PixelFormats.Bgra32; break;
}
}
public byte[] Unpack ()
{
m_input.Position = 0x10 + m_info.HeaderSize;
int pixel_size = m_info.BPP / 8;
int image_size = (int)m_info.Width * (int)m_info.Height * pixel_size;
double pixel_size = (double)m_info.BPP / 8;
int image_size = (int)((int)m_info.Width * (int)m_info.Height * pixel_size);
var output = m_input.ReadBytes (image_size);
if (pixel_size <= 8 && m_info.Colors > 0)
Palette = ReadPalette (m_info.Colors, m_info.Alpha);
if (pixel_size == 3 || pixel_size == 4 && m_info.Alpha == 8)
{
for (int i = 0; i < image_size; i += pixel_size)
for (int i = 0; i < image_size; i += (int)pixel_size)
{
byte r = output[i];
output[i] = output[i+2];
@@ -175,6 +177,11 @@ namespace GameRes.Formats.DigitalWorks
color_num, X_A == 7 ? PaletteFormat.RgbA7 : X_A == 0 ? PaletteFormat.RgbX : PaletteFormat.RgbA);
var color_map = new Color[color_num];
if (color_num == 16){
Array.Copy(source, 0, color_map, 0, 16);
return new BitmapPalette(color_map);
}
int parts = color_num / 32;
const int blocks = 2;
const int rows = 2;

View File

@@ -71,8 +71,8 @@ namespace GameRes
BgrX = 6,
RgbA = 9,
BgrA = 10,
RgbA7 = 55,
BgrA7 = 66,
RgbA7 = 55,
BgrA7 = 66,
}
public class ImageData
@@ -126,7 +126,8 @@ namespace GameRes
public static ImageData Create (ImageMetaData info, PixelFormat format, BitmapPalette palette,
Array pixel_data)
{
return Create (info, format, palette, pixel_data, (int)info.Width*((format.BitsPerPixel+7)/8));
return Create (info, format, palette, pixel_data,
format.BitsPerPixel == 4 ? (int)info.Width*format.BitsPerPixel/8 : (int)info.Width*((format.BitsPerPixel+7)/8));
}
public static ImageData CreateFlipped (ImageMetaData info, PixelFormat format, BitmapPalette palette,