114 m_pStream->LoadAllDataFiltered();
115 m_BitStream = std::make_unique<CFX_BitStream>(m_pStream->GetSpan());
117 RetainPtr<
const CPDF_Dictionary> pDict = m_pShadingStream->GetDict();
118 m_nCoordBits = pDict->GetIntegerFor(
"BitsPerCoordinate");
119 m_nComponentBits = pDict->GetIntegerFor(
"BitsPerComponent");
120 if (ShouldCheckBPC(m_type)) {
121 if (!IsValidBitsPerCoordinate(m_nCoordBits))
123 if (!IsValidBitsPerComponent(m_nComponentBits))
127 m_nFlagBits = pDict->GetIntegerFor(
"BitsPerFlag");
128 if (ShouldCheckBitsPerFlag(m_type) && !IsValidBitsPerFlag(m_nFlagBits))
131 uint32_t nComponents = m_pCS->CountComponents();
132 if (nComponents > kMaxComponents)
135 m_nComponents = m_funcs.empty() ? nComponents : 1;
136 RetainPtr<
const CPDF_Array> pDecode = pDict->GetArrayFor(
"Decode");
137 if (!pDecode || pDecode->size() != 4 + m_nComponents * 2)
140 m_xmin = pDecode->GetFloatAt(0);
141 m_xmax = pDecode->GetFloatAt(1);
142 m_ymin = pDecode->GetFloatAt(2);
143 m_ymax = pDecode->GetFloatAt(3);
144 for (uint32_t i = 0; i < m_nComponents; ++i) {
145 m_ColorMin[i] = pDecode->GetFloatAt(i * 2 + 4);
146 m_ColorMax[i] = pDecode->GetFloatAt(i * 2 + 5);
149 if (ShouldCheckBPC(m_type)) {
150 m_CoordMax = m_nCoordBits == 32 ? -1 : (1 << m_nCoordBits) - 1;
151 m_ComponentMax = (1 << m_nComponentBits) - 1;
186 DCHECK(ShouldCheckBPC(m_type));
189 if (m_nCoordBits == 32) {
190 pos.x = m_xmin + m_BitStream->GetBits(m_nCoordBits) * (m_xmax - m_xmin) /
191 static_cast<
double>(m_CoordMax);
192 pos.y = m_ymin + m_BitStream->GetBits(m_nCoordBits) * (m_ymax - m_ymin) /
193 static_cast<
double>(m_CoordMax);
196 m_BitStream->GetBits(m_nCoordBits) * (m_xmax - m_xmin) / m_CoordMax;
198 m_BitStream->GetBits(m_nCoordBits) * (m_ymax - m_ymin) / m_CoordMax;
204 DCHECK(ShouldCheckBPC(m_type));
206 float color_value[kMaxComponents];
207 for (uint32_t i = 0; i < m_nComponents; ++i) {
208 color_value[i] = m_ColorMin[i] + m_BitStream->GetBits(m_nComponentBits) *
209 (m_ColorMax[i] - m_ColorMin[i]) /
216 if (m_funcs.empty()) {
217 m_pCS->GetRGB(color_value, &r, &g, &b);
218 return std::tuple<
float,
float,
float>(r, g, b);
221 float result[kMaxComponents] = {};
222 for (
const auto& func : m_funcs) {
223 if (func && func->CountOutputs() <= kMaxComponents)
224 func->Call(pdfium::make_span(color_value, 1u), result);
227 m_pCS->GetRGB(result, &r, &g, &b);
228 return std::tuple<
float,
float,
float>(r, g, b);
252 std::vector<CPDF_MeshVertex> vertices;
253 for (
int i = 0; i < count; ++i) {
254 if (m_BitStream->IsEOF() || !CanReadCoords())
255 return std::vector<CPDF_MeshVertex>();
257 vertices.emplace_back();
259 vertex.position = pObject2Bitmap.Transform(ReadCoords());
261 return std::vector<CPDF_MeshVertex>();
263 std::tie(vertex.r, vertex.g, vertex.b) = ReadColor();
264 m_BitStream->ByteAlign();