Change CPDF_MeshStream::ReadColor() to return an array
Use std::array<float, 3> consistently for color representation.
Also mark some CPDF_MeshStream methods as const.
Change-Id: I0c80cd34d916615b46525d260b1b9501e638f3fa
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/117390
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
diff --git a/core/fpdfapi/page/cpdf_meshstream.cpp b/core/fpdfapi/page/cpdf_meshstream.cpp
index 39ce012..ea90c58 100644
--- a/core/fpdfapi/page/cpdf_meshstream.cpp
+++ b/core/fpdfapi/page/cpdf_meshstream.cpp
@@ -177,12 +177,12 @@
return m_BitStream->BitsRemaining() / m_nComponentBits >= m_nComponents;
}
-uint32_t CPDF_MeshStream::ReadFlag() {
+uint32_t CPDF_MeshStream::ReadFlag() const {
DCHECK(ShouldCheckBitsPerFlag(m_type));
return m_BitStream->GetBits(m_nFlagBits) & 0x03;
}
-CFX_PointF CPDF_MeshStream::ReadCoords() {
+CFX_PointF CPDF_MeshStream::ReadCoords() const {
DCHECK(ShouldCheckBPC(m_type));
CFX_PointF pos;
@@ -200,7 +200,7 @@
return pos;
}
-std::tuple<float, float, float> CPDF_MeshStream::ReadColor() {
+std::array<float, 3> CPDF_MeshStream::ReadColor() const {
DCHECK(ShouldCheckBPC(m_type));
float color_value[kMaxComponents];
@@ -210,12 +210,10 @@
m_ComponentMax;
}
- float r = 0.0;
- float g = 0.0;
- float b = 0.0;
+ std::array<float, 3> rgb = {};
if (m_funcs.empty()) {
- m_pCS->GetRGB(color_value, &r, &g, &b);
- return std::tuple<float, float, float>(r, g, b);
+ m_pCS->GetRGB(color_value, &rgb[0], &rgb[1], &rgb[2]);
+ return rgb;
}
float result[kMaxComponents] = {};
@@ -225,8 +223,8 @@
}
}
- m_pCS->GetRGB(result, &r, &g, &b);
- return std::tuple<float, float, float>(r, g, b);
+ m_pCS->GetRGB(result, &rgb[0], &rgb[1], &rgb[2]);
+ return rgb;
}
bool CPDF_MeshStream::ReadVertex(const CFX_Matrix& pObject2Bitmap,
@@ -242,7 +240,7 @@
if (!CanReadColor())
return false;
- std::tie(vertex->r, vertex->g, vertex->b) = ReadColor();
+ vertex->rgb = ReadColor();
m_BitStream->ByteAlign();
return true;
}
@@ -261,7 +259,7 @@
if (!CanReadColor())
return std::vector<CPDF_MeshVertex>();
- std::tie(vertex.r, vertex.g, vertex.b) = ReadColor();
+ vertex.rgb = ReadColor();
m_BitStream->ByteAlign();
}
return vertices;
diff --git a/core/fpdfapi/page/cpdf_meshstream.h b/core/fpdfapi/page/cpdf_meshstream.h
index b1dab6e..48c68e7 100644
--- a/core/fpdfapi/page/cpdf_meshstream.h
+++ b/core/fpdfapi/page/cpdf_meshstream.h
@@ -9,8 +9,8 @@
#include <stdint.h>
+#include <array>
#include <memory>
-#include <tuple>
#include <vector>
#include "core/fpdfapi/page/cpdf_shadingpattern.h"
@@ -25,9 +25,7 @@
~CPDF_MeshVertex();
CFX_PointF position;
- float r = 0.0f;
- float g = 0.0f;
- float b = 0.0f;
+ std::array<float, 3> rgb = {};
};
class CFX_BitStream;
@@ -53,9 +51,9 @@
bool CanReadCoords() const;
bool CanReadColor() const;
- uint32_t ReadFlag();
- CFX_PointF ReadCoords();
- std::tuple<float, float, float> ReadColor();
+ uint32_t ReadFlag() const;
+ CFX_PointF ReadCoords() const;
+ std::array<float, 3> ReadColor() const;
bool ReadVertex(const CFX_Matrix& pObject2Bitmap,
CPDF_MeshVertex* vertex,
diff --git a/core/fpdfapi/render/cpdf_rendershading.cpp b/core/fpdfapi/render/cpdf_rendershading.cpp
index edd7e60..7b9b557 100644
--- a/core/fpdfapi/render/cpdf_rendershading.cpp
+++ b/core/fpdfapi/render/cpdf_rendershading.cpp
@@ -370,9 +370,12 @@
continue;
float y_dist = (y - position1.y) / (position2.y - position1.y);
- r[nIntersects] = vertex1.r + ((vertex2.r - vertex1.r) * y_dist);
- g[nIntersects] = vertex1.g + ((vertex2.g - vertex1.g) * y_dist);
- b[nIntersects] = vertex1.b + ((vertex2.b - vertex1.b) * y_dist);
+ r[nIntersects] =
+ vertex1.rgb[0] + ((vertex2.rgb[0] - vertex1.rgb[0]) * y_dist);
+ g[nIntersects] =
+ vertex1.rgb[1] + ((vertex2.rgb[1] - vertex1.rgb[1]) * y_dist);
+ b[nIntersects] =
+ vertex1.rgb[2] + ((vertex2.rgb[2] - vertex1.rgb[2]) * y_dist);
nIntersects++;
}
if (nIntersects != 2)
@@ -845,15 +848,12 @@
if (!stream.CanReadColor())
break;
- float r;
- float g;
- float b;
- std::tie(r, g, b) = stream.ReadColor();
-
- patch.patch_colors[i].comp[0] = static_cast<int32_t>(r * 255);
- patch.patch_colors[i].comp[1] = static_cast<int32_t>(g * 255);
- patch.patch_colors[i].comp[2] = static_cast<int32_t>(b * 255);
+ std::array<float, 3> rgb = stream.ReadColor();
+ patch.patch_colors[i].comp[0] = static_cast<int32_t>(rgb[0] * 255);
+ patch.patch_colors[i].comp[1] = static_cast<int32_t>(rgb[1] * 255);
+ patch.patch_colors[i].comp[2] = static_cast<int32_t>(rgb[2] * 255);
}
+
CFX_FloatRect bbox =
CFX_FloatRect::GetBBox(pdfium::make_span(coords).first(point_count));
if (bbox.right <= 0 || bbox.left >= (float)pBitmap->GetWidth() ||