mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-21 02:08:12 +03:00
LibGfx: Add BitmapFormat::RGBA8888
This will be used by ImageData objects in LibWeb since the web spec says these store colors in RGBA8888 order. The only thing you can do with this format right now is blitting it onto a BGRA8888 bitmap.
This commit is contained in:
parent
5023331726
commit
fe861512c8
Notes:
sideshowbarker
2024-07-18 21:18:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/fe861512c8a
@ -66,6 +66,7 @@ size_t Bitmap::minimum_pitch(size_t physical_width, BitmapFormat format)
|
||||
break;
|
||||
case StorageFormat::BGRx8888:
|
||||
case StorageFormat::BGRA8888:
|
||||
case StorageFormat::RGBA8888:
|
||||
element_size = 4;
|
||||
break;
|
||||
default:
|
||||
|
@ -54,6 +54,7 @@ enum class BitmapFormat {
|
||||
Indexed8,
|
||||
BGRx8888,
|
||||
BGRA8888,
|
||||
RGBA8888,
|
||||
};
|
||||
|
||||
inline bool is_valid_bitmap_format(unsigned format)
|
||||
@ -66,6 +67,7 @@ inline bool is_valid_bitmap_format(unsigned format)
|
||||
case (unsigned)BitmapFormat::Indexed8:
|
||||
case (unsigned)BitmapFormat::BGRx8888:
|
||||
case (unsigned)BitmapFormat::BGRA8888:
|
||||
case (unsigned)BitmapFormat::RGBA8888:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -75,6 +77,7 @@ enum class StorageFormat {
|
||||
Indexed8,
|
||||
BGRx8888,
|
||||
BGRA8888,
|
||||
RGBA8888,
|
||||
};
|
||||
|
||||
static StorageFormat determine_storage_format(BitmapFormat format)
|
||||
@ -84,6 +87,8 @@ static StorageFormat determine_storage_format(BitmapFormat format)
|
||||
return StorageFormat::BGRx8888;
|
||||
case BitmapFormat::BGRA8888:
|
||||
return StorageFormat::BGRA8888;
|
||||
case BitmapFormat::RGBA8888:
|
||||
return StorageFormat::RGBA8888;
|
||||
case BitmapFormat::Indexed1:
|
||||
case BitmapFormat::Indexed2:
|
||||
case BitmapFormat::Indexed4:
|
||||
|
@ -770,6 +770,23 @@ void Painter::blit(const IntPoint& position, const Gfx::Bitmap& source, const In
|
||||
return;
|
||||
}
|
||||
|
||||
if (source.format() == BitmapFormat::RGBA8888) {
|
||||
const u32* src = source.scanline(src_rect.top() + first_row) + src_rect.left() + first_column;
|
||||
const size_t src_skip = source.pitch() / sizeof(u32);
|
||||
for (int row = first_row; row <= last_row; ++row) {
|
||||
for (int i = 0; i < clipped_rect.width(); ++i) {
|
||||
u32 rgba = src[i];
|
||||
u32 bgra = (rgba & 0xff00ff00)
|
||||
| ((rgba & 0x000000ff) << 16)
|
||||
| ((rgba & 0x00ff0000) >> 16);
|
||||
dst[i] = bgra;
|
||||
}
|
||||
dst += dst_skip;
|
||||
src += src_skip;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (Bitmap::is_indexed(source.format())) {
|
||||
const u8* src = source.scanline_u8(src_rect.top() + first_row) + src_rect.left() + first_column;
|
||||
const size_t src_skip = source.pitch();
|
||||
|
Loading…
Reference in New Issue
Block a user