SharedGraphics: Fix broken clipping in draw_bitmap().

This commit is contained in:
Andreas Kling 2019-01-25 06:37:56 +01:00
parent 5adaeeaa3b
commit 2279f5eaa6
Notes: sideshowbarker 2024-07-19 15:57:05 +09:00

View file

@ -160,17 +160,19 @@ void Painter::draw_bitmap(const Point& p, const CharacterBitmap& bitmap, Color c
Rect rect { p, bitmap.size() };
rect.move_by(m_translation);
auto clipped_rect = Rect::intersection(rect, m_clip_rect);
if (clipped_rect.is_empty())
return;
const int first_row = clipped_rect.top() - rect.top();
const int last_row = clipped_rect.bottom() - rect.top();
const int first_column = clipped_rect.left() - rect.left();
const int last_column = clipped_rect.right() - rect.left();
RGBA32* dst = m_target->scanline(rect.y() + first_row) + rect.x();
RGBA32* dst = m_target->scanline(clipped_rect.y()) + clipped_rect.x();
const size_t dst_skip = m_target->width();
const char* bitmap_row = &bitmap.bits()[first_row];
const char* bitmap_row = &bitmap.bits()[first_row * bitmap.width() + first_column];
const size_t bitmap_skip = bitmap.width();
for (int row = first_row; row <= last_row; ++row) {
for (int j = first_column; j <= last_column; ++j) {
for (int j = 0; j <= (last_column - first_column); ++j) {
char fc = bitmap_row[j];
if (fc == '#')
dst[j] = color.value();