mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
fix support of 4 BPP
This commit is contained in:
@@ -69,6 +69,7 @@ namespace GameRes.Formats.DigitalWorks
|
|||||||
case 1: bpp = 16; break;
|
case 1: bpp = 16; break;
|
||||||
case 2: bpp = 24; break;
|
case 2: bpp = 24; break;
|
||||||
case 3: bpp = 32; break;
|
case 3: bpp = 32; break;
|
||||||
|
case 4: bpp = 4; break; //16color
|
||||||
case 5: bpp = 8; break;
|
case 5: bpp = 8; break;
|
||||||
default: return null;
|
default: return null;
|
||||||
}
|
}
|
||||||
@@ -118,25 +119,26 @@ namespace GameRes.Formats.DigitalWorks
|
|||||||
m_info = info;
|
m_info = info;
|
||||||
switch (info.BPP)
|
switch (info.BPP)
|
||||||
{
|
{
|
||||||
case 8: Format = PixelFormats.Indexed8; break;
|
case 4: Format = PixelFormats.Indexed4; break;
|
||||||
case 16: Format = PixelFormats.Bgr555; break;
|
case 8: Format = PixelFormats.Indexed8; break;
|
||||||
case 24: Format = PixelFormats.Bgr24; break;
|
case 16: Format = PixelFormats.Bgr555; break;
|
||||||
case 32: Format = PixelFormats.Bgra32; break;
|
case 24: Format = PixelFormats.Bgr24; break;
|
||||||
|
case 32: Format = PixelFormats.Bgra32; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] Unpack ()
|
public byte[] Unpack ()
|
||||||
{
|
{
|
||||||
m_input.Position = 0x10 + m_info.HeaderSize;
|
m_input.Position = 0x10 + m_info.HeaderSize;
|
||||||
int pixel_size = m_info.BPP / 8;
|
double pixel_size = (double)m_info.BPP / 8;
|
||||||
int image_size = (int)m_info.Width * (int)m_info.Height * pixel_size;
|
int image_size = (int)((int)m_info.Width * (int)m_info.Height * pixel_size);
|
||||||
var output = m_input.ReadBytes (image_size);
|
var output = m_input.ReadBytes (image_size);
|
||||||
if (pixel_size <= 8 && m_info.Colors > 0)
|
if (pixel_size <= 8 && m_info.Colors > 0)
|
||||||
Palette = ReadPalette (m_info.Colors, m_info.Alpha);
|
Palette = ReadPalette (m_info.Colors, m_info.Alpha);
|
||||||
|
|
||||||
if (pixel_size == 3 || pixel_size == 4 && m_info.Alpha == 8)
|
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];
|
byte r = output[i];
|
||||||
output[i] = output[i+2];
|
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);
|
color_num, X_A == 7 ? PaletteFormat.RgbA7 : X_A == 0 ? PaletteFormat.RgbX : PaletteFormat.RgbA);
|
||||||
var color_map = new Color[color_num];
|
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;
|
int parts = color_num / 32;
|
||||||
const int blocks = 2;
|
const int blocks = 2;
|
||||||
const int rows = 2;
|
const int rows = 2;
|
||||||
|
|||||||
@@ -71,8 +71,8 @@ namespace GameRes
|
|||||||
BgrX = 6,
|
BgrX = 6,
|
||||||
RgbA = 9,
|
RgbA = 9,
|
||||||
BgrA = 10,
|
BgrA = 10,
|
||||||
RgbA7 = 55,
|
RgbA7 = 55,
|
||||||
BgrA7 = 66,
|
BgrA7 = 66,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ImageData
|
public class ImageData
|
||||||
@@ -126,7 +126,8 @@ namespace GameRes
|
|||||||
public static ImageData Create (ImageMetaData info, PixelFormat format, BitmapPalette palette,
|
public static ImageData Create (ImageMetaData info, PixelFormat format, BitmapPalette palette,
|
||||||
Array pixel_data)
|
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,
|
public static ImageData CreateFlipped (ImageMetaData info, PixelFormat format, BitmapPalette palette,
|
||||||
|
|||||||
Reference in New Issue
Block a user