Merge branch 'master' into feature/label

This commit is contained in:
2019-08-16 07:40:40 +07:00
85 changed files with 1738 additions and 691 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,3 +0,0 @@
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:332aff6826f8eb97cf3420112aa6a42655c5e284b46acd2caa80d5dfe4404e46
size 5438

View File

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

View File

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

View File

@@ -190,19 +190,17 @@ TEST_CASE("render"){
texture_ptr tex = r.create_texture(v2u(128,128), pixel_declaration::pixel_type::rgba8);
REQUIRE(tex != nullptr);
buffer src;
src.resize(((tex->size().x * tex->decl().bits_per_pixel()) / 8u) * tex->size().y);
buffer src(tex->size().x * tex->size().y * 4u);
for ( auto& c : src ) {
c = rand() % 255;
}
REQUIRE_NOTHROW(r.update_texture(tex, src, b2u(0, 0, 128, 128)));
}
{
texture_ptr tex = r.create_texture(v2u(128,128), pixel_declaration::pixel_type::g8);
texture_ptr tex = r.create_texture(v2u(128,128), pixel_declaration::pixel_type::l8);
REQUIRE(tex != nullptr);
buffer src;
src.resize(((tex->size().x * tex->decl().bits_per_pixel()) / 8u) * tex->size().y);
buffer src(tex->size().x * tex->size().y * 1u);
for ( auto& c : src ) {
c = rand() % 255;
}
@@ -212,8 +210,7 @@ TEST_CASE("render"){
texture_ptr tex = r.create_texture(v2u(128,128), pixel_declaration::pixel_type::rgb8);
REQUIRE(tex != nullptr);
buffer src;
src.resize(((tex->size().x * tex->decl().bits_per_pixel()) / 8u) * tex->size().y);
buffer src(tex->size().x * tex->size().y * 3u);
for ( auto& c : src ) {
c = rand() % 255;
}
@@ -223,8 +220,7 @@ TEST_CASE("render"){
texture_ptr tex = r.create_texture(v2u(57,31), pixel_declaration::pixel_type::rgba8);
REQUIRE(tex != nullptr);
buffer src;
src.resize(((tex->size().x * tex->decl().bits_per_pixel()) / 8u) * tex->size().y);
buffer src(tex->size().x * tex->size().y * 4u);
for ( auto& c : src ) {
c = rand() % 255;
}
@@ -234,8 +230,7 @@ TEST_CASE("render"){
texture_ptr tex = r.create_texture(v2u(128,128), pixel_declaration::pixel_type::rgba8);
REQUIRE(tex != nullptr);
buffer src;
src.resize(((31 * tex->decl().bits_per_pixel()) / 8u) * 44);
buffer src(31u * 44u * 4u);
for ( auto& c : src ) {
c = rand() % 255;
}
@@ -245,13 +240,12 @@ TEST_CASE("render"){
texture_ptr tex = r.create_texture(v2u(128,128), pixel_declaration::pixel_type::rgba8);
REQUIRE(tex != nullptr);
buffer src;
src.resize(((31 * tex->decl().bits_per_pixel()) / 8u) * 44);
buffer src(31u * 44u * 4u);
for ( auto& c : src ) {
c = rand() % 255;
}
image img(v2u(31, 44), image_data_format::ga8, src);
image img(v2u(31, 44), image_data_format::la8, src);
REQUIRE_THROWS_AS(
r.update_texture(tex, img, v2u(11,27)),
bad_render_operation);
@@ -264,7 +258,7 @@ TEST_CASE("render"){
filesystem::predef_path::resources));
image src;
REQUIRE(images::try_load_image(src, make_read_file(path::combine(resources, "bin/images/ship_rgba.dds"))));
REQUIRE(images::try_load_image(src, make_read_file(path::combine(resources, "bin/images/dds/ship_dxt5.dds"))));
texture_ptr tex = r.create_texture(src.size(), pixel_declaration::pixel_type::rgba_dxt5);
REQUIRE(tex != nullptr);

View File

@@ -220,6 +220,11 @@ TEST_CASE("buffer_view") {
buffer_view v5(b2);
REQUIRE(v5.data() == b2.data());
REQUIRE(v5.size() == 20);
str32 b3 = make_utf32("hello");
buffer_view v6(b3);
REQUIRE(v6.data() == b3.data());
REQUIRE(v6.size() == 20);
}
{
const char* s0 = "hell";
@@ -273,4 +278,13 @@ TEST_CASE("buffer_view") {
REQUIRE(buffer_view("hello",5) != buffer_view("hello, world",12));
REQUIRE_FALSE(buffer_view("hello",5) == buffer_view("hello, world",12));
}
{
buffer_view v0("hello",5);
buffer b0 = buffer(v0);
REQUIRE(v0 == b0);
buffer_view v1;
buffer b1 = buffer(v1);
REQUIRE(v1 == b1);
}
}

View File

@@ -8,167 +8,363 @@
using namespace e2d;
TEST_CASE("images") {
{
image i;
REQUIRE(i.size() == v2u::zero());
REQUIRE(i.format() == image_data_format::rgba8);
REQUIRE(i.data().empty());
REQUIRE(i.empty());
SECTION("image") {
{
image i;
REQUIRE(i.size() == v2u::zero());
REQUIRE(i.format() == image_data_format::rgba8);
REQUIRE(i.data().empty());
REQUIRE(i.empty());
}
{
const u8 img[] = {1,2,3,4,5,6,7,8};
image i0(v2u(2,2), image_data_format::a8, {img,4});
image i1(v2u(2,2), image_data_format::l8, {img,4});
image i2(v2u(2,1), image_data_format::la8, {img,4});
image i3(v2u(1,2), image_data_format::la8, {img,4});
image i4(v2u(2,1), image_data_format::rgb8, {img,6});
image i5(v2u(1,2), image_data_format::rgb8, {img,6});
image i6(v2u(2,1), image_data_format::rgba8, {img,8});
image i7(v2u(1,2), image_data_format::rgba8, {img,8});
REQUIRE(i0.format() == image_data_format::a8);
REQUIRE(i1.format() == image_data_format::l8);
REQUIRE(i2.format() == image_data_format::la8);
REQUIRE(i3.format() == image_data_format::la8);
REQUIRE(i4.format() == image_data_format::rgb8);
REQUIRE(i5.format() == image_data_format::rgb8);
REQUIRE(i6.format() == image_data_format::rgba8);
REQUIRE(i7.format() == image_data_format::rgba8);
}
}
{
const u8 img[] = {1,2,3,4,5,6,7,8};
image i0(v2u(2,2), image_data_format::g8, {img,4});
image i1(v2u(2,1), image_data_format::ga8, {img,4});
image i2(v2u(1,2), image_data_format::ga8, {img,4});
image i3(v2u(2,1), image_data_format::rgb8, {img,6});
image i4(v2u(1,2), image_data_format::rgb8, {img,6});
image i5(v2u(2,1), image_data_format::rgba8, {img,8});
image i6(v2u(1,2), image_data_format::rgba8, {img,8});
REQUIRE(i0.format() == image_data_format::g8);
REQUIRE(i1.format() == image_data_format::ga8);
REQUIRE(i2.format() == image_data_format::ga8);
REQUIRE(i3.format() == image_data_format::rgb8);
REQUIRE(i4.format() == image_data_format::rgb8);
REQUIRE(i5.format() == image_data_format::rgba8);
REQUIRE(i6.format() == image_data_format::rgba8);
SECTION("stb") {
{
REQUIRE(filesystem::remove_file("image_save_test.jpg"));
REQUIRE(filesystem::remove_file("image_save_test.png"));
REQUIRE(filesystem::remove_file("image_save_test.tga"));
const u8 img_data[] = {255,0,0, 0,255,0, 0,0,255};
image img(v2u(3,1), image_data_format::rgb8, buffer(img_data, sizeof(img_data)));
REQUIRE(images::try_save_image(
img,
image_file_format::jpg,
make_write_file("image_save_test.jpg", false)));
REQUIRE(filesystem::file_exists("image_save_test.jpg"));
REQUIRE(images::try_save_image(
img,
image_file_format::png,
make_write_file("image_save_test.png", false)));
REQUIRE(filesystem::file_exists("image_save_test.png"));
REQUIRE(images::try_save_image(
img,
image_file_format::tga,
make_write_file("image_save_test.tga", false)));
REQUIRE(filesystem::file_exists("image_save_test.tga"));
}
{
image img;
REQUIRE(images::try_load_image(img, make_read_file("image_save_test.jpg")));
REQUIRE(img.size() == v2u(3,1));
REQUIRE(img.format() == image_data_format::rgb8);
REQUIRE(math::approximately(img.pixel32(0,0), color32::red(), 10u));
REQUIRE(math::approximately(img.pixel32(1,0), color32::green(), 10u));
REQUIRE(math::approximately(img.pixel32(2,0), color32::blue(), 10u));
REQUIRE(images::try_load_image(img, make_read_file("image_save_test.png")));
REQUIRE(img.size() == v2u(3,1));
REQUIRE(img.format() == image_data_format::rgb8);
REQUIRE(math::approximately(img.pixel32(0,0), color32::red(), 0u));
REQUIRE(math::approximately(img.pixel32(1,0), color32::green(), 0u));
REQUIRE(math::approximately(img.pixel32(2,0), color32::blue(), 0u));
REQUIRE(images::try_load_image(img, make_read_file("image_save_test.tga")));
REQUIRE(img.size() == v2u(3,1));
REQUIRE(img.format() == image_data_format::rgb8);
REQUIRE(math::approximately(img.pixel32(0,0), color32::red(), 0u));
REQUIRE(math::approximately(img.pixel32(1,0), color32::green(), 0u));
REQUIRE(math::approximately(img.pixel32(2,0), color32::blue(), 0u));
}
{
REQUIRE(filesystem::remove_file("image_save_test.jpg"));
REQUIRE(filesystem::remove_file("image_save_test.png"));
REQUIRE(filesystem::remove_file("image_save_test.tga"));
const u8 img_data[] = {255,0,0, 0,255,0, 0,0,255};
image img(v2u(3,1), image_data_format::rgb8, buffer(img_data, sizeof(img_data)));
buffer buf;
REQUIRE(images::try_save_image(
img,
image_file_format::jpg,
buf));
REQUIRE(filesystem::try_write_all(buf, "image_save_test.jpg", false));
REQUIRE(images::try_save_image(
img,
image_file_format::png,
buf));
REQUIRE(filesystem::try_write_all(buf, "image_save_test.png", false));
REQUIRE(images::try_save_image(
img,
image_file_format::tga,
buf));
REQUIRE(filesystem::try_write_all(buf, "image_save_test.tga", false));
}
{
image img;
buffer buf;
REQUIRE(filesystem::try_read_all(buf, "image_save_test.jpg"));
REQUIRE(images::try_load_image(img, buf));
REQUIRE(img.size() == v2u(3,1));
REQUIRE(img.format() == image_data_format::rgb8);
REQUIRE(math::approximately(img.pixel32(0,0), color32::red(), 10));
REQUIRE(math::approximately(img.pixel32(1,0), color32::green(), 10));
REQUIRE(math::approximately(img.pixel32(2,0), color32::blue(), 10));
REQUIRE(filesystem::try_read_all(buf, "image_save_test.png"));
REQUIRE(images::try_load_image(img, buf));
REQUIRE(img.size() == v2u(3,1));
REQUIRE(img.format() == image_data_format::rgb8);
REQUIRE(math::approximately(img.pixel32(0,0), color32::red(), 0));
REQUIRE(math::approximately(img.pixel32(1,0), color32::green(), 0));
REQUIRE(math::approximately(img.pixel32(2,0), color32::blue(), 0));
REQUIRE(filesystem::try_read_all(buf, "image_save_test.tga"));
REQUIRE(images::try_load_image(img, buf));
REQUIRE(img.size() == v2u(3,1));
REQUIRE(img.format() == image_data_format::rgb8);
REQUIRE(math::approximately(img.pixel32(0,0), color32::red(), 0));
REQUIRE(math::approximately(img.pixel32(1,0), color32::green(), 0));
REQUIRE(math::approximately(img.pixel32(2,0), color32::blue(), 0));
}
}
{
REQUIRE(filesystem::remove_file("image_save_test.jpg"));
REQUIRE(filesystem::remove_file("image_save_test.png"));
REQUIRE(filesystem::remove_file("image_save_test.tga"));
const u8 img_data[] = {255,0,0, 0,255,0, 0,0,255};
image img(v2u(3,1), image_data_format::rgb8, buffer(img_data, sizeof(img_data)));
REQUIRE(images::try_save_image(
img,
image_file_format::jpg,
make_write_file("image_save_test.jpg", false)));
REQUIRE(filesystem::file_exists("image_save_test.jpg"));
REQUIRE(images::try_save_image(
img,
image_file_format::png,
make_write_file("image_save_test.png", false)));
REQUIRE(filesystem::file_exists("image_save_test.png"));
REQUIRE(images::try_save_image(
img,
image_file_format::tga,
make_write_file("image_save_test.tga", false)));
REQUIRE(filesystem::file_exists("image_save_test.tga"));
}
{
image img;
REQUIRE(images::try_load_image(img, make_read_file("image_save_test.jpg")));
REQUIRE(img.size() == v2u(3,1));
REQUIRE(img.format() == image_data_format::rgb8);
REQUIRE(math::approximately(img.pixel32(0,0), color32::red(), 10u));
REQUIRE(math::approximately(img.pixel32(1,0), color32::green(), 10u));
REQUIRE(math::approximately(img.pixel32(2,0), color32::blue(), 10u));
str resources;
REQUIRE(filesystem::extract_predef_path(
resources,
filesystem::predef_path::resources));
REQUIRE(images::try_load_image(img, make_read_file("image_save_test.png")));
REQUIRE(img.size() == v2u(3,1));
REQUIRE(img.format() == image_data_format::rgb8);
REQUIRE(math::approximately(img.pixel32(0,0), color32::red(), 0u));
REQUIRE(math::approximately(img.pixel32(1,0), color32::green(), 0u));
REQUIRE(math::approximately(img.pixel32(2,0), color32::blue(), 0u));
REQUIRE(images::try_load_image(img, make_read_file("image_save_test.tga")));
REQUIRE(img.size() == v2u(3,1));
REQUIRE(img.format() == image_data_format::rgb8);
REQUIRE(math::approximately(img.pixel32(0,0), color32::red(), 0u));
REQUIRE(math::approximately(img.pixel32(1,0), color32::green(), 0u));
REQUIRE(math::approximately(img.pixel32(2,0), color32::blue(), 0u));
}
{
REQUIRE(filesystem::remove_file("image_save_test.jpg"));
REQUIRE(filesystem::remove_file("image_save_test.png"));
REQUIRE(filesystem::remove_file("image_save_test.tga"));
const u8 img_data[] = {255,0,0, 0,255,0, 0,0,255};
image img(v2u(3,1), image_data_format::rgb8, buffer(img_data, sizeof(img_data)));
buffer buf;
REQUIRE(images::try_save_image(
img,
image_file_format::jpg,
buf));
REQUIRE(filesystem::try_write_all(buf, "image_save_test.jpg", false));
REQUIRE(images::try_save_image(
img,
image_file_format::png,
buf));
REQUIRE(filesystem::try_write_all(buf, "image_save_test.png", false));
REQUIRE(images::try_save_image(
img,
image_file_format::tga,
buf));
REQUIRE(filesystem::try_write_all(buf, "image_save_test.tga", false));
}
{
image img;
buffer buf;
REQUIRE(filesystem::try_read_all(buf, "image_save_test.jpg"));
REQUIRE(images::try_load_image(img, buf));
REQUIRE(img.size() == v2u(3,1));
REQUIRE(img.format() == image_data_format::rgb8);
REQUIRE(math::approximately(img.pixel32(0,0), color32::red(), 10));
REQUIRE(math::approximately(img.pixel32(1,0), color32::green(), 10));
REQUIRE(math::approximately(img.pixel32(2,0), color32::blue(), 10));
REQUIRE(filesystem::try_read_all(buf, "image_save_test.png"));
REQUIRE(images::try_load_image(img, buf));
REQUIRE(img.size() == v2u(3,1));
REQUIRE(img.format() == image_data_format::rgb8);
REQUIRE(math::approximately(img.pixel32(0,0), color32::red(), 0));
REQUIRE(math::approximately(img.pixel32(1,0), color32::green(), 0));
REQUIRE(math::approximately(img.pixel32(2,0), color32::blue(), 0));
REQUIRE(filesystem::try_read_all(buf, "image_save_test.tga"));
REQUIRE(images::try_load_image(img, buf));
REQUIRE(img.size() == v2u(3,1));
REQUIRE(img.format() == image_data_format::rgb8);
REQUIRE(math::approximately(img.pixel32(0,0), color32::red(), 0));
REQUIRE(math::approximately(img.pixel32(1,0), color32::green(), 0));
REQUIRE(math::approximately(img.pixel32(2,0), color32::blue(), 0));
}
{
SECTION("stb") {
struct img_info {
const char* name;
const char* path;
std::size_t size;
image_data_format format;
};
const img_info test_infos[] = {
{"bin/images/stb/ship.jpg", 64 * 128 * 3, image_data_format::rgb8},
{"bin/images/stb/ship.png", 64 * 128 * 4, image_data_format::rgba8},
{"bin/images/stb/ship.tga", 64 * 128 * 4, image_data_format::rgba8}};
for ( const auto& info : test_infos ) {
input_stream_uptr stream = make_read_file(path::combine(resources, info.path));
REQUIRE(stream);
image img;
REQUIRE(images::try_load_image(img, stream));
REQUIRE(img.format() == info.format);
REQUIRE(img.data().size() == info.size);
REQUIRE(img.size().x == 64);
REQUIRE(img.size().y == 128);
}
}
SECTION("dds") {
struct img_info {
const char* path;
std::size_t size;
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},
{"bin/images/ship_r8.pvr", true, image_data_format::g8},
{"bin/images/ship_rg8.pvr", true, image_data_format::ga8},
{"bin/images/ship_rgb8.pvr", true, image_data_format::rgb8}
const img_info test_infos[] = {
{"bin/images/dds/ship_a8.dds", 64 * 128 * 1, true, image_data_format::a8},
{"bin/images/dds/ship_l8.dds", 64 * 128 * 1, true, image_data_format::l8},
{"bin/images/dds/ship_a8l8.dds", 64 * 128 * 2, true, image_data_format::la8},
{"bin/images/dds/ship_r8g8b8.dds", 64 * 128 * 3, true, image_data_format::rgb8},
{"bin/images/dds/ship_x8r8g8b8.dds", 64 * 128 * 3, true, image_data_format::rgb8},
{"bin/images/dds/ship_rgba8.dds", 64 * 128 * 4, true, image_data_format::rgba8},
{"bin/images/dds/ship_a8r8g8b8.dds", 64 * 128 * 4, true, image_data_format::rgba8},
{"bin/images/dds/ship_dxt1.dds", 64 * 128 * 4 / 8, true, image_data_format::rgba_dxt1},
{"bin/images/dds/ship_dxt3.dds", 64 * 128 * 8 / 8, true, image_data_format::rgba_dxt3},
{"bin/images/dds/ship_dxt5.dds", 64 * 128 * 8 / 8, true, image_data_format::rgba_dxt5},
};
str resources;
REQUIRE(filesystem::extract_predef_path(
resources,
filesystem::predef_path::resources));
for ( const auto& info : test_infos ) {
CAPTURE(info.path);
for ( const auto& info : test_images ) {
input_stream_uptr stream = make_read_file(path::combine(resources, info.name));
REQUIRE(stream);
image img;
REQUIRE(images::try_load_image(img, stream) == info.can_load);
REQUIRE(info.can_load == images::try_load_image(
img,
make_read_file(path::combine(resources, info.path))));
if ( info.can_load ) {
REQUIRE(img.format() == info.format);
REQUIRE(img.data().size() == info.size);
REQUIRE(img.size().x == 64);
REQUIRE(img.size().y == 128);
REQUIRE(img.data().size() > 0);
}
}
for ( const auto& info : test_infos ) {
CAPTURE(info.path);
if ( !info.can_load ) {
continue;
}
image img;
REQUIRE(images::try_load_image(
img,
make_read_file(path::combine(resources, info.path))));
REQUIRE(filesystem::remove_file("image_save_test.dds"));
REQUIRE(images::try_save_image(
img,
image_file_format::dds, make_write_file("image_save_test.dds", false)));
image img2;
REQUIRE(images::try_load_image(
img2,
make_read_file("image_save_test.dds")));
REQUIRE(img == img2);
}
}
SECTION("dds_bgr") {
{
image img;
REQUIRE(images::try_load_image(
img,
make_read_file(path::combine(resources, "bin/images/dds/ship_r8g8b8.dds"))));
image img2;
REQUIRE(images::try_load_image(
img2,
make_read_file(path::combine(resources, "bin/images/dds/ship_r8g8b8.dds"))));
image img3;
REQUIRE(images::try_load_image(
img3,
make_read_file(path::combine(resources, "bin/images/dds/ship_x8r8g8b8.dds"))));
REQUIRE(img == img2);
REQUIRE(img2 == img3);
}
{
image img;
REQUIRE(images::try_load_image(
img,
make_read_file(path::combine(resources, "bin/images/dds/ship_rgba8.dds"))));
image img2;
REQUIRE(images::try_load_image(
img2,
make_read_file(path::combine(resources, "bin/images/dds/ship_a8r8g8b8.dds"))));
REQUIRE(img == img2);
}
}
SECTION("pvr") {
struct img_info {
const char* path;
std::size_t size;
bool can_load;
image_data_format format;
};
const img_info test_infos[] = {
{"bin/images/pvr/ship_a8.pvr", 64 * 128 * 1, true, image_data_format::a8},
{"bin/images/pvr/ship_l8.pvr", 64 * 128 * 1, true, image_data_format::l8},
{"bin/images/pvr/ship_la8.pvr", 64 * 128 * 2, true, image_data_format::la8},
{"bin/images/pvr/ship_rgb8.pvr", 64 * 128 * 3, true, image_data_format::rgb8},
{"bin/images/pvr/ship_rgba8.pvr", 64 * 128 * 4, true, image_data_format::rgba8},
{"bin/images/pvr/ship_bgra8.pvr", 64 * 128 * 4, true, image_data_format::rgba8},
{"bin/images/pvr/ship_dxt1.pvr", 64 * 128 * 4 / 8, true, image_data_format::rgba_dxt1},
{"bin/images/pvr/ship_dxt3.pvr", 64 * 128 * 8 / 8, true, image_data_format::rgba_dxt3},
{"bin/images/pvr/ship_dxt5.pvr", 64 * 128 * 8 / 8, true, image_data_format::rgba_dxt5},
{"bin/images/pvr/ship_etc1.pvr", 64 * 128 * 4 / 8, true, image_data_format::rgb_etc1},
{"bin/images/pvr/ship_etc2_rgb.pvr", 64 * 128 * 4 / 8, true, image_data_format::rgb_etc2},
{"bin/images/pvr/ship_etc2_rgba.pvr", 64 * 128 * 8 / 8, true, image_data_format::rgba_etc2},
{"bin/images/pvr/ship_etc2_rgb_a1.pvr", 64 * 128 * 4 / 8, true, image_data_format::rgb_a1_etc2},
{"bin/images/pvr/ship_astc4x4.pvr", ((64+3)/4) * ((128+3)/4) * 16, true, image_data_format::rgba_astc4x4},
{"bin/images/pvr/ship_astc5x5.pvr", ((64+4)/5) * ((128+4)/5) * 16, true, image_data_format::rgba_astc5x5},
{"bin/images/pvr/ship_astc6x6.pvr", ((64+5)/6) * ((128+5)/6) * 16, true, image_data_format::rgba_astc6x6},
{"bin/images/pvr/ship_astc8x8.pvr", ((64+7)/8) * ((128+7)/8) * 16, true, image_data_format::rgba_astc8x8},
{"bin/images/pvr/ship_astc10x10.pvr", ((64+9)/10) * ((128+9)/10) * 16, true, image_data_format::rgba_astc10x10},
{"bin/images/pvr/ship_astc12x12.pvr", ((64+11)/12) * ((128+11)/12) * 16, true, image_data_format::rgba_astc12x12},
{"bin/images/pvr/ship_pvrtc_2bpp_rgb.pvr", 64 * 128 * 2 / 8, true, image_data_format::rgb_pvrtc2},
{"bin/images/pvr/ship_pvrtc_2bpp_rgba.pvr", 64 * 128 * 2 / 8, true, image_data_format::rgba_pvrtc2},
{"bin/images/pvr/ship_pvrtc_4bpp_rgb.pvr", 64 * 128 * 4 / 8, true, image_data_format::rgb_pvrtc4},
{"bin/images/pvr/ship_pvrtc_4bpp_rgba.pvr", 64 * 128 * 4 / 8, true, image_data_format::rgba_pvrtc4},
{"bin/images/pvr/ship_pvrtc2_2bpp.pvr", 64 * 128 * 2 / 8, true, image_data_format::rgba_pvrtc2_v2},
{"bin/images/pvr/ship_pvrtc2_4bpp.pvr", 64 * 128 * 4 / 8, true, image_data_format::rgba_pvrtc4_v2},
{"bin/images/pvr/ship_eac_r11.pvr", 0, false, image_data_format(-1)},
{"bin/images/pvr/ship_eac_rg11.pvr", 0, false, image_data_format(-1)},
};
for ( const auto& info : test_infos ) {
CAPTURE(info.path);
image img;
REQUIRE(info.can_load == images::try_load_image(
img,
make_read_file(path::combine(resources, info.path))));
if ( info.can_load ) {
REQUIRE(img.format() == info.format);
REQUIRE(img.data().size() == info.size);
REQUIRE(img.size().x == 64);
REQUIRE(img.size().y == 128);
}
}
for ( const auto& info : test_infos ) {
CAPTURE(info.path);
if ( !info.can_load ) {
continue;
}
image img;
REQUIRE(images::try_load_image(
img,
make_read_file(path::combine(resources, info.path))));
REQUIRE(filesystem::remove_file("image_save_test.pvr"));
REQUIRE(images::try_save_image(
img,
image_file_format::pvr, make_write_file("image_save_test.pvr", false)));
image img2;
REQUIRE(images::try_load_image(
img2,
make_read_file("image_save_test.pvr")));
REQUIRE(img == img2);
}
}
SECTION("pvr_bgr") {
{
image img;
REQUIRE(images::try_load_image(
img,
make_read_file(path::combine(resources, "bin/images/pvr/ship_rgba8.pvr"))));
image img2;
REQUIRE(images::try_load_image(
img2,
make_read_file(path::combine(resources, "bin/images/pvr/ship_bgra8.pvr"))));
REQUIRE(img == img2);
}
}
}