Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix alpha compositing in ft2font's draw_bitmap. #30043

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
Loading
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
13 changes: 12 additions & 1 deletion 13 src/ft2font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ void FT2Image::resize(long width, long height)
}
}

static std::array<uint8_t, 0x10000> const alpha_cov_merge_table{[]() {
auto table = std::array<uint8_t, 0x10000>{};
for (auto dst = 0; dst < 0x100; ++dst) {
for (auto src = 0; src < 0x100; ++src) {
table[(dst << 8) + src] = dst + src - (dst * src + 0x7f) / 0xff;
}
}
return table;
} ()};

void FT2Image::draw_bitmap(FT_Bitmap *bitmap, FT_Int x, FT_Int y)
{
FT_Int image_width = (FT_Int)m_width;
Expand All @@ -124,7 +134,8 @@ void FT2Image::draw_bitmap(FT_Bitmap *bitmap, FT_Int x, FT_Int y)
unsigned char *dst = m_buffer + (i * image_width + x1);
unsigned char *src = bitmap->buffer + (((i - y_offset) * bitmap->pitch) + x_start);
for (FT_Int j = x1; j < x2; ++j, ++dst, ++src)
*dst |= *src;
// Provide a fast-path for the common case of black background.
*dst = *dst ? alpha_cov_merge_table[(*dst << 8) + *src] : *src;
}
} else if (bitmap->pixel_mode == FT_PIXEL_MODE_MONO) {
for (FT_Int i = y1; i < y2; ++i) {
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.