Skip to content

Commit

Permalink
FreeType: convert premultiplied alpha to straight
Browse files Browse the repository at this point in the history
  • Loading branch information
pshurgal committed Oct 2, 2020
1 parent b1ce571 commit 1cc96e7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions misc/freetype/imgui_freetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,17 @@ namespace
}
case FT_PIXEL_MODE_BGRA:
{
#define DE_MULTIPLY(color, alpha) (ImU32)(255.0f * (float)color / (float)alpha + 0.5f)

if (multiply_table == NULL)
{
for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch)
{
for (uint32_t x = 0; x < w; x++)
dst[x] = IM_COL32(
src[x * 4 + 2],
src[x * 4 + 1],
src[x * 4],
DE_MULTIPLY(src[x * 4 + 2], src[x * 4 + 3]),
DE_MULTIPLY(src[x * 4 + 1], src[x * 4 + 3]),
DE_MULTIPLY(src[x * 4], src[x * 4 + 3]),
src[x * 4 + 3]);
}
}
Expand All @@ -301,12 +303,14 @@ namespace
{
for (uint32_t x = 0; x < w; x++)
dst[x] = IM_COL32(
multiply_table[src[x * 4 + 2]],
multiply_table[src[x * 4 + 1]],
multiply_table[src[x * 4]],
multiply_table[DE_MULTIPLY(src[x * 4 + 2], src[x * 4 + 3])],
multiply_table[DE_MULTIPLY(src[x * 4 + 1], src[x * 4 + 3])],
multiply_table[DE_MULTIPLY(src[x * 4], src[x * 4 + 3])],
multiply_table[src[x * 4 + 3]]);
}
}

#undef DE_MULTIPLY
break;
}
default:
Expand Down

0 comments on commit 1cc96e7

Please sign in to comment.