From 03ff8ba4e7abae20405e5964b3c5936a34e64daf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Sat, 25 Jun 2022 13:16:51 +0200 Subject: [PATCH] save texture to file: support R8_UNORM format --- WickedEngine/wiHelper.cpp | 14 ++++++++++---- WickedEngine/wiVersion.cpp | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/WickedEngine/wiHelper.cpp b/WickedEngine/wiHelper.cpp index ed56af51b..33cb2560d 100644 --- a/WickedEngine/wiHelper.cpp +++ b/WickedEngine/wiHelper.cpp @@ -249,6 +249,7 @@ namespace wi::helper basisu::image basis_image; basisu::vector basis_mipmaps; + int dst_channel_count = 4; if (desc.format == Format::R10G10B10A2_UNORM) { // This will be converted first to rgba8 before saving to common format: @@ -343,6 +344,11 @@ namespace wi::helper data32[i] = rgba8; } } + else if (desc.format == Format::R8_UNORM) + { + // This can be saved by reducing target channel count, no conversion needed + dst_channel_count = 1; + } else if (IsFormatBlockCompressed(desc.format)) { basisu::texture_format fmt; @@ -478,19 +484,19 @@ namespace wi::helper if (!extension.compare("JPG") || !extension.compare("JPEG")) { - write_result = stbi_write_jpg_to_func(func, &filedata, (int)mip.width, (int)mip.height, 4, mip.address, 100); + write_result = stbi_write_jpg_to_func(func, &filedata, (int)mip.width, (int)mip.height, dst_channel_count, mip.address, 100); } else if (!extension.compare("PNG")) { - write_result = stbi_write_png_to_func(func, &filedata, (int)mip.width, (int)mip.height, 4, mip.address, 0); + write_result = stbi_write_png_to_func(func, &filedata, (int)mip.width, (int)mip.height, dst_channel_count, mip.address, 0); } else if (!extension.compare("TGA")) { - write_result = stbi_write_tga_to_func(func, &filedata, (int)mip.width, (int)mip.height, 4, mip.address); + write_result = stbi_write_tga_to_func(func, &filedata, (int)mip.width, (int)mip.height, dst_channel_count, mip.address); } else if (!extension.compare("BMP")) { - write_result = stbi_write_bmp_to_func(func, &filedata, (int)mip.width, (int)mip.height, 4, mip.address); + write_result = stbi_write_bmp_to_func(func, &filedata, (int)mip.width, (int)mip.height, dst_channel_count, mip.address); } else { diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 047741762..0f3f9a203 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 60; // minor bug fixes, alterations, refactors, updates - const int revision = 101; + const int revision = 102; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);