mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 12:17:35 +00:00
LibGfx/ICC: Cache inverted matrix on profile
Reduces time spent rendering page 3 of 0000849.pdf from 1.85s to 1.45s on my machine. As determined by running time Build/lagom/bin/pdf --page 3 --render out.png \ ~/Downloads/0000/0000849.pdf a few times and eyeballing the min time. Also reduces the time to run Meta/test_pdf.py on 0000.zip (without 0000849.pdf) from 1m7s to 58s.
This commit is contained in:
parent
19d434b229
commit
3365a92ead
2 changed files with 10 additions and 5 deletions
|
@ -1505,7 +1505,7 @@ ErrorOr<void> Profile::from_pcs(Profile const& source_profile, FloatVector3 pcs,
|
||||||
// inverted."
|
// inverted."
|
||||||
|
|
||||||
// Convert from XYZ to linear rgb.
|
// Convert from XYZ to linear rgb.
|
||||||
// FIXME: Inverting matrix and curve on every call to this function is very inefficient.
|
// FIXME: Inverting curves on every call to this function is very inefficient.
|
||||||
FloatVector3 linear_rgb = TRY(xyz_to_rgb_matrix()) * pcs;
|
FloatVector3 linear_rgb = TRY(xyz_to_rgb_matrix()) * pcs;
|
||||||
|
|
||||||
auto evaluate_curve_inverse = [this](TagSignature curve_tag, float f) {
|
auto evaluate_curve_inverse = [this](TagSignature curve_tag, float f) {
|
||||||
|
@ -1619,10 +1619,13 @@ Optional<String> Profile::tag_string_data(TagSignature signature) const
|
||||||
|
|
||||||
ErrorOr<FloatMatrix3x3> Profile::xyz_to_rgb_matrix() const
|
ErrorOr<FloatMatrix3x3> Profile::xyz_to_rgb_matrix() const
|
||||||
{
|
{
|
||||||
FloatMatrix3x3 forward_matrix = rgb_to_xyz_matrix();
|
if (!m_cached_xyz_to_rgb_matrix.has_value()) {
|
||||||
if (!forward_matrix.is_invertible())
|
FloatMatrix3x3 forward_matrix = rgb_to_xyz_matrix();
|
||||||
return Error::from_string_literal("ICC::Profile::from_pcs: matrix not invertible");
|
if (!forward_matrix.is_invertible())
|
||||||
return forward_matrix.inverse();
|
return Error::from_string_literal("ICC::Profile::from_pcs: matrix not invertible");
|
||||||
|
m_cached_xyz_to_rgb_matrix = forward_matrix.inverse();
|
||||||
|
}
|
||||||
|
return m_cached_xyz_to_rgb_matrix.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatMatrix3x3 Profile::rgb_to_xyz_matrix() const
|
FloatMatrix3x3 Profile::rgb_to_xyz_matrix() const
|
||||||
|
|
|
@ -252,6 +252,8 @@ private:
|
||||||
// Only valid for RGB matrix-based profiles.
|
// Only valid for RGB matrix-based profiles.
|
||||||
ErrorOr<FloatMatrix3x3> xyz_to_rgb_matrix() const;
|
ErrorOr<FloatMatrix3x3> xyz_to_rgb_matrix() const;
|
||||||
FloatMatrix3x3 rgb_to_xyz_matrix() const;
|
FloatMatrix3x3 rgb_to_xyz_matrix() const;
|
||||||
|
|
||||||
|
mutable Optional<FloatMatrix3x3> m_cached_xyz_to_rgb_matrix;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue