mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:17:45 +00:00
LibPDF: Don't reallocate Vectors in ICCBasedColorSpace all the time
Microoptimization; according to ministat a bit faster: ``` N Min Max Median Avg Stddev x 50 1.0179932 1.0561159 1.0315337 1.0333617 0.0094757426 + 50 1.000875 1.0427601 1.0208509 1.0201902 0.01066116 Difference at 95.0% confidence -0.0131715 +/- 0.00400208 -1.27463% +/- 0.387287% (Student's t, pooled s = 0.0100859) ```
This commit is contained in:
parent
75262a92e1
commit
56a4af8d03
2 changed files with 9 additions and 7 deletions
|
@ -500,7 +500,7 @@ ICCBasedColorSpace::ICCBasedColorSpace(NonnullRefPtr<Gfx::ICC::Profile> profile)
|
|||
|
||||
PDFErrorOr<ColorOrStyle> ICCBasedColorSpace::style(ReadonlySpan<Value> arguments) const
|
||||
{
|
||||
Vector<float, 4> 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<ColorOrStyle> ICCBasedColorSpace::style(ReadonlySpan<Value> 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<u8, 4> bytes;
|
||||
for (auto component : components)
|
||||
bytes.append(static_cast<u8>(component * 255.0f));
|
||||
m_bytes.resize(arguments.size());
|
||||
for (size_t i = 0; i < arguments.size(); ++i)
|
||||
m_bytes[i] = static_cast<u8>(m_components[i] * 255.0f);
|
||||
|
||||
auto pcs = TRY(m_profile->to_pcs(bytes));
|
||||
auto pcs = TRY(m_profile->to_pcs(m_bytes));
|
||||
Array<u8, 3> output;
|
||||
TRY(sRGB()->from_pcs(m_profile, pcs, output.span()));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue