7#include "core/fpdfapi/render/cpdf_rendershading.h"
17#include "core/fpdfapi/page/cpdf_colorspace.h"
18#include "core/fpdfapi/page/cpdf_dib.h"
19#include "core/fpdfapi/page/cpdf_function.h"
20#include "core/fpdfapi/page/cpdf_meshstream.h"
21#include "core/fpdfapi/parser/cpdf_array.h"
22#include "core/fpdfapi/parser/cpdf_dictionary.h"
23#include "core/fpdfapi/parser/cpdf_stream.h"
24#include "core/fpdfapi/parser/fpdf_parser_utility.h"
25#include "core/fpdfapi/render/cpdf_devicebuffer.h"
26#include "core/fpdfapi/render/cpdf_renderoptions.h"
27#include "core/fxcrt/fx_safe_types.h"
28#include "core/fxcrt/fx_system.h"
29#include "core/fxcrt/span_util.h"
30#include "core/fxcrt/unowned_ptr.h"
31#include "core/fxge/cfx_defaultrenderdevice.h"
32#include "core/fxge/cfx_fillrenderoptions.h"
33#include "core/fxge/cfx_path.h"
34#include "core/fxge/dib/cfx_dibitmap.h"
35#include "core/fxge/dib/fx_dib.h"
36#include "third_party/base/check.h"
37#include "third_party/base/check_op.h"
38#include "third_party/base/containers/span.h"
42constexpr int kShadingSteps = 256;
44uint32_t CountOutputsFromFunctions(
45 const std::vector<std::unique_ptr<CPDF_Function>>& funcs) {
46 FX_SAFE_UINT32 total = 0;
47 for (
const auto& func : funcs) {
49 total += func->CountOutputs();
51 return total.ValueOrDefault(0);
54uint32_t GetValidatedOutputsCount(
55 const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
57 uint32_t funcs_outputs = CountOutputsFromFunctions(funcs);
58 return funcs_outputs ? std::max(funcs_outputs, pCS->CountComponents()) : 0;
61std::array<FX_ARGB, kShadingSteps> GetShadingSteps(
64 const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
67 size_t results_count) {
68 DCHECK(results_count >= CountOutputsFromFunctions(funcs));
69 DCHECK(results_count >= pCS->CountComponents());
70 std::array<FX_ARGB, kShadingSteps> shading_steps;
71 std::vector<
float> result_array(results_count);
72 float diff = t_max - t_min;
73 for (
int i = 0; i < kShadingSteps; ++i) {
74 float input = diff * i / kShadingSteps + t_min;
75 pdfium::span<
float> result_span = pdfium::make_span(result_array);
76 for (
const auto& func : funcs) {
79 absl::optional<uint32_t> nresults =
80 func->Call(pdfium::span_from_ref(input), result_span);
81 if (nresults.has_value())
82 result_span = result_span.subspan(nresults.value());
87 pCS->GetRGB(result_array, &R, &G, &B);
94void DrawAxialShading(
const RetainPtr<CFX_DIBitmap>& pBitmap,
96 const CPDF_Dictionary* pDict,
97 const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
100 DCHECK_EQ(pBitmap->GetFormat(), FXDIB_Format::kArgb);
102 const uint32_t total_results = GetValidatedOutputsCount(funcs, pCS);
103 if (total_results == 0)
106 RetainPtr<
const CPDF_Array> pCoords = pDict->GetArrayFor(
"Coords");
110 float start_x = pCoords->GetFloatAt(0);
111 float start_y = pCoords->GetFloatAt(1);
112 float end_x = pCoords->GetFloatAt(2);
113 float end_y = pCoords->GetFloatAt(3);
116 RetainPtr<
const CPDF_Array> pArray = pDict->GetArrayFor(
"Domain");
118 t_min = pArray->GetFloatAt(0);
119 t_max = pArray->GetFloatAt(1);
122 const bool bStartExtend = pArray && pArray->GetBooleanAt(0,
false);
123 const bool bEndExtend = pArray && pArray->GetBooleanAt(1,
false);
125 int width = pBitmap->GetWidth();
126 int height = pBitmap->GetHeight();
127 float x_span = end_x - start_x;
128 float y_span = end_y - start_y;
129 float axis_len_square = (x_span * x_span) + (y_span * y_span);
131 std::array<FX_ARGB, kShadingSteps> shading_steps =
132 GetShadingSteps(t_min, t_max, funcs, pCS, alpha, total_results);
135 for (
int row = 0; row < height; row++) {
137 fxcrt::reinterpret_span<uint32_t>(pBitmap->GetWritableScanline(row))
139 for (
int column = 0; column < width; column++) {
140 CFX_PointF pos = matrix.Transform(
141 CFX_PointF(
static_cast<
float>(column),
static_cast<
float>(row)));
143 (((pos.x - start_x) * x_span) + ((pos.y - start_y) * y_span)) /
145 int index =
static_cast<int32_t>(scale * (kShadingSteps - 1));
151 }
else if (index >= kShadingSteps) {
155 index = kShadingSteps - 1;
157 dib_buf[column] = shading_steps[index];
162void DrawRadialShading(
const RetainPtr<CFX_DIBitmap>& pBitmap,
164 const CPDF_Dictionary* pDict,
165 const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
168 DCHECK_EQ(pBitmap->GetFormat(), FXDIB_Format::kArgb);
170 const uint32_t total_results = GetValidatedOutputsCount(funcs, pCS);
171 if (total_results == 0)
174 RetainPtr<
const CPDF_Array> pCoords = pDict->GetArrayFor(
"Coords");
178 float start_x = pCoords->GetFloatAt(0);
179 float start_y = pCoords->GetFloatAt(1);
180 float start_r = pCoords->GetFloatAt(2);
181 float end_x = pCoords->GetFloatAt(3);
182 float end_y = pCoords->GetFloatAt(4);
183 float end_r = pCoords->GetFloatAt(5);
186 RetainPtr<
const CPDF_Array> pArray = pDict->GetArrayFor(
"Domain");
188 t_min = pArray->GetFloatAt(0);
189 t_max = pArray->GetFloatAt(1);
192 const bool bStartExtend = pArray && pArray->GetBooleanAt(0,
false);
193 const bool bEndExtend = pArray && pArray->GetBooleanAt(1,
false);
195 std::array<FX_ARGB, kShadingSteps> shading_steps =
196 GetShadingSteps(t_min, t_max, funcs, pCS, alpha, total_results);
198 const float dx = end_x - start_x;
199 const float dy = end_y - start_y;
200 const float dr = end_r - start_r;
201 const float a = dx * dx + dy * dy - dr * dr;
204 int width = pBitmap->GetWidth();
205 int height = pBitmap->GetHeight();
206 bool bDecreasing = dr < 0 &&
static_cast<
int>(
FXSYS_sqrt2(dx
, dy
)) < -dr;
209 for (
int row = 0; row < height; row++) {
211 fxcrt::reinterpret_span<uint32_t>(pBitmap->GetWritableScanline(row))
213 for (
int column = 0; column < width; column++) {
214 CFX_PointF pos = matrix.Transform(
215 CFX_PointF(
static_cast<
float>(column),
static_cast<
float>(row)));
216 float pos_dx = pos.x - start_x;
217 float pos_dy = pos.y - start_y;
218 float b = -2 * (pos_dx * dx + pos_dy * dy + start_r * dr);
219 float c = pos_dx * pos_dx + pos_dy * pos_dy - start_r * start_r;
223 }
else if (a_is_float_zero) {
226 float b2_4ac = (b * b) - 4 * (a * c);
230 float root = sqrt(b2_4ac);
231 float s1 = (-b - root) / (2 * a);
232 float s2 = (-b + root) / (2 * a);
236 s = (s1 >= 0 || bStartExtend) ? s1 : s2;
238 s = (s2 <= 1.0f || bEndExtend) ? s2 : s1;
240 if (start_r + s * dr < 0)
244 int index =
static_cast<int32_t>(s * (kShadingSteps - 1));
249 }
else if (index >= kShadingSteps) {
252 index = kShadingSteps - 1;
254 dib_buf[column] = shading_steps[index];
259void DrawFuncShading(
const RetainPtr<CFX_DIBitmap>& pBitmap,
261 const CPDF_Dictionary* pDict,
262 const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
265 DCHECK_EQ(pBitmap->GetFormat(), FXDIB_Format::kArgb);
267 const uint32_t total_results = GetValidatedOutputsCount(funcs, pCS);
268 if (total_results == 0)
271 RetainPtr<
const CPDF_Array> pDomain = pDict->GetArrayFor(
"Domain");
277 xmin = pDomain->GetFloatAt(0);
278 xmax = pDomain->GetFloatAt(1);
279 ymin = pDomain->GetFloatAt(2);
280 ymax = pDomain->GetFloatAt(3);
285 int width = pBitmap->GetWidth();
286 int height = pBitmap->GetHeight();
288 DCHECK(total_results >= CountOutputsFromFunctions(funcs));
289 DCHECK(total_results >= pCS->CountComponents());
290 std::vector<
float> result_array(total_results);
291 for (
int row = 0; row < height; ++row) {
293 fxcrt::reinterpret_span<uint32_t>(pBitmap->GetWritableScanline(row))
295 for (
int column = 0; column < width; column++) {
296 CFX_PointF pos = matrix.Transform(
297 CFX_PointF(
static_cast<
float>(column),
static_cast<
float>(row)));
298 if (pos.x < xmin || pos.x > xmax || pos.y < ymin || pos.y > ymax)
301 float input[2] = {pos.x, pos.y};
302 pdfium::span<
float> result_span = pdfium::make_span(result_array);
303 for (
const auto& func : funcs) {
306 absl::optional<uint32_t> nresults = func->Call(input, result_span);
307 if (nresults.has_value())
308 result_span = result_span.subspan(nresults.value());
313 pCS->GetRGB(result_array, &R, &G, &B);
314 dib_buf[column] =
ArgbEncode(alpha
, static_cast<int32_t>(R * 255)
,
315 static_cast<int32_t>(G * 255)
,
316 static_cast<int32_t>(B * 255)
);
321bool GetScanlineIntersect(
int y,
322 const CFX_PointF& first,
323 const CFX_PointF& second,
325 if (first.y == second.y)
328 if (first.y < second.y) {
329 if (y < first.y || y > second.y)
331 }
else if (y < second.y || y > first.y) {
334 *x = first.x + ((second.x - first.x) * (y - first.y) / (second.y - first.y));
338void DrawGouraud(
const RetainPtr<CFX_DIBitmap>& pBitmap,
341 float min_y = triangle[0].position.y;
342 float max_y = triangle[0].position.y;
343 for (
int i = 1; i < 3; i++) {
344 min_y =
std::min(min_y, triangle[i].position.y);
345 max_y =
std::max(max_y, triangle[i].position.y);
350 int min_yi =
std::max(
static_cast<
int>(floorf(min_y)), 0);
351 int max_yi =
static_cast<
int>(ceilf(max_y));
352 if (max_yi >= pBitmap->GetHeight())
353 max_yi = pBitmap->GetHeight() - 1;
355 for (
int y = min_yi; y <= max_yi; y++) {
361 for (
int i = 0; i < 3; i++) {
364 CFX_PointF& position1 = vertex1.position;
365 CFX_PointF& position2 = vertex2.position;
367 GetScanlineIntersect(y, position1, position2, &inter_x[nIntersects]);
371 float y_dist = (y - position1.y) / (position2.y - position1.y);
372 r[nIntersects] = vertex1
.r + ((vertex2
.r - vertex1
.r) * y_dist);
373 g[nIntersects] = vertex1
.g + ((vertex2
.g - vertex1
.g) * y_dist);
374 b[nIntersects] = vertex1
.b + ((vertex2
.b - vertex1
.b) * y_dist);
377 if (nIntersects != 2)
384 if (inter_x[0] < inter_x[1]) {
385 min_x =
static_cast<
int>(floorf(inter_x[0]));
386 max_x =
static_cast<
int>(ceilf(inter_x[1]));
390 min_x =
static_cast<
int>(floorf(inter_x[1]));
391 max_x =
static_cast<
int>(ceilf(inter_x[0]));
396 int start_x = std::clamp(min_x, 0, pBitmap->GetWidth());
397 int end_x = std::clamp(max_x, 0, pBitmap->GetWidth());
398 float r_unit = (r[end_index] - r[start_index]) / (max_x - min_x);
399 float g_unit = (g[end_index] - g[start_index]) / (max_x - min_x);
400 float b_unit = (b[end_index] - b[start_index]) / (max_x - min_x);
401 float r_result = r[start_index] + (start_x - min_x) * r_unit;
402 float g_result = g[start_index] + (start_x - min_x) * g_unit;
403 float b_result = b[start_index] + (start_x - min_x) * b_unit;
404 pdfium::span<uint8_t> dib_span =
405 pBitmap->GetWritableScanline(y).subspan(start_x * 4);
407 for (
int x = start_x; x < end_x; x++) {
408 uint8_t* dib_buf = dib_span.data();
413 static_cast<
int>(g_result * 255)
,
414 static_cast<
int>(b_result * 255)
));
415 dib_span = dib_span.subspan(4);
420void DrawFreeGouraudShading(
423 RetainPtr<
const CPDF_Stream> pShadingStream,
424 const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
427 DCHECK_EQ(pBitmap->GetFormat(), FXDIB_Format::kArgb);
430 std::move(pShadingStream),
std::move(pCS));
442 triangle[0] = vertex;
443 for (
int i = 1; i < 3; ++i) {
450 triangle[0] = triangle[1];
452 triangle[1] = triangle[2];
453 triangle[2] = vertex;
455 DrawGouraud(pBitmap, alpha, triangle);
459void DrawLatticeGouraudShading(
462 RetainPtr<
const CPDF_Stream> pShadingStream,
463 const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
466 DCHECK_EQ(pBitmap->GetFormat(), FXDIB_Format::kArgb);
468 int row_verts = pShadingStream->GetDict()->GetIntegerFor(
"VerticesPerRow");
473 std::move(pShadingStream),
std::move(pCS));
477 std::vector<CPDF_MeshVertex> vertices[2];
478 vertices[0] = stream.ReadVertexRow(mtObject2Bitmap, row_verts);
479 if (vertices[0].empty())
484 vertices[1 - last_index] = stream.ReadVertexRow(mtObject2Bitmap, row_verts);
485 if (vertices[1 - last_index].empty())
489 for (
int i = 1; i < row_verts; ++i) {
490 triangle[0] = vertices[last_index][i];
491 triangle[1] = vertices[1 - last_index][i - 1];
492 triangle[2] = vertices[last_index][i - 1];
493 DrawGouraud(pBitmap, alpha, triangle);
494 triangle[2] = vertices[1 - last_index][i];
495 DrawGouraud(pBitmap, alpha, triangle);
497 last_index = 1 - last_index;
501struct CoonBezierCoeff {
502 void InitFromPoints(
float p0,
float p1,
float p2,
float p3) {
503 a = -p0 + 3 * p1 - 3 * p2 + p3;
504 b = 3 * p0 - 6 * p1 + 3 * p2;
505 c = -3 * p0 + 3 * p1;
509 void InitFromBezierInterpolation(
const CoonBezierCoeff& C1,
510 const CoonBezierCoeff& C2,
511 const CoonBezierCoeff& D1,
512 const CoonBezierCoeff& D2) {
513 a = (D1.a + D2.a) / 2;
514 b = (D1.b + D2.b) / 2;
515 c = (D1.c + D2.c) / 2 - (C1.a / 8 + C1.b / 4 + C1.c / 2) +
516 (C2.a / 8 + C2.b / 4) + (-C1.d + D2.d) / 2 - (C2.a + C2.b) / 2;
517 d = C1.a / 8 + C1.b / 4 + C1.c / 2 + C1.d;
520 CoonBezierCoeff first_half()
const {
521 CoonBezierCoeff result;
529 CoonBezierCoeff second_half()
const {
530 CoonBezierCoeff result;
532 result.b = 3 * a / 8 + b / 4;
533 result.c = 3 * a / 8 + b / 2 + c / 2;
534 result.d = a / 8 + b / 4 + c / 2 + d;
538 void GetPoints(
float p[4])
const {
541 p[2] = b / 3 - p[0] + 2 * p[1];
542 p[3] = a + p[0] - 3 * p[1] + 3 * p[2];
545 float Distance()
const {
546 float dis = a + b + c;
547 return dis < 0 ? -dis : dis;
557 void InitFromPoints(
float x0,
565 x.InitFromPoints(x0, x1, x2, x3);
566 y.InitFromPoints(y0, y1, y2, y3);
569 void InitFromBezierInterpolation(
const CoonBezier& C1,
570 const CoonBezier& C2,
571 const CoonBezier& D1,
572 const CoonBezier& D2) {
573 x.InitFromBezierInterpolation(C1.x, C2.x, D1.x, D2.x);
574 y.InitFromBezierInterpolation(C1.y, C2.y, D1.y, D2.y);
577 CoonBezier first_half()
const {
579 result.x = x.first_half();
580 result.y = y.first_half();
584 CoonBezier second_half()
const {
586 result.x = x.second_half();
587 result.y = y.second_half();
591 void GetPoints(pdfium::span<
CFX_Path::
Point> path_points)
const {
592 constexpr size_t kPointsCount = 4;
593 float points_x[kPointsCount];
594 float points_y[kPointsCount];
595 x.GetPoints(points_x);
596 y.GetPoints(points_y);
597 for (size_t i = 0; i < kPointsCount; ++i)
598 path_points[i].m_Point = {points_x[i], points_y[i]};
601 void GetPointsReverse(pdfium::span<
CFX_Path::
Point> path_points)
const {
602 constexpr size_t kPointsCount = 4;
603 float points_x[kPointsCount];
604 float points_y[kPointsCount];
605 x.GetPoints(points_x);
606 y.GetPoints(points_y);
607 for (size_t i = 0; i < kPointsCount; ++i) {
608 size_t reverse_index = kPointsCount - i - 1;
609 path_points[i].m_Point = {points_x[reverse_index],
610 points_y[reverse_index]};
614 float Distance()
const {
return x.Distance() + y.Distance(); }
620int Interpolate(
int p1,
int p2,
int delta1,
int delta2,
bool* overflow) {
621 FX_SAFE_INT32 p = p2;
628 return p.ValueOrDefault(0);
631int BiInterpolImpl(
int c0,
640 int x1 = Interpolate(c0, c3, x, x_scale, overflow);
641 int x2 = Interpolate(c1, c2, x, x_scale, overflow);
642 return Interpolate(x1, x2, y, y_scale, overflow);
646 CoonColor() =
default;
649 bool BiInterpol(CoonColor colors[4],
int x,
int y,
int x_scale,
int y_scale) {
650 bool overflow =
false;
651 for (
int i = 0; i < 3; i++) {
652 comp[i] = BiInterpolImpl(colors[0].comp[i], colors[1].comp[i],
653 colors[2].comp[i], colors[3].comp[i], x, y,
654 x_scale, y_scale, &overflow);
659 int Distance(
const CoonColor& o)
const {
660 return std::max({abs(comp[0] - o.comp[0]), abs(comp[1] - o.comp[1]),
661 abs(comp[2] - o.comp[2])});
668 static constexpr int kCoonColorThreshold = 4;
670 void Draw(
int x_scale,
678 bool bSmall = C1.Distance() < 2 && C2.Distance() < 2 && D1.Distance() < 2 &&
680 CoonColor div_colors[4];
685 if (!div_colors[0].BiInterpol(patch_colors, left, bottom, x_scale,
690 if (!div_colors[1].BiInterpol(patch_colors, left, bottom + 1, x_scale,
694 if (!div_colors[2].BiInterpol(patch_colors, left + 1, bottom + 1, x_scale,
698 if (!div_colors[3].BiInterpol(patch_colors, left + 1, bottom, x_scale,
702 d_bottom = div_colors[3].Distance(div_colors[0]);
703 d_left = div_colors[1].Distance(div_colors[0]);
704 d_top = div_colors[1].Distance(div_colors[2]);
705 d_right = div_colors[2].Distance(div_colors[3]);
709 (d_bottom < kCoonColorThreshold && d_left < kCoonColorThreshold &&
710 d_top < kCoonColorThreshold && d_right < kCoonColorThreshold)) {
712 C1.GetPoints(points.subspan(0, 4));
713 D2.GetPoints(points.subspan(3, 4));
714 C2.GetPointsReverse(points.subspan(6, 4));
715 D1.GetPointsReverse(points.subspan(9, 4));
723 path,
nullptr,
nullptr,
724 ArgbEncode(alpha, div_colors[0].comp[0], div_colors[0].comp[1],
725 div_colors[0].comp[2]),
728 if (d_bottom < kCoonColorThreshold && d_top < kCoonColorThreshold) {
730 m1.InitFromBezierInterpolation(D1, D2, C1, C2);
733 Draw(x_scale, y_scale, left, bottom, C1, m1, D1.first_half(),
735 Draw(x_scale, y_scale, left, bottom + 1, m1, C2, D1.second_half(),
737 }
else if (d_left < kCoonColorThreshold &&
738 d_right < kCoonColorThreshold) {
740 m2.InitFromBezierInterpolation(C1, C2, D1, D2);
743 Draw(x_scale, y_scale, left, bottom, C1.first_half(), C2.first_half(),
745 Draw(x_scale, y_scale, left + 1, bottom, C1.second_half(),
746 C2.second_half(), m2, D2);
750 m1.InitFromBezierInterpolation(D1, D2, C1, C2);
751 m2.InitFromBezierInterpolation(C1, C2, D1, D2);
752 CoonBezier m1f = m1.first_half();
753 CoonBezier m1s = m1.second_half();
754 CoonBezier m2f = m2.first_half();
755 CoonBezier m2s = m2.second_half();
760 Draw(x_scale, y_scale, left, bottom, C1.first_half(), m1f,
761 D1.first_half(), m2f);
762 Draw(x_scale, y_scale, left, bottom + 1, m1f, C2.first_half(),
763 D1.second_half(), m2s);
764 Draw(x_scale, y_scale, left + 1, bottom, C1.second_half(), m1s, m2f,
766 Draw(x_scale, y_scale, left + 1, bottom + 1, m1s, C2.second_half(), m2s,
777 CoonColor patch_colors[4];
780void DrawCoonPatchMeshes(
784 RetainPtr<
const CPDF_Stream> pShadingStream,
785 const std::vector<std::unique_ptr<CPDF_Function>>& funcs,
789 DCHECK_EQ(pBitmap->GetFormat(), FXDIB_Format::kArgb);
790 DCHECK(type == kCoonsPatchMeshShading ||
791 type == kTensorProductPatchMeshShading);
793 CFX_DefaultRenderDevice device;
803 patch.pDevice = &device;
804 patch.bNoPathSmooth = bNoPathSmooth;
806 for (
int i = 0; i < 13; i++) {
807 patch.path.AppendPoint(CFX_PointF(), i == 0
812 CFX_PointF coords[16];
824 CFX_PointF tempCoords[4];
825 for (i = 0; i < 4; i++) {
826 tempCoords[i] = coords[(flag * 3 + i) % 12];
828 fxcrt::spancpy(pdfium::make_span(coords), pdfium::make_span(tempCoords));
829 CoonColor tempColors[2] = {
830 tempColors[0] = patch.patch_colors[flag],
831 tempColors[1] = patch.patch_colors[(flag + 1) % 4]};
832 fxcrt::spancpy(pdfium::make_span(patch.patch_colors),
833 pdfium::make_span(tempColors));
835 for (i = iStartPoint; i < point_count; i++) {
841 for (i = iStartColor; i < 4; i++) {
850 patch.patch_colors[i].comp[0] =
static_cast<int32_t>(r * 255);
851 patch.patch_colors[i].comp[1] =
static_cast<int32_t>(g * 255);
852 patch.patch_colors[i].comp[2] =
static_cast<int32_t>(b * 255);
856 if (bbox.right <= 0 || bbox.left >= (
float)pBitmap->GetWidth() ||
857 bbox.top <= 0 || bbox.bottom >= (
float)pBitmap->GetHeight()) {
864 C1.InitFromPoints(coords[0].x, coords[0].y, coords[11].x, coords[11].y,
865 coords[10].x, coords[10].y, coords[9].x, coords[9].y);
866 C2.InitFromPoints(coords[3].x, coords[3].y, coords[4].x, coords[4].y,
867 coords[5].x, coords[5].y, coords[6].x, coords[6].y);
868 D1.InitFromPoints(coords[0].x, coords[0].y, coords[1].x, coords[1].y,
869 coords[2].x, coords[2].y, coords[3].x, coords[3].y);
870 D2.InitFromPoints(coords[9].x, coords[9].y, coords[8].x, coords[8].y,
871 coords[7].x, coords[7].y, coords[6].x, coords[6].y);
872 patch.Draw(1, 1, 0, 0, C1, C2, D1, D2);
882 const CPDF_ShadingPattern* pPattern,
891 FX_ARGB background = 0;
893 pPattern->GetShadingObject()->GetDict();
895 RetainPtr<
const CPDF_Array> pBackColor = pDict->GetArrayFor(
"Background");
896 if (pBackColor && pBackColor->size() >= pColorSpace->CountComponents()) {
897 std::vector<
float> comps = ReadArrayElementsToVector(
898 pBackColor.Get(), pColorSpace->CountComponents());
903 pColorSpace->GetRGB(comps, &R, &G, &B);
905 static_cast<int32_t>(G * 255)
,
906 static_cast<int32_t>(B * 255)
);
909 FX_RECT clip_rect_bbox = clip_rect;
910 if (pDict->KeyExist(
"BBox")) {
911 clip_rect_bbox.Intersect(
912 mtMatrix.TransformRect(pDict->GetRectFor(
"BBox")).GetOuterRect());
921 RetainPtr<CFX_DIBitmap> pBitmap = buffer.Initialize();
926 if (background != 0) {
927 pBitmap->Clear(background);
930 const auto& funcs = pPattern->GetFuncs();
936 DrawFuncShading(pBitmap, final_matrix, pDict.Get(), funcs, pColorSpace,
940 DrawAxialShading(pBitmap, final_matrix, pDict.Get(), funcs, pColorSpace,
944 DrawRadialShading(pBitmap, final_matrix, pDict.Get(), funcs, pColorSpace,
951 ToStream(pPattern->GetShadingObject());
953 DrawFreeGouraudShading(pBitmap, final_matrix,
std::move(pStream), funcs,
962 ToStream(pPattern->GetShadingObject());
964 DrawLatticeGouraudShading(pBitmap, final_matrix,
std::move(pStream),
965 funcs, pColorSpace, alpha);
974 ToStream(pPattern->GetShadingObject());
977 std::move(pStream), funcs, pColorSpace,
984 pBitmap->SetRedFromBitmap(pBitmap);
987 pBitmap->ConvertColorScale(0, 0xffffff);
bool Attach(RetainPtr< CFX_DIBitmap > pBitmap)
static CFX_FloatRect GetBBox(pdfium::span< const CFX_PointF > pPoints)
CFX_Matrix operator*(const CFX_Matrix &right) const
CFX_PointF Transform(const CFX_PointF &point) const
CFX_Matrix GetInverse() const
bool DrawShading(const CPDF_ShadingPattern *pPattern, const CFX_Matrix *pMatrix, const FX_RECT &clip_rect, int alpha, bool bAlphaMode)
int GetDeviceCaps(int id) const
CPDF_DeviceBuffer(CPDF_RenderContext *pContext, CFX_RenderDevice *pDevice, const FX_RECT &rect, const CPDF_PageObject *pObj, int max_dpi)
const CFX_Matrix & GetMatrix() const
RetainPtr< const CPDF_Array > GetArrayFor(const ByteString &key) const
CFX_Matrix GetMatrixFor(const ByteString &key) const
bool CanReadCoords() const
bool ReadVertex(const CFX_Matrix &pObject2Bitmap, CPDF_MeshVertex *vertex, uint32_t *flag)
bool CanReadColor() const
std::tuple< float, float, float > ReadColor()
const Options & GetOptions() const
bool ColorModeIs(Type mode) const
static void Draw(CFX_RenderDevice *pDevice, CPDF_RenderContext *pContext, const CPDF_PageObject *pCurObj, const CPDF_ShadingPattern *pPattern, const CFX_Matrix &mtMatrix, const FX_RECT &clip_rect, int alpha, const CPDF_RenderOptions &options)
ShadingType GetShadingType() const
bool IsShadingObject() const
@ kTensorProductPatchMeshShading
@ kLatticeFormGouraudTriangleMeshShading
@ kFreeFormGouraudTriangleMeshShading
constexpr FX_ARGB ArgbEncode(uint32_t a, uint32_t r, uint32_t g, uint32_t b)
#define FXARGB_SETDIB(p, argb)
#define FXSYS_IsFloatZero(f)
int FXSYS_roundf(float f)
float FXSYS_sqrt2(float a, float b)
static constexpr CFX_FillRenderOptions WindingOptions()