Skip to content

Commit

Permalink
#5448: Add (currently failing) test case loading an 8-Bit Greyscale P…
Browse files Browse the repository at this point in the history
…NG with alpha channel
  • Loading branch information
codereader committed Dec 20, 2020
1 parent ec5c1af commit 906af04
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/ImageLoading.cpp
@@ -1,6 +1,7 @@
#include "RadiantTest.h"

#include "iimage.h"
#include "RGBAImage.h"

namespace test
{
Expand All @@ -25,4 +26,35 @@ TEST_F(ImageLoadingTest, LoadPng16Bit)
EXPECT_EQ(img->getHeight(), 32);
}

TEST_F(ImageLoadingTest, LoadPngGreyscaleWithAlpha)
{
// This is a 8-Bit Greyscale PNG with Alpha channel, so pixel depth is 16 bits
auto filePath = _context.getTestProjectPath() + "textures/pngs/transparent_greyscale.png";
auto img = GlobalImageLoader().imageFromFile(filePath);

EXPECT_EQ(img->getWidth(), 32);
EXPECT_EQ(img->getHeight(), 32);
EXPECT_FALSE(img->isPrecompressed());

// If the image loader interprets the file correctly, we should have an RGBA
// image with the colour values being the same for R, G and B.
// If the image loader didn't convert grey to RGB, the grey value is
// smeared across the whole RGB channels and they are not uniform

EXPECT_TRUE(std::dynamic_pointer_cast<RGBAImage>(img));
auto pixels = reinterpret_cast<RGBAPixel*>(img->getPixels());

auto numPixels = img->getWidth() * img->getHeight();
for (auto i = 0; i < numPixels; ++i)
{
EXPECT_EQ(pixels[i].blue, pixels[i].green) << "Expected Green == Blue";
EXPECT_EQ(pixels[i].red, pixels[i].green) << "Expected Red == Blue";

if (pixels[i].blue != pixels[i].green || pixels[i].red != pixels[i].green)
{
break;
}
}
}

}
17 changes: 17 additions & 0 deletions test/resources/tdm/materials/pngs.mtr
Expand Up @@ -7,3 +7,20 @@ textures/pngs/twentyone_16bit
{
diffusemap textures/pngs/twentyone_16bit
}

textures/pngs/transparent_greyscale
{
DECAL_MACRO
noShadows
nonsolid
noimpact
translucent

qer_editorimage textures/pngs/transparent_greyscale
description "256 x 256"

{
blend gl_src_alpha, gl_one_minus_src_alpha
map textures/pngs/transparent_greyscale
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 906af04

Please sign in to comment.