From 3c2d8203914a596ba3fca7b20702ed2b5a52f0bc Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 18 Oct 2023 10:57:41 -0400 Subject: [PATCH] LibPDF: If softmask has different size than target bitmap, resize it Size of smask and image aren't guaranteed to be equal by the spec (...except for /Matte, see page 555 of the PDF 1.7 spec, but we don't implement that), and in pratice they sometimes aren't. Fixes an assert on page 4 of https://devstreaming-cdn.apple.com/videos/wwdc/2017/821kjtggolzxsv/821/821_get_started_with_display_p3.pdf We now make it all the way to page 43 of 64 before crashing. --- Userland/Libraries/LibPDF/Renderer.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibPDF/Renderer.cpp b/Userland/Libraries/LibPDF/Renderer.cpp index cd6dd30740..a306eb4855 100644 --- a/Userland/Libraries/LibPDF/Renderer.cpp +++ b/Userland/Libraries/LibPDF/Renderer.cpp @@ -892,7 +892,12 @@ PDFErrorOr Renderer::show_image(NonnullRefPtr image) auto image_bitmap = TRY(load_image(image)); if (image_dict->contains(CommonNames::SMask)) { auto smask_bitmap = TRY(load_image(TRY(image_dict->get_stream(m_document, CommonNames::SMask)))); - VERIFY(smask_bitmap->rect() == image_bitmap->rect()); + + // Make softmask same size as image. + // FIXME: The smask code here is fairly ad-hoc and incomplete. + if (smask_bitmap->size() != image_bitmap->size()) + smask_bitmap = TRY(smask_bitmap->scaled_to_size(image_bitmap->size())); + 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);