1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-17 14:11:06 +00:00

DDS: Load BGRA4 textures directly as RGBA4

This commit is contained in:
BlueCube3310
2025-05-03 15:31:13 +02:00
parent 1cf573f44d
commit 2b8fcca343
2 changed files with 7 additions and 17 deletions

View File

@@ -196,7 +196,7 @@ static const DDSFormatInfo dds_format_info[DDS_MAX] = {
{ "B2GR3A8", false, 1, 2, Image::FORMAT_RGBA8 }, { "B2GR3A8", false, 1, 2, Image::FORMAT_RGBA8 },
{ "BGR10A2", false, 1, 4, Image::FORMAT_RGBA8 }, { "BGR10A2", false, 1, 4, Image::FORMAT_RGBA8 },
{ "RGB10A2", false, 1, 4, Image::FORMAT_RGBA8 }, { "RGB10A2", false, 1, 4, Image::FORMAT_RGBA8 },
{ "BGRA4", false, 1, 2, Image::FORMAT_RGBA8 }, { "BGRA4", false, 1, 2, Image::FORMAT_RGBA4444 },
{ "GRAYSCALE", false, 1, 1, Image::FORMAT_L8 }, { "GRAYSCALE", false, 1, 1, Image::FORMAT_L8 },
{ "GRAYSCALE_ALPHA", false, 1, 2, Image::FORMAT_LA8 }, { "GRAYSCALE_ALPHA", false, 1, 2, Image::FORMAT_LA8 },
{ "GRAYSCALE_ALPHA_4", false, 1, 1, Image::FORMAT_LA8 }, { "GRAYSCALE_ALPHA_4", false, 1, 1, Image::FORMAT_LA8 },

View File

@@ -177,7 +177,6 @@ static Ref<Image> _dds_load_layer(Ref<FileAccess> p_file, DDSFormat p_dds_format
break; break;
case DDS_BGR5A1: case DDS_BGR5A1:
case DDS_BGRA4:
case DDS_B2GR3A8: case DDS_B2GR3A8:
case DDS_LUMINANCE_ALPHA_4: case DDS_LUMINANCE_ALPHA_4:
size = size * 2; size = size * 2;
@@ -235,22 +234,13 @@ static Ref<Image> _dds_load_layer(Ref<FileAccess> p_file, DDSFormat p_dds_format
} break; } break;
case DDS_BGRA4: { case DDS_BGRA4: {
// To RGBA8. // To RGBA4.
int colcount = size / 4; for (uint32_t i = 0; i < size; i += 2) {
uint8_t ar = wb[i + 0];
uint8_t gb = wb[i + 1];
for (int i = colcount - 1; i >= 0; i--) { wb[i + 0] = ((ar & 0x0F) << 4) | ((gb & 0xF0) >> 4);
int src_ofs = i * 2; wb[i + 1] = ((ar & 0xF0) >> 4) | ((gb & 0x0F) << 4);
int dst_ofs = i * 4;
uint8_t b = wb[src_ofs] & 0x0F;
uint8_t g = wb[src_ofs] & 0xF0;
uint8_t r = wb[src_ofs + 1] & 0x0F;
uint8_t a = wb[src_ofs + 1] & 0xF0;
wb[dst_ofs] = (r << 4) | r;
wb[dst_ofs + 1] = g | (g >> 4);
wb[dst_ofs + 2] = (b << 4) | b;
wb[dst_ofs + 3] = a | (a >> 4);
} }
} break; } break;