mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 07:07:34 +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:
parent
c161b2d2f9
commit
cfd05b1a55
2 changed files with 11 additions and 2 deletions
|
@ -495,11 +495,12 @@ PDFErrorOr<NonnullRefPtr<ColorSpace>> ICCBasedColorSpace::create(Document* docum
|
||||||
ICCBasedColorSpace::ICCBasedColorSpace(NonnullRefPtr<Gfx::ICC::Profile> profile)
|
ICCBasedColorSpace::ICCBasedColorSpace(NonnullRefPtr<Gfx::ICC::Profile> profile)
|
||||||
: m_profile(profile)
|
: m_profile(profile)
|
||||||
{
|
{
|
||||||
|
m_map = sRGB()->matrix_matrix_conversion(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFErrorOr<ColorOrStyle> ICCBasedColorSpace::style(ReadonlySpan<Value> arguments) const
|
PDFErrorOr<ColorOrStyle> ICCBasedColorSpace::style(ReadonlySpan<Value> arguments) const
|
||||||
{
|
{
|
||||||
Vector<u8> bytes;
|
Vector<float, 4> components;
|
||||||
for (size_t i = 0; i < arguments.size(); ++i) {
|
for (size_t i = 0; i < arguments.size(); ++i) {
|
||||||
auto const& arg = arguments[i];
|
auto const& arg = arguments[i];
|
||||||
VERIFY(arg.has_number());
|
VERIFY(arg.has_number());
|
||||||
|
@ -514,9 +515,16 @@ PDFErrorOr<ColorOrStyle> ICCBasedColorSpace::style(ReadonlySpan<Value> arguments
|
||||||
number = (number + 128.0f) / 255.0f;
|
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));
|
auto pcs = TRY(m_profile->to_pcs(bytes));
|
||||||
Array<u8, 3> output;
|
Array<u8, 3> output;
|
||||||
TRY(sRGB()->from_pcs(m_profile, pcs, output.span()));
|
TRY(sRGB()->from_pcs(m_profile, pcs, output.span()));
|
||||||
|
|
|
@ -195,6 +195,7 @@ private:
|
||||||
|
|
||||||
static RefPtr<Gfx::ICC::Profile> s_srgb_profile;
|
static RefPtr<Gfx::ICC::Profile> s_srgb_profile;
|
||||||
NonnullRefPtr<Gfx::ICC::Profile> m_profile;
|
NonnullRefPtr<Gfx::ICC::Profile> m_profile;
|
||||||
|
Optional<Gfx::ICC::MatrixMatrixConversion> m_map;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LabColorSpace final : public ColorSpace {
|
class LabColorSpace final : public ColorSpace {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue