From b5ebdb8bff69f527047392146817193dcae7a881 Mon Sep 17 00:00:00 2001 From: Aaron Barany Date: Wed, 30 Dec 2020 20:34:20 -0800 Subject: [PATCH] Better handle HDR ASTC textures. sRGB color space is only supported with the LDR profile, so perform sRGB conversion before conversion. Also support HDR vs LDR for alpha channels based on the alpha type. --- lib/src/AstcConverter.cpp | 17 +++++++++++++---- lib/src/AstcConverter.h | 2 +- lib/src/Texture.cpp | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/src/AstcConverter.cpp b/lib/src/AstcConverter.cpp index f18bb21..4932264 100644 --- a/lib/src/AstcConverter.cpp +++ b/lib/src/AstcConverter.cpp @@ -101,7 +101,7 @@ class AstcConverter::AstcThreadData : public Converter::ThreadData } astcenc_config config; - astcenc_config_init(converter.m_hdr ? ASTCENC_PRF_HDR : ASTCENC_PRF_LDR, converter.m_blockX, + astcenc_config_init(static_cast(converter.m_hdr), converter.m_blockX, converter.m_blockY, 1, preset, flags, config); astcenc_context_alloc(config, 1, &context); @@ -156,8 +156,17 @@ AstcConverter::AstcConverter(const Texture& texture, const Image& image, unsigne : Converter(image), m_blockX(blockX), m_blockY(blockY), m_jobsX((image.width() + blockX - 1)/blockX), m_jobsY((image.height() + blockY - 1)/blockY), m_quality(quality), m_alphaType(texture.alphaType()), m_colorSpace(texture.colorSpace()), - m_colorMask(texture.colorMask()), m_hdr(texture.type() == Texture::Type::UFloat) + m_colorMask(texture.colorMask()) { + if (texture.type() == Texture::Type::UFloat) + { + if (m_alphaType == Texture::Alpha::None || m_alphaType == Texture::Alpha::PreMultiplied) + m_hdr = ASTCENC_PRF_HDR_RGB_LDR_A; + else + m_hdr = ASTCENC_PRF_HDR; + } + else + m_hdr = ASTCENC_PRF_LDR; assert(texture.type() == Texture::Type::UNorm || texture.type() == Texture::Type::UFloat); data().resize(m_jobsX*m_jobsY*blockSize); } @@ -187,8 +196,8 @@ void AstcConverter::process(unsigned int x, unsigned int y, ThreadData* threadDa void* imageDataPtr = imageData; dummyImage.data = &imageDataPtr; imageblock astcBlock; - fetch_imageblock(m_hdr ? ASTCENC_PRF_HDR : ASTCENC_PRF_LDR, dummyImage, &astcBlock, - context->bsd, 0, 0, 0, astcThreadData->swizzle); + fetch_imageblock(static_cast(m_hdr), dummyImage, &astcBlock, context->bsd, 0, + 0, 0, astcThreadData->swizzle); if (astcThreadData->context->input_averages) { diff --git a/lib/src/AstcConverter.h b/lib/src/AstcConverter.h index a95d860..22e9261 100644 --- a/lib/src/AstcConverter.h +++ b/lib/src/AstcConverter.h @@ -54,7 +54,7 @@ class AstcConverter : public Converter Texture::Alpha m_alphaType; ColorSpace m_colorSpace; Texture::ColorMask m_colorMask; - bool m_hdr; + unsigned int m_hdr; }; } // namespace cuttlefish diff --git a/lib/src/Texture.cpp b/lib/src/Texture.cpp index 14518fd..e751a1c 100644 --- a/lib/src/Texture.cpp +++ b/lib/src/Texture.cpp @@ -254,7 +254,7 @@ bool Texture::hasNativeSRGB(Format format, Type type) case Format::ASTC_10x10: case Format::ASTC_12x10: case Format::ASTC_12x12: - return type == Type::UNorm || type == Type::UFloat; + return type == Type::UNorm; default: return false;