diff --git a/Userland/Libraries/LibPDF/ColorSpace.cpp b/Userland/Libraries/LibPDF/ColorSpace.cpp index b4c1e44759..fb71d60c3e 100644 --- a/Userland/Libraries/LibPDF/ColorSpace.cpp +++ b/Userland/Libraries/LibPDF/ColorSpace.cpp @@ -500,7 +500,7 @@ ICCBasedColorSpace::ICCBasedColorSpace(NonnullRefPtr profile) PDFErrorOr ICCBasedColorSpace::style(ReadonlySpan arguments) const { - Vector components; + m_components.resize(arguments.size()); for (size_t i = 0; i < arguments.size(); ++i) { auto const& arg = arguments[i]; VERIFY(arg.has_number()); @@ -515,17 +515,17 @@ PDFErrorOr ICCBasedColorSpace::style(ReadonlySpan arguments number = (number + 128.0f) / 255.0f; } - components.append(number); + m_components[i] = number; } if (m_map.has_value()) - return m_map->map(FloatVector3 { components[0], components[1], components[2] }); + return m_map->map(FloatVector3 { m_components[0], m_components[1], m_components[2] }); - Vector bytes; - for (auto component : components) - bytes.append(static_cast(component * 255.0f)); + m_bytes.resize(arguments.size()); + for (size_t i = 0; i < arguments.size(); ++i) + m_bytes[i] = static_cast(m_components[i] * 255.0f); - auto pcs = TRY(m_profile->to_pcs(bytes)); + auto pcs = TRY(m_profile->to_pcs(m_bytes)); Array output; TRY(sRGB()->from_pcs(m_profile, pcs, output.span())); diff --git a/Userland/Libraries/LibPDF/ColorSpace.h b/Userland/Libraries/LibPDF/ColorSpace.h index dfbca3dee1..fb592558d1 100644 --- a/Userland/Libraries/LibPDF/ColorSpace.h +++ b/Userland/Libraries/LibPDF/ColorSpace.h @@ -195,6 +195,8 @@ private: static RefPtr s_srgb_profile; NonnullRefPtr m_profile; + mutable Vector m_components; + mutable Vector m_bytes; Optional m_map; };