Skip to content

Commit

Permalink
Better handle HDR ASTC textures.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akb825 committed Dec 31, 2020
1 parent 63a8d17 commit b5ebdb8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions lib/src/AstcConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<astcenc_profile>(converter.m_hdr), converter.m_blockX,
converter.m_blockY, 1, preset, flags, config);

astcenc_context_alloc(config, 1, &context);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<astcenc_profile>(m_hdr), dummyImage, &astcBlock, context->bsd, 0,
0, 0, astcThreadData->swizzle);

if (astcThreadData->context->input_averages)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/src/AstcConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b5ebdb8

Please sign in to comment.