diff --git a/Userland/Libraries/LibGfx/Bitmap.h b/Userland/Libraries/LibGfx/Bitmap.h index 8b61a7d5faa..75369b2ddea 100644 --- a/Userland/Libraries/LibGfx/Bitmap.h +++ b/Userland/Libraries/LibGfx/Bitmap.h @@ -177,6 +177,20 @@ public: void fill(Color); [[nodiscard]] bool has_alpha_channel() const { return m_format == BitmapFormat::BGRA8888 || m_format == BitmapFormat::RGBA8888; } + void add_alpha_channel() + { + switch (m_format) { + case BitmapFormat::BGRx8888: + m_format = BitmapFormat::BGRA8888; + break; + case BitmapFormat::RGBA8888: + case BitmapFormat::BGRA8888: + // Nothing to do. + break; + case BitmapFormat::Invalid: + VERIFY_NOT_REACHED(); + } + } [[nodiscard]] BitmapFormat format() const { return m_format; } // Call only for BGRx8888 and BGRA8888 bitmaps. diff --git a/Userland/Libraries/LibPDF/Renderer.cpp b/Userland/Libraries/LibPDF/Renderer.cpp index ed4fa40e212..bde2d63a569 100644 --- a/Userland/Libraries/LibPDF/Renderer.cpp +++ b/Userland/Libraries/LibPDF/Renderer.cpp @@ -986,6 +986,7 @@ PDFErrorOr Renderer::show_image(NonnullRefPtr image) if (smask_bitmap->size() != image_bitmap->size()) smask_bitmap = TRY(smask_bitmap->scaled_to_size(image_bitmap->size())); + image_bitmap->add_alpha_channel(); for (int j = 0; j < image_bitmap->height(); ++j) { for (int i = 0; i < image_bitmap->width(); ++i) { auto image_color = image_bitmap->get_pixel(i, j);