save texture to file: support R8_UNORM format

This commit is contained in:
Turánszki János
2022-06-25 13:16:51 +02:00
parent d17a3f1fbe
commit 03ff8ba4e7
2 changed files with 11 additions and 5 deletions
+10 -4
View File
@@ -249,6 +249,7 @@ namespace wi::helper
basisu::image basis_image;
basisu::vector<basisu::image> 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
{
+1 -1
View File
@@ -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);