mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-10-23 12:08:11 +00:00
fix: distinguish DDS formats by pixel bit depth (#1048)
Match bit depth as well as channel masks.
This commit is contained in:
2 files changed
+36
-3
No files matched your search
@@ -172,9 +172,10 @@ namespace
|
||||
|
||||
const auto* unsignedImageFormat = dynamic_cast<const ImageFormatUnsigned*>(imageFormat);
|
||||
|
||||
if (unsignedImageFormat->m_r_offset == rOffset && unsignedImageFormat->m_r_size == rSize && unsignedImageFormat->m_g_offset == gOffset
|
||||
&& unsignedImageFormat->m_g_size == gSize && unsignedImageFormat->m_b_offset == bOffset && unsignedImageFormat->m_b_size == bSize
|
||||
&& unsignedImageFormat->m_a_offset == aOffset && unsignedImageFormat->m_a_size == aSize)
|
||||
if (unsignedImageFormat->m_bits_per_pixel == pf.dwRGBBitCount && unsignedImageFormat->m_r_offset == rOffset
|
||||
&& unsignedImageFormat->m_r_size == rSize && unsignedImageFormat->m_g_offset == gOffset && unsignedImageFormat->m_g_size == gSize
|
||||
&& unsignedImageFormat->m_b_offset == bOffset && unsignedImageFormat->m_b_size == bSize && unsignedImageFormat->m_a_offset == aOffset
|
||||
&& unsignedImageFormat->m_a_size == aSize)
|
||||
{
|
||||
m_format = imageFormat;
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#include "Image/DdsLoader.h"
|
||||
#include "Image/DdsWriter.h"
|
||||
#include "Image/Texture.h"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
TEST_CASE("DDS loading distinguishes BGR pixel strides with identical channel masks", "[image][dds]")
|
||||
{
|
||||
const auto* format = GENERATE(&image::format::B8_G8_R8, &image::format::B8_G8_R8_X8);
|
||||
image::Texture2D source(format, 4, 4, true);
|
||||
source.Allocate();
|
||||
for (auto mip = 0; mip < source.GetMipMapCount(); ++mip)
|
||||
for (auto i = 0uz; i < source.GetSizeOfMipLevel(mip); ++i)
|
||||
source.GetBufferForMipLevel(mip, 0)[i] = static_cast<uint8_t>(i * 13 + mip);
|
||||
|
||||
std::stringstream file(std::ios::in | std::ios::out | std::ios::binary);
|
||||
image::DdsWriter writer;
|
||||
writer.DumpImage(file, &source);
|
||||
file.seekg(0);
|
||||
const auto loaded = image::LoadDds(file);
|
||||
REQUIRE(loaded);
|
||||
REQUIRE(loaded->GetFormat()->GetId() == format->GetId());
|
||||
REQUIRE(loaded->GetMipMapCount() == source.GetMipMapCount());
|
||||
for (auto mip = 0; mip < source.GetMipMapCount(); ++mip)
|
||||
{
|
||||
REQUIRE(loaded->GetSizeOfMipLevel(mip) == source.GetSizeOfMipLevel(mip));
|
||||
CHECK(std::memcmp(loaded->GetBufferForMipLevel(mip), source.GetBufferForMipLevel(mip, 0), source.GetSizeOfMipLevel(mip)) == 0);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user