Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

png loader: fix grayscale/alpha images bug #813

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions src/nbl/asset/interchange/CImageLoaderPNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ asset::SAssetBundle CImageLoaderPng::loadAsset(system::IFile* _file, const asset

if (ColorType == PNG_COLOR_TYPE_PALETTE)
png_set_palette_to_rgb(png_ptr);
else if (ColorType == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);

// Convert low bit colors to 8 bit colors
if (BitDepth < 8)
Expand Down Expand Up @@ -238,7 +240,6 @@ asset::SAssetBundle CImageLoaderPng::loadAsset(system::IFile* _file, const asset
imgInfo.flags = static_cast<IImage::E_CREATE_FLAGS>(0u);
core::smart_refctd_ptr<ICPUImage> image = nullptr;

bool lumaAlphaType = false;
switch (ColorType) {
case PNG_COLOR_TYPE_RGB_ALPHA:
imgInfo.format = EF_R8G8B8A8_SRGB;
Expand All @@ -251,7 +252,6 @@ asset::SAssetBundle CImageLoaderPng::loadAsset(system::IFile* _file, const asset
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
imgInfo.format = EF_R8G8B8A8_SRGB;
lumaAlphaType = true;
break;
default:
{
Expand Down Expand Up @@ -309,20 +309,6 @@ asset::SAssetBundle CImageLoaderPng::loadAsset(system::IFile* _file, const asset
png_read_image(png_ptr, RowPointers);

png_read_end(png_ptr, nullptr);
if (lumaAlphaType)
{
assert(imgInfo.format==asset::EF_R8G8B8A8_SRGB);
for (uint32_t i=0u; i<Height; ++i)
for (uint32_t j=0u; j<Width;)
{
uint32_t in = reinterpret_cast<uint16_t*>(RowPointers[i])[j];
j++;
auto& out = reinterpret_cast<uint32_t*>(RowPointers[i])[Width-j];
out = in|(in << 16u); // LXLA
out &= 0xffff00ffu;
out |= (in&0xffu) << 8u;
}
}
_NBL_DELETE_ARRAY(RowPointers, Height);
png_destroy_read_struct(&png_ptr,&info_ptr, 0); // Clean up memory
#else
Expand Down