mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00: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
3 changed files with 23 additions and 0 deletions
|
@ -66,6 +66,7 @@ size_t Bitmap::minimum_pitch(size_t physical_width, BitmapFormat format)
|
||||||
break;
|
break;
|
||||||
case StorageFormat::BGRx8888:
|
case StorageFormat::BGRx8888:
|
||||||
case StorageFormat::BGRA8888:
|
case StorageFormat::BGRA8888:
|
||||||
|
case StorageFormat::RGBA8888:
|
||||||
element_size = 4;
|
element_size = 4;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -54,6 +54,7 @@ enum class BitmapFormat {
|
||||||
Indexed8,
|
Indexed8,
|
||||||
BGRx8888,
|
BGRx8888,
|
||||||
BGRA8888,
|
BGRA8888,
|
||||||
|
RGBA8888,
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool is_valid_bitmap_format(unsigned format)
|
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::Indexed8:
|
||||||
case (unsigned)BitmapFormat::BGRx8888:
|
case (unsigned)BitmapFormat::BGRx8888:
|
||||||
case (unsigned)BitmapFormat::BGRA8888:
|
case (unsigned)BitmapFormat::BGRA8888:
|
||||||
|
case (unsigned)BitmapFormat::RGBA8888:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -75,6 +77,7 @@ enum class StorageFormat {
|
||||||
Indexed8,
|
Indexed8,
|
||||||
BGRx8888,
|
BGRx8888,
|
||||||
BGRA8888,
|
BGRA8888,
|
||||||
|
RGBA8888,
|
||||||
};
|
};
|
||||||
|
|
||||||
static StorageFormat determine_storage_format(BitmapFormat format)
|
static StorageFormat determine_storage_format(BitmapFormat format)
|
||||||
|
@ -84,6 +87,8 @@ static StorageFormat determine_storage_format(BitmapFormat format)
|
||||||
return StorageFormat::BGRx8888;
|
return StorageFormat::BGRx8888;
|
||||||
case BitmapFormat::BGRA8888:
|
case BitmapFormat::BGRA8888:
|
||||||
return StorageFormat::BGRA8888;
|
return StorageFormat::BGRA8888;
|
||||||
|
case BitmapFormat::RGBA8888:
|
||||||
|
return StorageFormat::RGBA8888;
|
||||||
case BitmapFormat::Indexed1:
|
case BitmapFormat::Indexed1:
|
||||||
case BitmapFormat::Indexed2:
|
case BitmapFormat::Indexed2:
|
||||||
case BitmapFormat::Indexed4:
|
case BitmapFormat::Indexed4:
|
||||||
|
|
|
@ -770,6 +770,23 @@ void Painter::blit(const IntPoint& position, const Gfx::Bitmap& source, const In
|
||||||
return;
|
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())) {
|
if (Bitmap::is_indexed(source.format())) {
|
||||||
const u8* src = source.scanline_u8(src_rect.top() + first_row) + src_rect.left() + first_column;
|
const u8* src = source.scanline_u8(src_rect.top() + first_row) + src_rect.left() + first_column;
|
||||||
const size_t src_skip = source.pitch();
|
const size_t src_skip = source.pitch();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue