mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
SharedGraphics: Optimize Painter::draw_bitmap().
Manually peel as much as possible out of the loop for a ~100% speedup.
This commit is contained in:
parent
267a903dd0
commit
8a3af99416
1 changed files with 18 additions and 13 deletions
|
@ -118,21 +118,26 @@ void Painter::draw_rect(const Rect& a_rect, Color color)
|
||||||
|
|
||||||
void Painter::draw_bitmap(const Point& p, const CharacterBitmap& bitmap, Color color)
|
void Painter::draw_bitmap(const Point& p, const CharacterBitmap& bitmap, Color color)
|
||||||
{
|
{
|
||||||
Point point = p;
|
Rect rect { p, bitmap.size() };
|
||||||
point.move_by(m_translation);
|
rect.move_by(m_translation);
|
||||||
for (unsigned row = 0; row < bitmap.height(); ++row) {
|
auto clipped_rect = Rect::intersection(rect, m_clip_rect);
|
||||||
int y = point.y() + row;
|
const int first_row = clipped_rect.top() - rect.top();
|
||||||
if (y < m_clip_rect.top() || y > m_clip_rect.bottom())
|
const int last_row = clipped_rect.bottom() - rect.top();
|
||||||
continue;
|
const int first_column = clipped_rect.left() - rect.left();
|
||||||
auto* bits = m_target->scanline(y);
|
const int last_column = clipped_rect.right() - rect.left();
|
||||||
for (unsigned j = 0; j < bitmap.width(); ++j) {
|
RGBA32* dst = m_target->scanline(rect.y() + first_row) + rect.x();
|
||||||
int x = point.x() + j;
|
const size_t dst_skip = m_target->width();
|
||||||
if (x < m_clip_rect.left() || x > m_clip_rect.right())
|
const char* bitmap_row = &bitmap.bits()[first_row];
|
||||||
continue;
|
const size_t bitmap_skip = bitmap.width();
|
||||||
char fc = bitmap.bits()[row * bitmap.width() + j];
|
|
||||||
|
for (int row = first_row; row <= last_row; ++row) {
|
||||||
|
for (int j = first_column; j <= last_column; ++j) {
|
||||||
|
char fc = bitmap_row[j];
|
||||||
if (fc == '#')
|
if (fc == '#')
|
||||||
bits[x] = color.value();
|
dst[j] = color.value();
|
||||||
}
|
}
|
||||||
|
bitmap_row += bitmap_skip;
|
||||||
|
dst += dst_skip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue