unit tests for dds and pvr image loader

This commit is contained in:
andrey.zhirnov
2019-06-20 11:49:06 +03:00
parent 9e44f8c5fa
commit 2a68c66cc1
15 changed files with 93 additions and 13 deletions

2
.gitattributes vendored
View File

@@ -9,3 +9,5 @@
*.dll filter=lfs diff=lfs merge=lfs -text
*.lib filter=lfs diff=lfs merge=lfs -text
*.dylib filter=lfs diff=lfs merge=lfs -text
*.pvr filter=lfs diff=lfs merge=lfs -text
*.dds filter=lfs diff=lfs merge=lfs -text

View File

@@ -8,8 +8,10 @@
namespace
{
// DDS format specification:
// https://docs.microsoft.com/en-us/windows/desktop/direct3ddds/dx-graphics-dds-pguide
using namespace e2d;
// from https://github.com/tlorach/nvFX/blob/master/samples/shared/nv_dds/nv_dds.h
// pixel format flags
const u32 ddsf_alphapixels = 0x00000001;
@@ -145,8 +147,8 @@ namespace e2d::images::impl
}
const dds_header& hdr = ((const dds_header_with_magic*)src.data())->header;
const u8* content = src.data() + sizeof(dds_header_with_magic);
if ( math::check_all_flags(ddsf_cubemap, hdr.dwCaps2) ||
math::check_all_flags(ddsf_volume, hdr.dwCaps2) ||
if ( math::check_all_flags(hdr.dwCaps2, ddsf_cubemap) ||
math::check_all_flags(hdr.dwCaps2, ddsf_volume) ||
(hdr.dwDepth > 0) ) {
return false; // cubemap and volume textures are not supported
}

View File

@@ -63,6 +63,7 @@ namespace
astc_10x10 = 38,
astc_12x10 = 39,
astc_12x12 = 40,
rgba8 = 0x08080808'61626772ull,
};
enum class pvr_color_space : u32 {
@@ -113,54 +114,62 @@ namespace
}
bool get_pvr_format(const pvr_header& hdr, image_data_format& out_format, u32& out_bytes_per_block, v2u& out_block_size) {
if ( pvr_color_space(hdr.colorSpace) != pvr_color_space::linear ) {
return false; // only linear color space is supported
}
const pvr_pixel_format fmt = pvr_pixel_format(hdr.pixelFormat0 | (u64(hdr.pixelFormat1) << 32));
switch (fmt)
{
case pvr_pixel_format::pvrtc_2bpp_rgb:
out_format =image_data_format::rgb_pvrtc2;
out_format = image_data_format::rgb_pvrtc2;
out_bytes_per_block = 8;
out_block_size = v2u(8,4);
break;
case pvr_pixel_format::pvrtc_2bpp_rgba:
out_format =image_data_format::rgba_pvrtc2;
out_format = image_data_format::rgba_pvrtc2;
out_bytes_per_block = 8;
out_block_size = v2u(8,4);
break;
case pvr_pixel_format::pvrtc_4bpp_rgb:
out_format =image_data_format::rgb_pvrtc4;
out_format = image_data_format::rgb_pvrtc4;
out_bytes_per_block = 8;
out_block_size = v2u(4,4);
break;
case pvr_pixel_format::pvrtc_4bpp_rgba:
out_format =image_data_format::rgba_pvrtc4;
out_format = image_data_format::rgba_pvrtc4;
out_bytes_per_block = 8;
out_block_size = v2u(4,4);
break;
case pvr_pixel_format::pvrtc_ii_2bpp:
out_format =image_data_format::rgba_pvrtc2_v2;
out_format = image_data_format::rgba_pvrtc2_v2;
out_bytes_per_block = 8;
out_block_size = v2u(8,4);
break;
case pvr_pixel_format::pvrtc_ii_4bpp:
out_format =image_data_format::rgba_pvrtc4_v2;
out_format = image_data_format::rgba_pvrtc4_v2;
out_bytes_per_block = 8;
out_block_size = v2u(4,4);
break;
case pvr_pixel_format::dxt1:
out_format =image_data_format::rgb_dxt1;
out_format = image_data_format::rgb_dxt1;
out_bytes_per_block = 8;
out_block_size = v2u(4,4);
break;
case pvr_pixel_format::dxt3:
out_format =image_data_format::rgba_dxt3;
out_format = image_data_format::rgba_dxt3;
out_bytes_per_block = 16;
out_block_size = v2u(4,4);
break;
case pvr_pixel_format::dxt5:
out_format =image_data_format::rgba_dxt5;
out_format = image_data_format::rgba_dxt5;
out_bytes_per_block = 16;
out_block_size = v2u(4,4);
break;
case pvr_pixel_format::rgba8:
out_format = image_data_format::rgba8;
out_bytes_per_block = 4;
out_block_size = v2u(1,1);
break;
default:
return false; // unsupported format
}

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5fc7e9bc99500be4f25f1d0e6ea372a1b14fb1dec6fc73a7c5a0ddf505ae16a8
size 8259

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6b7f41f18f51ec169a9c521cd1177fd49037b200a850aad05a923240c37d8d87
size 4163

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:bd1c2362dc5b0b75d97ca3d5bbdf2cf647b25a5b2f8834a9005e8c9c0a70e82c
size 8259

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7a62a7760e33b7130539c3b6a8b7c287ccdd11edb9dd273be3c1e6ec7b81b47e
size 2115

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6a9b1a7f97b26ff7df0a7275f786e029dbc45aab796247f8063c820140933685
size 2115

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:69e2bab57471fbde23d432f77270678e0a28cf809eb079fbb39a61e68abe4059
size 4163

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f730702b1075c5a0ef929272106275debf12dbce31a59664038545b5b91d1545
size 4163

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7fcf6cb866364b0a8b31bea7407a40aa2dcda1af4f618604aec2249e2e0cc588
size 2115

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1a928929dc7532d84072e5668e5098b17289fdea1d36bff3ae48fa232294f770
size 4163

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:07b0e533a85a8eef51e9baf6ebca2f5a451f74e712557ef315fd1952dcaef307
size 8320

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9bae52a491e072cd7f1cd70100ca4dcab6eb66fbadd3a72f5e517a9916b445e8
size 32835

View File

@@ -129,4 +129,38 @@ TEST_CASE("images") {
REQUIRE(math::approximately(img.pixel32(1,0), color32::green(), 0));
REQUIRE(math::approximately(img.pixel32(2,0), color32::blue(), 0));
}
{
struct img_info {
str_view name;
bool can_load;
image_data_format format;
};
const img_info test_images[] = {
{"bin/images/ship_pvrtc_2bpp_rgba.pvr", true, image_data_format::rgba_pvrtc2},
{"bin/images/ship_pvrtc_2bpp_rgb.pvr", true, image_data_format::rgb_pvrtc2},
{"bin/images/ship_pvrtc_4bpp_rgba.pvr", true, image_data_format::rgba_pvrtc4},
{"bin/images/ship_pvrtc_4bpp_rgb.pvr", true, image_data_format::rgb_pvrtc4},
{"bin/images/ship_pvrtc_ii_2bpp.pvr", true, image_data_format::rgba_pvrtc2_v2},
{"bin/images/ship_pvrtc_ii_4bpp.pvr", true, image_data_format::rgba_pvrtc4_v2},
{"bin/images/ship_etc1.pvr", false, image_data_format(-1)},
{"bin/images/ship_etc2.pvr", false, image_data_format(-1)},
{"bin/images/ship_eac_rg11.pvr", false, image_data_format(-1)},
{"bin/images/ship_rgba8.pvr", true, image_data_format::rgba8},
{"bin/images/ship_rgba.dds", true, image_data_format::rgba_dxt5}
};
for (auto& info : test_images) {
image img;
input_stream_uptr stream = make_read_file(info.name);
REQUIRE(stream);
REQUIRE(images::try_load_image(img, make_read_file(info.name)) == info.can_load);
if ( info.can_load ) {
REQUIRE(img.format() == info.format);
REQUIRE(img.size().x == 64);
REQUIRE(img.size().y == 128);
REQUIRE(img.data().size() > 0);
}
}
}
}