summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Offenhäuser <offenhaeuser@protonmail.com>2022-10-27 20:06:02 +0200
committerAndreas Kling <kling@serenityos.org>2022-11-19 15:42:08 +0100
commitbaaf42360ece1102dc1987b69afa828ec2d32d4c (patch)
tree8c23e98ad58d18b6b05d64ac1948593faeaee2d9
parent16ed407c01b51295b80db5575bf6da75c22294b6 (diff)
downloadserenity-baaf42360ece1102dc1987b69afa828ec2d32d4c.zip
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.
-rw-r--r--Userland/Libraries/LibPDF/ColorSpace.cpp20
1 files 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<NonnullRefPtr<ColorSpace>> ICCBasedColorSpace::create(Document* docum
return Error { Error::Type::MalformedPDF, "ICCBased color space expects a stream parameter" };
auto dict = param.get<NonnullRefPtr<Object>>()->cast<StreamObject>()->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<Value> const&) const