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

ImageDecoder: Add a new service for out-of-process image decoding :^)

The new ImageDecoder service (available for members of "image" via
/tmp/portal/image) allows you to decode images in a separate process.

This will allow programs to confidently load untrusted images, since
the bulk of the security concerns are sandboxed to a separate process.

The only API right now is a synchronous IPC DecodeImage() call that
takes a shbuf with encoded image data and returns a shared buffer and
metadata for the decoded image.

It also comes with a very simple library for interfacing with the
ImageDecoder service: LibImageDecoderClient. The name is a bit of a
mouthful but I guess we can rename it later if we think of something
nicer to call it.

There's obviously a bit of overhead to spawning a separate process
for every image decode, so this is mostly only appropriate for
untrusted images (e.g stuff downloaded from the web) and not necessary
for trusted local images (e.g stuff in /res)
This commit is contained in:
Andreas Kling 2020-06-22 21:35:22 +02:00
parent b191f24f05
commit e3782a7f99
17 changed files with 491 additions and 19 deletions

View file

@ -65,6 +65,7 @@ public:
static RefPtr<Bitmap> create_wrapper(BitmapFormat, const IntSize&, size_t pitch, RGBA32*);
static RefPtr<Bitmap> load_from_file(const StringView& path);
static RefPtr<Bitmap> create_with_shared_buffer(BitmapFormat, NonnullRefPtr<SharedBuffer>&&, const IntSize&);
static RefPtr<Bitmap> create_with_shared_buffer(BitmapFormat, NonnullRefPtr<SharedBuffer>&&, const IntSize&, const Vector<RGBA32>& palette);
static bool is_path_a_supported_image_format(const StringView& path)
{
#define __ENUMERATE_IMAGE_FORMAT(Name, Ext) \
@ -102,12 +103,35 @@ public:
SharedBuffer* shared_buffer() { return m_shared_buffer.ptr(); }
const SharedBuffer* shared_buffer() const { return m_shared_buffer.ptr(); }
ALWAYS_INLINE bool is_indexed() const
{
return is_indexed(m_format);
}
ALWAYS_INLINE static bool is_indexed(BitmapFormat format)
{
return format == BitmapFormat::Indexed8 || format == BitmapFormat::Indexed4
|| format == BitmapFormat::Indexed2 || format == BitmapFormat::Indexed1;
}
size_t palette_size(BitmapFormat format) const
{
switch (format) {
case BitmapFormat::Indexed1:
return 2;
case BitmapFormat::Indexed2:
return 4;
case BitmapFormat::Indexed4:
return 16;
case BitmapFormat::Indexed8:
return 256;
default:
return 0;
}
}
Vector<RGBA32> palette_to_vector() const;
static unsigned bpp_for_format(BitmapFormat format)
{
switch (format) {
@ -186,9 +210,9 @@ private:
Yes };
Bitmap(BitmapFormat, const IntSize&, Purgeable);
Bitmap(BitmapFormat, const IntSize&, size_t pitch, RGBA32*);
Bitmap(BitmapFormat, NonnullRefPtr<SharedBuffer>&&, const IntSize&);
Bitmap(BitmapFormat, NonnullRefPtr<SharedBuffer>&&, const IntSize&, const Vector<RGBA32>& palette);
void allocate_palette_from_format(BitmapFormat);
void allocate_palette_from_format(BitmapFormat, const Vector<RGBA32>& source_palette );
IntSize m_size;
RGBA32* m_data { nullptr };