Skip to content

Commit 9462151

Browse files
committed
LibPDF: Stop storing number of components in gouraud shadings
Reverts d26686c and tweaks draw_gouraud_triangles() a bit. It's fairly easy to compute number_of_components locally in draw_gouraud_triangles(), so let's do that. No behavior change.
1 parent 3b3c2f4 commit 9462151

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

Userland/Libraries/LibPDF/Shading.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,9 @@ struct Triangle {
748748
u32 c;
749749
};
750750

751-
PDFErrorOr<void> draw_gouraud_triangles(Gfx::Painter& painter, Gfx::AffineTransform const& ctm, NonnullRefPtr<ColorSpace> color_space, GouraudFunctionsType const& functions, Vector<Triangle> const& triangles, Vector<float> const& vertex_data, size_t number_of_components)
751+
PDFErrorOr<void> draw_gouraud_triangles(Gfx::Painter& painter, Gfx::AffineTransform const& ctm, NonnullRefPtr<ColorSpace> color_space, GouraudFunctionsType const& functions, Vector<Triangle> const& triangles, Vector<float> const& vertex_data)
752752
{
753+
size_t const number_of_components = !functions.has<Empty>() ? 1 : color_space->number_of_components();
753754
bool is_indexed = color_space->family() == ColorSpaceFamily::Indexed;
754755
RefPtr<IndexedColorSpace> indexed_color_space;
755756
if (is_indexed) {
@@ -797,10 +798,9 @@ class FreeFormGouraudShading final : public Shading {
797798
virtual PDFErrorOr<void> draw(Gfx::Painter&, Gfx::AffineTransform const&) override;
798799

799800
private:
800-
FreeFormGouraudShading(CommonEntries common_entries, Vector<float> vertex_data, size_t number_of_components, Vector<Triangle> triangles, GouraudFunctionsType functions)
801+
FreeFormGouraudShading(CommonEntries common_entries, Vector<float> vertex_data, Vector<Triangle> triangles, GouraudFunctionsType functions)
801802
: m_common_entries(move(common_entries))
802803
, m_vertex_data(move(vertex_data))
803-
, m_number_of_components(number_of_components)
804804
, m_triangles(move(triangles))
805805
, m_functions(move(functions))
806806
{
@@ -810,7 +810,6 @@ class FreeFormGouraudShading final : public Shading {
810810

811811
// Interleaved x, y, c0, c1, c2, ...
812812
Vector<float> m_vertex_data;
813-
size_t m_number_of_components { 0 };
814813
Vector<Triangle> m_triangles;
815814
GouraudFunctionsType m_functions;
816815
};
@@ -938,12 +937,12 @@ PDFErrorOr<NonnullRefPtr<FreeFormGouraudShading>> FreeFormGouraudShading::create
938937
}
939938
}
940939

941-
return adopt_ref(*new FreeFormGouraudShading(move(common_entries), move(vertex_data), number_of_components, move(triangles), move(functions)));
940+
return adopt_ref(*new FreeFormGouraudShading(move(common_entries), move(vertex_data), move(triangles), move(functions)));
942941
}
943942

944943
PDFErrorOr<void> FreeFormGouraudShading::draw(Gfx::Painter& painter, Gfx::AffineTransform const& ctm)
945944
{
946-
return draw_gouraud_triangles(painter, ctm, m_common_entries.color_space, m_functions, m_triangles, m_vertex_data, m_number_of_components);
945+
return draw_gouraud_triangles(painter, ctm, m_common_entries.color_space, m_functions, m_triangles, m_vertex_data);
947946
}
948947

949948
class LatticeFormGouraudShading final : public Shading {
@@ -953,10 +952,9 @@ class LatticeFormGouraudShading final : public Shading {
953952
virtual PDFErrorOr<void> draw(Gfx::Painter&, Gfx::AffineTransform const&) override;
954953

955954
private:
956-
LatticeFormGouraudShading(CommonEntries common_entries, Vector<float> vertex_data, size_t number_of_components, Vector<Triangle> triangles, GouraudFunctionsType functions)
955+
LatticeFormGouraudShading(CommonEntries common_entries, Vector<float> vertex_data, Vector<Triangle> triangles, GouraudFunctionsType functions)
957956
: m_common_entries(move(common_entries))
958957
, m_vertex_data(move(vertex_data))
959-
, m_number_of_components(number_of_components)
960958
, m_triangles(move(triangles))
961959
, m_functions(move(functions))
962960
{
@@ -966,7 +964,6 @@ class LatticeFormGouraudShading final : public Shading {
966964

967965
// Interleaved x, y, c0, c1, c2, ...
968966
Vector<float> m_vertex_data;
969-
size_t m_number_of_components { 0 };
970967
Vector<Triangle> m_triangles;
971968
GouraudFunctionsType m_functions;
972969
};
@@ -1084,12 +1081,12 @@ PDFErrorOr<NonnullRefPtr<LatticeFormGouraudShading>> LatticeFormGouraudShading::
10841081
}
10851082
}
10861083

1087-
return adopt_ref(*new LatticeFormGouraudShading(move(common_entries), move(vertex_data), number_of_components, move(triangles), move(functions)));
1084+
return adopt_ref(*new LatticeFormGouraudShading(move(common_entries), move(vertex_data), move(triangles), move(functions)));
10881085
}
10891086

10901087
PDFErrorOr<void> LatticeFormGouraudShading::draw(Gfx::Painter& painter, Gfx::AffineTransform const& ctm)
10911088
{
1092-
return draw_gouraud_triangles(painter, ctm, m_common_entries.color_space, m_functions, m_triangles, m_vertex_data, m_number_of_components);
1089+
return draw_gouraud_triangles(painter, ctm, m_common_entries.color_space, m_functions, m_triangles, m_vertex_data);
10931090
}
10941091

10951092
class CoonsPatchShading final : public Shading {

0 commit comments

Comments
 (0)