Index: core/fpdfapi/fpdf_page/cpdf_meshstream.cpp |
diff --git a/core/fpdfapi/fpdf_page/cpdf_meshstream.cpp b/core/fpdfapi/fpdf_page/cpdf_meshstream.cpp |
index f4a1c16754e072bcfaa0dd2b99e8c72a919e57e9..52498c5f9e2fe8fbaa44048eb91c3b43a7bcd02c 100644 |
--- a/core/fpdfapi/fpdf_page/cpdf_meshstream.cpp |
+++ b/core/fpdfapi/fpdf_page/cpdf_meshstream.cpp |
@@ -10,15 +10,14 @@ |
#include "core/fpdfapi/fpdf_page/pageint.h" |
#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
-FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, |
- CPDF_Function** pFuncs, |
- int nFuncs, |
- CPDF_ColorSpace* pCS) { |
+CPDF_MeshStream::CPDF_MeshStream( |
+ const std::vector<std::unique_ptr<CPDF_Function>>& funcs, |
+ CPDF_ColorSpace* pCS) |
+ : m_funcs(funcs), m_pCS(pCS) {} |
+ |
+bool CPDF_MeshStream::Load(CPDF_Stream* pShadingStream) { |
m_Stream.LoadAllData(pShadingStream); |
m_BitStream.Init(m_Stream.GetData(), m_Stream.GetSize()); |
- m_pFuncs = pFuncs; |
- m_nFuncs = nFuncs; |
- m_pCS = pCS; |
CPDF_Dictionary* pDict = pShadingStream->GetDict(); |
m_nCoordBits = pDict->GetIntegerBy("BitsPerCoordinate"); |
m_nCompBits = pDict->GetIntegerBy("BitsPerComponent"); |
@@ -26,14 +25,11 @@ FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, |
if (!m_nCoordBits || !m_nCompBits) |
return FALSE; |
- uint32_t nComps = pCS->CountComponents(); |
+ uint32_t nComps = m_pCS->CountComponents(); |
if (nComps > 8) |
return FALSE; |
- m_nComps = nFuncs ? 1 : nComps; |
- if (((int)m_nComps < 0) || m_nComps > 8) |
- return FALSE; |
- |
+ m_nComps = m_funcs.empty() ? nComps : 1; |
m_CoordMax = m_nCoordBits == 32 ? -1 : (1 << m_nCoordBits) - 1; |
m_CompMax = (1 << m_nCompBits) - 1; |
CPDF_Array* pDecode = pDict->GetArrayBy("Decode"); |
@@ -77,19 +73,18 @@ void CPDF_MeshStream::GetColor(FX_FLOAT& r, FX_FLOAT& g, FX_FLOAT& b) { |
m_BitStream.GetBits(m_nCompBits) * |
(m_ColorMax[i] - m_ColorMin[i]) / m_CompMax; |
} |
- if (m_nFuncs) { |
+ if (m_funcs.empty()) { |
+ m_pCS->GetRGB(color_value, r, g, b); |
+ } else { |
Tom Sepez
2016/05/23 19:09:33
nit: early return instead of else?
Lei Zhang
2016/05/23 19:26:20
Done.
|
static const int kMaxResults = 8; |
Tom Sepez
2016/05/23 19:09:33
nit: maybe use this in the decl at line 70.
Lei Zhang
2016/05/23 19:26:20
Done.
|
FX_FLOAT result[kMaxResults]; |
- int nResults; |
FXSYS_memset(result, 0, sizeof(result)); |
- for (uint32_t i = 0; i < m_nFuncs; i++) { |
- if (m_pFuncs[i] && m_pFuncs[i]->CountOutputs() <= kMaxResults) { |
- m_pFuncs[i]->Call(color_value, 1, result, nResults); |
- } |
+ int nResults; |
+ for (const auto& func : m_funcs) { |
+ if (func && func->CountOutputs() <= kMaxResults) |
+ func->Call(color_value, 1, result, nResults); |
} |
m_pCS->GetRGB(result, r, g, b); |
- } else { |
- m_pCS->GetRGB(color_value, r, g, b); |
} |
} |