LibGfx: Add a method to copy a Bitmap to a PaintingSurface

This commit is contained in:
Tim Ledbetter 2024-11-13 10:44:50 +00:00 committed by Andreas Kling
parent 3d8ab0e67c
commit b08f12d3e6
Notes: github-actions[bot] 2024-11-13 13:39:39 +00:00
2 changed files with 10 additions and 0 deletions

View file

@ -101,6 +101,15 @@ void PaintingSurface::read_into_bitmap(Gfx::Bitmap& bitmap)
m_impl->surface->readPixels(pixmap, 0, 0);
}
void PaintingSurface::write_from_bitmap(Gfx::Bitmap& bitmap)
{
auto color_type = to_skia_color_type(bitmap.format());
auto alpha_type = bitmap.alpha_type() == Gfx::AlphaType::Premultiplied ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
auto image_info = SkImageInfo::Make(bitmap.width(), bitmap.height(), color_type, alpha_type);
SkPixmap const pixmap(image_info, bitmap.begin(), bitmap.pitch());
m_impl->surface->writePixels(pixmap, 0, 0);
}
IntSize PaintingSurface::size() const
{
return m_impl->size;

View file

@ -32,6 +32,7 @@ public:
#endif
void read_into_bitmap(Bitmap&);
void write_from_bitmap(Bitmap&);
IntSize size() const;
IntRect rect() const;