1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 18:10:56 +09:00

LibGfx: Add BMP loader

Adds an *almost fully featured BMP loader to process .bmp files.

Features:
- All header formats are supported
- Full RLE4/8/24 support
- Color scaling (e.g. distributing a 5-bit color throughout the 8-bit
color spectrum, so 5-bit white is still 0xffffff)
- Full BITMASK/ALPHABITMASK support

*Not included:
- 1D Huffman compression. Good luck actually finding a bmp in the wild
that uses this
- Use of any field in the V4/V5 header. Color spaces? Endpoints? No
thanks :)

This loader was tested with the images at
https://entropymine.com/jason/bmpsuite/bmpsuite/html/bmpsuite.html. This
loader correctly displays 81 out of the 90 total images (for reference,
firefox displays 64 correctly). Note that not rendering the images at
the bottom is counted as displaying correctly.
This commit is contained in:
Matthew Olsson 2020-06-17 12:37:16 -07:00 committed by Andreas Kling
parent dfe5b232f4
commit 4e093a7c23
Notes: sideshowbarker 2024-07-19 05:30:21 +09:00
8 changed files with 1477 additions and 15 deletions

View file

@ -53,6 +53,12 @@ ALWAYS_INLINE Color get_pixel(const Gfx::Bitmap& bitmap, int x, int y)
{
if constexpr (format == BitmapFormat::Indexed8)
return bitmap.palette_color(bitmap.bits(y)[x]);
if constexpr (format == BitmapFormat::Indexed4)
return bitmap.palette_color(bitmap.bits(y)[x]);
if constexpr (format == BitmapFormat::Indexed2)
return bitmap.palette_color(bitmap.bits(y)[x]);
if constexpr (format == BitmapFormat::Indexed1)
return bitmap.palette_color(bitmap.bits(y)[x]);
if constexpr (format == BitmapFormat::RGB32)
return Color::from_rgb(bitmap.scanline(y)[x]);
if constexpr (format == BitmapFormat::RGBA32)
@ -668,7 +674,7 @@ void Painter::blit(const IntPoint& position, const Gfx::Bitmap& source, const In
return;
}
if (source.format() == BitmapFormat::Indexed8) {
if (Bitmap::is_indexed(source.format())) {
const u8* src = source.bits(src_rect.top() + first_row) + src_rect.left() + first_column;
const size_t src_skip = source.pitch();
for (int row = first_row; row <= last_row; ++row) {
@ -761,6 +767,15 @@ void Painter::draw_scaled_bitmap(const IntRect& a_dst_rect, const Gfx::Bitmap& s
case BitmapFormat::Indexed8:
do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<BitmapFormat::Indexed8>);
break;
case BitmapFormat::Indexed4:
do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<BitmapFormat::Indexed4>);
break;
case BitmapFormat::Indexed2:
do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<BitmapFormat::Indexed2>);
break;
case BitmapFormat::Indexed1:
do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<BitmapFormat::Indexed1>);
break;
default:
do_draw_scaled_bitmap<true>(*m_target, dst_rect, clipped_rect, source, src_rect, hscale, vscale, get_pixel<BitmapFormat::Invalid>);
break;