1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

LibGfx+LibGUI: Make Gfx::ShareableBitmap transmit indexed palettes

This commit is contained in:
Andreas Kling 2021-01-16 23:57:57 +01:00
parent b5d98c0945
commit 8a61aba1e5
5 changed files with 49 additions and 15 deletions

View file

@ -52,9 +52,14 @@ bool encode(Encoder& encoder, const Gfx::ShareableBitmap& shareable_bitmap)
encoder << shareable_bitmap.is_valid();
if (!shareable_bitmap.is_valid())
return true;
encoder << IPC::File(shareable_bitmap.bitmap()->anon_fd());
encoder << shareable_bitmap.width();
encoder << shareable_bitmap.height();
auto& bitmap = *shareable_bitmap.bitmap();
encoder << IPC::File(bitmap.anon_fd());
encoder << bitmap.size();
encoder << (u32)bitmap.format();
if (bitmap.is_indexed()) {
auto palette = bitmap.palette_to_vector();
encoder << palette;
}
return true;
}
@ -68,13 +73,23 @@ bool decode(Decoder& decoder, Gfx::ShareableBitmap& shareable_bitmap)
return true;
}
IPC::File anon_file;
Gfx::IntSize size;
if (!decoder.decode(anon_file))
return false;
Gfx::IntSize size;
if (!decoder.decode(size))
return false;
auto bitmap = Gfx::Bitmap::create_with_anon_fd(Gfx::BitmapFormat::RGBA32, anon_file.take_fd(), size, Gfx::Bitmap::ShouldCloseAnonymousFile::Yes);
u32 raw_bitmap_format;
if (!decoder.decode(raw_bitmap_format))
return false;
if (!Gfx::is_valid_bitmap_format(raw_bitmap_format))
return false;
auto bitmap_format = (Gfx::BitmapFormat)raw_bitmap_format;
Vector<Gfx::RGBA32> palette;
if (Gfx::Bitmap::is_indexed(bitmap_format)) {
if (!decoder.decode(palette))
return false;
}
auto bitmap = Gfx::Bitmap::create_with_anon_fd(bitmap_format, anon_file.take_fd(), size, palette, Gfx::Bitmap::ShouldCloseAnonymousFile::Yes);
if (!bitmap)
return false;
shareable_bitmap = Gfx::ShareableBitmap { bitmap.release_nonnull(), Gfx::ShareableBitmap::ConstructWithKnownGoodBitmap };