Navigation Menu

Skip to content

Commit

Permalink
Fixed|GL|Textures: Outline visible on external images
Browse files Browse the repository at this point in the history
External images did not undergo bilinear filtering outline reduction. Now the RGB values of transparent pixels is set to the average of the surrounding non-transparent pixels.

IssueID #2364
  • Loading branch information
skyjake committed Jan 5, 2020
1 parent 341ddc2 commit 11bdcc3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doomsday/apps/client/include/gl/gl_tex.h
Expand Up @@ -98,6 +98,8 @@ void BlackOutlines(uint8_t* pixels, int width, int height);
*/
void ColorOutlinesIdx(uint8_t* pixels, int width, int height);

void ColorOutlinesRGBA(uint8_t *buffer, int width, int height);

/**
* @param pixels RGB(a) image to be desaturated (in/out).
* @param width Width of the image in pixels.
Expand Down
45 changes: 45 additions & 0 deletions doomsday/apps/client/src/gl/gl_tex.cpp
Expand Up @@ -1261,6 +1261,51 @@ void ColorOutlinesIdx(uint8_t* buffer, int width, int height)
}
}

void ColorOutlinesRGBA(uint8_t *buffer, int width, int height)
{
using namespace de;

uint32_t *buffer32 = reinterpret_cast<uint32_t *>(buffer);

for (int y = 0; y < height; ++y)
{
uint32_t *row = buffer32 + y * width;
for (int x = 0; x < width; ++x)
{
if ((row[x] & 0xff000000) == 0) // transparent pixel
{
int average[3]{};
int count = 0;
for (int dy = -1; dy <= 1; ++dy)
{
for (int dx = -1; dx <= 1; ++dx)
{
if (!(dx || dy)) continue; // the current pixel

const Vec2i pos(x + dx, y + dy);
if (pos.x >= 0 && pos.y >= 0 && pos.x < width && pos.y < height)
{
const uint32_t adjacent = buffer32[pos.y * width + pos.x];
if (adjacent & 0xff000000) // non-transparent pixel
{
average[0] += adjacent & 0xff;
average[1] += (adjacent >> 8) & 0xff;
average[2] += (adjacent >> 16) & 0xff;
++count;
}
}
}
}
if (count)
{
for (int &c : average) c /= count;
}
row[x] = average[0] | (average[1] << 8) | (average[2] << 16);
}
}
}
}

void EqualizeLuma(uint8_t* pixels, int width, int height, float* rBaMul,
float* rHiMul, float* rLoMul)
{
Expand Down
9 changes: 7 additions & 2 deletions doomsday/apps/client/src/gl/texturecontent.cpp
Expand Up @@ -176,7 +176,7 @@ static dgltexformat_t prepareImageAsTexture(image_t &image,
}
image.pixelSize = 2;
}
else if (0 != image.paletteId)
else if (image.paletteId)
{
if (fillOutlines && (image.flags & IMGF_IS_MASKED))
{
Expand Down Expand Up @@ -256,7 +256,12 @@ static dgltexformat_t prepareImageAsTexture(image_t &image,
}
}
else if (image.pixelSize > 2)
{
{
if (fillOutlines && image.pixelSize == 4)
{
ColorOutlinesRGBA(image.pixels, image.size.x, image.size.y);
}

if (monochrome)
{
Image_ConvertToLuminance(image);
Expand Down

0 comments on commit 11bdcc3

Please sign in to comment.