LibPDF: Add more knowledge to ColorSpaces classes

ColorSpaces now can tell users how many components they expect, and the
default decode array that should be used when converting unit bit
sequences into color space component input values during image
rendering.
This commit is contained in:
Rodrigo Tobar 2022-11-25 01:43:31 +08:00 committed by Andreas Kling
parent ba16310739
commit 26f8c0b76c
Notes: sideshowbarker 2024-07-17 03:34:05 +09:00
2 changed files with 38 additions and 0 deletions

View file

@ -73,6 +73,11 @@ Color DeviceGrayColorSpace::color(Vector<Value> const& arguments) const
return Color(gray, gray, gray);
}
Vector<float> DeviceGrayColorSpace::default_decode() const
{
return { 0.0f, 1.0f };
}
NonnullRefPtr<DeviceRGBColorSpace> DeviceRGBColorSpace::the()
{
static auto instance = adopt_ref(*new DeviceRGBColorSpace());
@ -88,6 +93,11 @@ Color DeviceRGBColorSpace::color(Vector<Value> const& arguments) const
return Color(r, g, b);
}
Vector<float> DeviceRGBColorSpace::default_decode() const
{
return { 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f };
}
NonnullRefPtr<DeviceCMYKColorSpace> DeviceCMYKColorSpace::the()
{
static auto instance = adopt_ref(*new DeviceCMYKColorSpace());
@ -104,6 +114,11 @@ Color DeviceCMYKColorSpace::color(Vector<Value> const& arguments) const
return Color::from_cmyk(c, m, y, k);
}
Vector<float> DeviceCMYKColorSpace::default_decode() const
{
return { 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f };
}
PDFErrorOr<NonnullRefPtr<CalRGBColorSpace>> CalRGBColorSpace::create(Document* document, Vector<Value>&& parameters)
{
if (parameters.size() != 1)
@ -274,6 +289,11 @@ Color CalRGBColorSpace::color(Vector<Value> const& arguments) const
return Color(red, green, blue);
}
Vector<float> CalRGBColorSpace::default_decode() const
{
return { 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f };
}
PDFErrorOr<NonnullRefPtr<ColorSpace>> ICCBasedColorSpace::create(Document* document, Vector<Value>&& parameters)
{
if (parameters.is_empty())
@ -313,4 +333,9 @@ Color ICCBasedColorSpace::color(Vector<Value> const&) const
VERIFY_NOT_REACHED();
}
Vector<float> ICCBasedColorSpace::default_decode() const
{
VERIFY_NOT_REACHED();
}
}

View file

@ -6,6 +6,7 @@
#pragma once
#include "AK/Forward.h"
#include <AK/FlyString.h>
#include <LibGfx/Color.h>
#include <LibPDF/Value.h>
@ -54,6 +55,8 @@ public:
virtual ~ColorSpace() = default;
virtual Color color(Vector<Value> const& arguments) const = 0;
virtual int number_of_components() const = 0;
virtual Vector<float> default_decode() const = 0;
virtual ColorSpaceFamily const& family() const = 0;
};
@ -64,6 +67,8 @@ public:
~DeviceGrayColorSpace() override = default;
Color color(Vector<Value> const& arguments) const override;
int number_of_components() const override { return 1; }
Vector<float> default_decode() const override;
ColorSpaceFamily const& family() const override { return ColorSpaceFamily::DeviceGray; }
private:
@ -77,6 +82,8 @@ public:
~DeviceRGBColorSpace() override = default;
Color color(Vector<Value> const& arguments) const override;
int number_of_components() const override { return 3; }
Vector<float> default_decode() const override;
ColorSpaceFamily const& family() const override { return ColorSpaceFamily::DeviceRGB; }
private:
@ -90,6 +97,8 @@ public:
~DeviceCMYKColorSpace() override = default;
Color color(Vector<Value> const& arguments) const override;
int number_of_components() const override { return 4; }
Vector<float> default_decode() const override;
ColorSpaceFamily const& family() const override { return ColorSpaceFamily::DeviceCMYK; }
private:
@ -103,6 +112,8 @@ public:
~CalRGBColorSpace() override = default;
Color color(Vector<Value> const& arguments) const override;
int number_of_components() const override { return 3; }
Vector<float> default_decode() const override;
ColorSpaceFamily const& family() const override { return ColorSpaceFamily::CalRGB; }
private:
@ -121,6 +132,8 @@ public:
~ICCBasedColorSpace() override = default;
Color color(Vector<Value> const& arguments) const override;
int number_of_components() const override { VERIFY_NOT_REACHED(); }
Vector<float> default_decode() const override;
ColorSpaceFamily const& family() const override { return ColorSpaceFamily::ICCBased; }
private: