From baaf42360ece1102dc1987b69afa828ec2d32d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Offenh=C3=A4user?= Date: Thu, 27 Oct 2022 20:06:02 +0200 Subject: LibPDF: Derive alternate ICC color space from the number of components We currently don't support ICC color spaces and fall back to a "simple" one instead. If no alternative is specified however, we are allowed to pick the closest match based on the number of color components. --- Userland/Libraries/LibPDF/ColorSpace.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibPDF/ColorSpace.cpp b/Userland/Libraries/LibPDF/ColorSpace.cpp index 28949882ce..f647307350 100644 --- a/Userland/Libraries/LibPDF/ColorSpace.cpp +++ b/Userland/Libraries/LibPDF/ColorSpace.cpp @@ -271,11 +271,23 @@ PDFErrorOr> ICCBasedColorSpace::create(Document* docum return Error { Error::Type::MalformedPDF, "ICCBased color space expects a stream parameter" }; auto dict = param.get>()->cast()->dict(); - if (!dict->contains(CommonNames::Alternate)) - TODO(); - auto alternate = TRY(dict->get_name(document, CommonNames::Alternate))->name(); - return TRY(ColorSpace::create(document, alternate, page)); + FlyString name; + if (!dict->contains(CommonNames::Alternate)) { + auto number_of_components = dict->get_value(CommonNames::N).to_int(); + if (number_of_components == 1) + name = CommonNames::DeviceGray; + else if (number_of_components == 3) + name = CommonNames::DeviceRGB; + else if (number_of_components == 4) + name = CommonNames::DeviceCMYK; + else + VERIFY_NOT_REACHED(); + } else { + name = TRY(dict->get_name(document, CommonNames::Alternate))->name(); + } + + return TRY(ColorSpace::create(document, name, page)); } Color ICCBasedColorSpace::color(Vector const&) const -- cgit v1.2.3