diff --git a/headers/enduro2d/utils/image.hpp b/headers/enduro2d/utils/image.hpp index 95d0d4eb..032c0dd7 100644 --- a/headers/enduro2d/utils/image.hpp +++ b/headers/enduro2d/utils/image.hpp @@ -20,9 +20,7 @@ namespace e2d jpg, png, pvr, - tga, - - unknown + tga }; enum class image_data_format : u8 { @@ -39,9 +37,7 @@ namespace e2d rgb_pvrtc4, rgba_pvrtc2, - rgba_pvrtc4, - - unknown + rgba_pvrtc4 }; class bad_image_access final : public exception { @@ -94,7 +90,7 @@ namespace e2d private: buffer data_; v2u size_; - image_data_format format_ = image_data_format::unknown; + image_data_format format_ = image_data_format::rgba8; }; void swap(image& l, image& r) noexcept; diff --git a/sources/enduro2d/utils/image.cpp b/sources/enduro2d/utils/image.cpp index 966588c7..68018302 100644 --- a/sources/enduro2d/utils/image.cpp +++ b/sources/enduro2d/utils/image.cpp @@ -32,9 +32,7 @@ namespace {8, 2, image_data_format::rgb_pvrtc2, true, true, true}, {8, 4, image_data_format::rgb_pvrtc4, true, true, true}, {8, 2, image_data_format::rgba_pvrtc2, true, true, true}, - {8, 4, image_data_format::rgba_pvrtc4, true, true, true}, - - {0, 0, image_data_format::unknown, false, false, false} + {8, 4, image_data_format::rgba_pvrtc4, true, true, true} }; const data_format_description& get_data_format_description(image_data_format format) noexcept { @@ -67,8 +65,7 @@ namespace } bool check_image_format(const v2u& size, image_data_format format) noexcept { - return size == adjust_image_size(size, format) - && (format != image_data_format::unknown || size == v2u::zero()); + return size == adjust_image_size(size, format); } bool check_image_format(const v2u& size, image_data_format format, const buffer& data) noexcept { @@ -164,7 +161,7 @@ namespace e2d void image::clear() noexcept { data_.clear(); size_ = v2u::zero(); - format_ = image_data_format::unknown; + format_ = image_data_format::rgba8; } bool image::empty() const noexcept { @@ -183,9 +180,7 @@ namespace e2d const data_format_description& format_desc = get_data_format_description(format_); - if ( empty() || u >= size_.x || v >= size_.y ) { - throw bad_image_access(); - } else if ( format_desc.format == image_data_format::unknown || format_desc.compressed ) { + if ( empty() || u >= size_.x || v >= size_.y || format_desc.compressed ) { throw bad_image_access(); } @@ -303,8 +298,6 @@ namespace e2d { namespace images return impl::try_save_image_pvr(src, dst); case image_file_format::tga: return impl::try_save_image_tga(src, dst); - case image_file_format::unknown: - return false; default: E2D_ASSERT_MSG(false, "unexpected image file format"); return false; diff --git a/sources/enduro2d/utils/image_impl/image_reader_stb.cpp b/sources/enduro2d/utils/image_impl/image_reader_stb.cpp index 94447fdf..907287bb 100644 --- a/sources/enduro2d/utils/image_impl/image_reader_stb.cpp +++ b/sources/enduro2d/utils/image_impl/image_reader_stb.cpp @@ -48,11 +48,13 @@ namespace image_data_format image_format_from_stb_channels(u32 channels) noexcept { switch ( channels ) { - case 1: return image_data_format::g8; - case 2: return image_data_format::ga8; - case 3: return image_data_format::rgb8; - case 4: return image_data_format::rgba8; - default: return image_data_format::unknown; + case 1: return image_data_format::g8; + case 2: return image_data_format::ga8; + case 3: return image_data_format::rgb8; + case 4: return image_data_format::rgba8; + default: + E2D_ASSERT_MSG(false, "unexpected stb channel count"); + return image_data_format::rgba8; } } @@ -61,7 +63,7 @@ namespace { try { const image_data_format img_format = image_format_from_stb_channels(img_channels); - if ( img && img_size.x > 0 && img_size.y > 0 && img_format != image_data_format::unknown ) { + if ( img && img_size.x > 0 && img_size.y > 0 ) { buffer img_buffer( img.get(), math::numeric_cast(img_size.x * img_size.y * img_channels)); diff --git a/untests/sources/untests_utils/image.cpp b/untests/sources/untests_utils/image.cpp index 268f4719..c14ab301 100644 --- a/untests/sources/untests_utils/image.cpp +++ b/untests/sources/untests_utils/image.cpp @@ -11,29 +11,7 @@ TEST_CASE("images") { { image i; REQUIRE(i.size() == v2u::zero()); - REQUIRE(i.format() == image_data_format::unknown); - REQUIRE(i.data().empty()); - REQUIRE(i.empty()); - } - { - image i(v2u::zero(), image_data_format::unknown); - REQUIRE(i.size() == v2u::zero()); - REQUIRE(i.format() == image_data_format::unknown); - REQUIRE(i.data().empty()); - REQUIRE(i.empty()); - } - { - image i(v2u::zero(), image_data_format::unknown, buffer()); - REQUIRE(i.size() == v2u::zero()); - REQUIRE(i.format() == image_data_format::unknown); - REQUIRE(i.data().empty()); - REQUIRE(i.empty()); - } - { - const buffer b{}; - image i(v2u::zero(), image_data_format::unknown, b); - REQUIRE(i.size() == v2u::zero()); - REQUIRE(i.format() == image_data_format::unknown); + REQUIRE(i.format() == image_data_format::rgba8); REQUIRE(i.data().empty()); REQUIRE(i.empty()); }