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

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.
This commit is contained in:
Julian Offenhäuser 2022-10-27 20:06:02 +02:00 committed by Andreas Kling
parent 16ed407c01
commit baaf42360e

View file

@ -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