LibPDF: Extract ICCBasedColorSpace::sRGB() helper

This commit is contained in:
Nico Weber 2023-10-20 08:17:14 -04:00 committed by Andreas Kling
parent 4704e6aa5f
commit c161b2d2f9
2 changed files with 10 additions and 4 deletions

View file

@ -499,9 +499,6 @@ ICCBasedColorSpace::ICCBasedColorSpace(NonnullRefPtr<Gfx::ICC::Profile> profile)
PDFErrorOr<ColorOrStyle> ICCBasedColorSpace::style(ReadonlySpan<Value> arguments) const
{
if (!s_srgb_profile)
s_srgb_profile = TRY(Gfx::ICC::sRGB());
Vector<u8> bytes;
for (size_t i = 0; i < arguments.size(); ++i) {
auto const& arg = arguments[i];
@ -522,7 +519,7 @@ PDFErrorOr<ColorOrStyle> ICCBasedColorSpace::style(ReadonlySpan<Value> arguments
auto pcs = TRY(m_profile->to_pcs(bytes));
Array<u8, 3> output;
TRY(s_srgb_profile->from_pcs(m_profile, pcs, output.span()));
TRY(sRGB()->from_pcs(m_profile, pcs, output.span()));
return Color(output[0], output[1], output[2]);
}
@ -553,6 +550,13 @@ Vector<float> ICCBasedColorSpace::default_decode() const
}
}
NonnullRefPtr<Gfx::ICC::Profile> ICCBasedColorSpace::sRGB()
{
if (!s_srgb_profile)
s_srgb_profile = MUST(Gfx::ICC::sRGB());
return *s_srgb_profile;
}
PDFErrorOr<NonnullRefPtr<LabColorSpace>> LabColorSpace::create(Document* document, Vector<Value>&& parameters)
{
if (parameters.size() != 1)

View file

@ -188,6 +188,8 @@ public:
Vector<float> default_decode() const override;
ColorSpaceFamily const& family() const override { return ColorSpaceFamily::ICCBased; }
static NonnullRefPtr<Gfx::ICC::Profile> sRGB();
private:
ICCBasedColorSpace(NonnullRefPtr<Gfx::ICC::Profile>);