1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

LibPDF+LibGfx: Make SMasks on jpeg images work

SMasks are greyscale images that get used as alpha channel for a
different image.

JPEGs in PDFs are stored as streams with /DCTDecode filters, and
we have a separate code path for loading those in the PDF renderer.
That code path just calls our JPEG decoder, which creates bitmaps
with format BGRx8888.

So when we process an SMask for such a bitmap, we have to change
the bitmap's format to BGRA8888 in addition to setting alpha values
on all pixels.
This commit is contained in:
Nico Weber 2023-11-22 20:31:38 -05:00 committed by Andreas Kling
parent ef809eea1e
commit eb1c99bd72
2 changed files with 15 additions and 0 deletions

View file

@ -986,6 +986,7 @@ PDFErrorOr<void> Renderer::show_image(NonnullRefPtr<StreamObject> 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);