Przeglądaj źródła

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.
Julian Offenhäuser 2 lat temu
rodzic
commit
baaf42360e
1 zmienionych plików z 16 dodań i 4 usunięć
  1. 16 4
      Userland/Libraries/LibPDF/ColorSpace.cpp

+ 16 - 4
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