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

LibPDF: Use MatrixMatrixConversion when possible

Reduces time spent rendering page 3 of 0000849.pdf from 1.32s to 1.13s
on my machine.

Also reduces the time to run Meta/test_pdf.py on 0000.zip
(without 0000849.pdf) from 56s to 54s.
This commit is contained in:
Nico Weber 2024-01-08 19:52:14 -05:00 committed by Andreas Kling
parent c161b2d2f9
commit cfd05b1a55
2 changed files with 11 additions and 2 deletions

View file

@ -495,11 +495,12 @@ PDFErrorOr<NonnullRefPtr<ColorSpace>> ICCBasedColorSpace::create(Document* docum
ICCBasedColorSpace::ICCBasedColorSpace(NonnullRefPtr<Gfx::ICC::Profile> profile)
: m_profile(profile)
{
m_map = sRGB()->matrix_matrix_conversion(profile);
}
PDFErrorOr<ColorOrStyle> ICCBasedColorSpace::style(ReadonlySpan<Value> arguments) const
{
Vector<u8> bytes;
Vector<float, 4> components;
for (size_t i = 0; i < arguments.size(); ++i) {
auto const& arg = arguments[i];
VERIFY(arg.has_number());
@ -514,9 +515,16 @@ PDFErrorOr<ColorOrStyle> ICCBasedColorSpace::style(ReadonlySpan<Value> arguments
number = (number + 128.0f) / 255.0f;
}
bytes.append(static_cast<u8>(number * 255.0f));
components.append(number);
}
if (m_map.has_value())
return m_map->map(FloatVector3 { components[0], components[1], components[2] });
Vector<u8, 4> bytes;
for (auto component : components)
bytes.append(static_cast<u8>(component * 255.0f));
auto pcs = TRY(m_profile->to_pcs(bytes));
Array<u8, 3> output;
TRY(sRGB()->from_pcs(m_profile, pcs, output.span()));