LibGfx/ICC: Move MatrixMatrixConversion::map() inline
According to ministat, a bit faster to render page 3 of 0000849.pdf: ``` N Min Max Median Avg Stddev x 50 1.000875 1.0427601 1.0208509 1.0201902 0.01066116 + 50 0.99707389 1.03614 1.0084391 1.0107864 0.010002724 Difference at 95.0% confidence -0.00940384 +/- 0.0041018 -0.921773% +/- 0.402062% (Student's t, pooled s = 0.0103372) ```
This commit is contained in:
parent
56a4af8d03
commit
5ff2a824cc
Notes:
sideshowbarker
2024-07-17 04:49:48 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/5ff2a824cc Pull-request: https://github.com/SerenityOS/serenity/pull/22713 Reviewed-by: https://github.com/Hendiadyoin1
2 changed files with 35 additions and 35 deletions
Userland/Libraries/LibGfx/ICC
|
@ -1588,41 +1588,6 @@ MatrixMatrixConversion::MatrixMatrixConversion(LutCurveType source_red_TRC,
|
|||
{
|
||||
}
|
||||
|
||||
Color MatrixMatrixConversion::map(FloatVector3 in_rgb) const
|
||||
{
|
||||
auto evaluate_curve = [](TagData const& trc, float f) {
|
||||
VERIFY(trc.type() == CurveTagData::Type || trc.type() == ParametricCurveTagData::Type);
|
||||
if (trc.type() == CurveTagData::Type)
|
||||
return static_cast<CurveTagData const&>(trc).evaluate(f);
|
||||
return static_cast<ParametricCurveTagData const&>(trc).evaluate(f);
|
||||
};
|
||||
|
||||
auto evaluate_curve_inverse = [](TagData const& trc, float f) {
|
||||
VERIFY(trc.type() == CurveTagData::Type || trc.type() == ParametricCurveTagData::Type);
|
||||
if (trc.type() == CurveTagData::Type)
|
||||
return static_cast<CurveTagData const&>(trc).evaluate_inverse(f);
|
||||
return static_cast<ParametricCurveTagData const&>(trc).evaluate_inverse(f);
|
||||
};
|
||||
|
||||
FloatVector3 linear_rgb = {
|
||||
evaluate_curve(m_source_red_TRC, in_rgb[0]),
|
||||
evaluate_curve(m_source_green_TRC, in_rgb[1]),
|
||||
evaluate_curve(m_source_blue_TRC, in_rgb[2]),
|
||||
};
|
||||
linear_rgb = m_matrix * linear_rgb;
|
||||
|
||||
linear_rgb.clamp(0.f, 1.f);
|
||||
float device_r = evaluate_curve_inverse(m_destination_red_TRC, linear_rgb[0]);
|
||||
float device_g = evaluate_curve_inverse(m_destination_green_TRC, linear_rgb[1]);
|
||||
float device_b = evaluate_curve_inverse(m_destination_blue_TRC, linear_rgb[2]);
|
||||
|
||||
u8 out_r = round(255 * device_r);
|
||||
u8 out_g = round(255 * device_g);
|
||||
u8 out_b = round(255 * device_b);
|
||||
|
||||
return Color(out_r, out_g, out_b);
|
||||
}
|
||||
|
||||
Optional<MatrixMatrixConversion> Profile::matrix_matrix_conversion(Profile const& source_profile) const
|
||||
{
|
||||
auto has_normal_device_class = [](DeviceClass device) {
|
||||
|
|
|
@ -172,6 +172,41 @@ private:
|
|||
LutCurveType m_destination_blue_TRC;
|
||||
};
|
||||
|
||||
inline Color MatrixMatrixConversion::map(FloatVector3 in_rgb) const
|
||||
{
|
||||
auto evaluate_curve = [](TagData const& trc, float f) {
|
||||
VERIFY(trc.type() == CurveTagData::Type || trc.type() == ParametricCurveTagData::Type);
|
||||
if (trc.type() == CurveTagData::Type)
|
||||
return static_cast<CurveTagData const&>(trc).evaluate(f);
|
||||
return static_cast<ParametricCurveTagData const&>(trc).evaluate(f);
|
||||
};
|
||||
|
||||
auto evaluate_curve_inverse = [](TagData const& trc, float f) {
|
||||
VERIFY(trc.type() == CurveTagData::Type || trc.type() == ParametricCurveTagData::Type);
|
||||
if (trc.type() == CurveTagData::Type)
|
||||
return static_cast<CurveTagData const&>(trc).evaluate_inverse(f);
|
||||
return static_cast<ParametricCurveTagData const&>(trc).evaluate_inverse(f);
|
||||
};
|
||||
|
||||
FloatVector3 linear_rgb = {
|
||||
evaluate_curve(m_source_red_TRC, in_rgb[0]),
|
||||
evaluate_curve(m_source_green_TRC, in_rgb[1]),
|
||||
evaluate_curve(m_source_blue_TRC, in_rgb[2]),
|
||||
};
|
||||
linear_rgb = m_matrix * linear_rgb;
|
||||
|
||||
linear_rgb.clamp(0.f, 1.f);
|
||||
float device_r = evaluate_curve_inverse(m_destination_red_TRC, linear_rgb[0]);
|
||||
float device_g = evaluate_curve_inverse(m_destination_green_TRC, linear_rgb[1]);
|
||||
float device_b = evaluate_curve_inverse(m_destination_blue_TRC, linear_rgb[2]);
|
||||
|
||||
u8 out_r = round(255 * device_r);
|
||||
u8 out_g = round(255 * device_g);
|
||||
u8 out_b = round(255 * device_b);
|
||||
|
||||
return Color(out_r, out_g, out_b);
|
||||
}
|
||||
|
||||
class Profile : public RefCounted<Profile> {
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<Profile>> try_load_from_externally_owned_memory(ReadonlyBytes);
|
||||
|
|
Loading…
Add table
Reference in a new issue