Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_imagerenderer.cpp
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "core/fpdfapi/render/cpdf_imagerenderer.h"
8
9#include <math.h>
10
11#include <algorithm>
12#include <memory>
13#include <utility>
14
15#include "core/fpdfapi/page/cpdf_dib.h"
16#include "core/fpdfapi/page/cpdf_docpagedata.h"
17#include "core/fpdfapi/page/cpdf_image.h"
18#include "core/fpdfapi/page/cpdf_imageloader.h"
19#include "core/fpdfapi/page/cpdf_imageobject.h"
20#include "core/fpdfapi/page/cpdf_occontext.h"
21#include "core/fpdfapi/page/cpdf_page.h"
22#include "core/fpdfapi/page/cpdf_pageimagecache.h"
23#include "core/fpdfapi/page/cpdf_pageobject.h"
24#include "core/fpdfapi/page/cpdf_shadingpattern.h"
25#include "core/fpdfapi/page/cpdf_tilingpattern.h"
26#include "core/fpdfapi/page/cpdf_transferfunc.h"
27#include "core/fpdfapi/parser/cpdf_dictionary.h"
28#include "core/fpdfapi/parser/cpdf_document.h"
29#include "core/fpdfapi/parser/cpdf_stream.h"
30#include "core/fpdfapi/parser/fpdf_parser_decode.h"
31#include "core/fpdfapi/render/cpdf_rendercontext.h"
32#include "core/fpdfapi/render/cpdf_renderstatus.h"
33#include "core/fxcrt/fx_safe_types.h"
34#include "core/fxcrt/maybe_owned.h"
35#include "core/fxge/cfx_defaultrenderdevice.h"
36#include "core/fxge/cfx_fillrenderoptions.h"
37#include "core/fxge/cfx_path.h"
38#include "core/fxge/dib/cfx_dibbase.h"
39#include "core/fxge/dib/cfx_dibitmap.h"
40#include "core/fxge/dib/cfx_imagestretcher.h"
41#include "core/fxge/dib/cfx_imagetransformer.h"
42#include "third_party/base/check.h"
43
44namespace {
45
46bool IsImageValueTooBig(int val) {
47 // Likely large enough for any real rendering need, but sufficiently small
48 // that operations like val1 + val2 or -val will not overflow.
49 constexpr int kLimit = 256 * 1024 * 1024;
50 FX_SAFE_INT32 safe_val = val;
51 safe_val = safe_val.Abs();
52 return safe_val.ValueOrDefault(kLimit) >= kLimit;
53}
54
55} // namespace
56
60
62
63bool CPDF_ImageRenderer::StartLoadDIBBase() {
64 if (!GetUnitRect().has_value())
65 return false;
66
67 if (!m_pLoader->Start(
68 m_pImageObject, m_pRenderStatus->GetContext()->GetPageCache(),
69 m_pRenderStatus->GetFormResource(),
70 m_pRenderStatus->GetPageResource(), m_bStdCS,
71 m_pRenderStatus->GetGroupFamily(), m_pRenderStatus->GetLoadMask(),
72 {m_pRenderStatus->GetRenderDevice()->GetWidth(),
73 m_pRenderStatus->GetRenderDevice()->GetHeight()})) {
74 return false;
75 }
76 m_Mode = Mode::kDefault;
77 return true;
78}
79
80bool CPDF_ImageRenderer::StartRenderDIBBase() {
81 if (!m_pLoader->GetBitmap())
82 return false;
83
84 CPDF_GeneralState& state = m_pImageObject->mutable_general_state();
85 m_Alpha = state.GetFillAlpha();
86 m_pDIBBase = m_pLoader->GetBitmap();
87 if (GetRenderOptions().ColorModeIs(CPDF_RenderOptions::kAlpha) &&
88 !m_pLoader->GetMask()) {
89 return StartBitmapAlpha();
90 }
91 RetainPtr<const CPDF_Object> pTR = state.GetTR();
92 if (pTR) {
93 if (!state.GetTransferFunc())
94 state.SetTransferFunc(m_pRenderStatus->GetTransferFunc(std::move(pTR)));
95
96 if (state.GetTransferFunc() && !state.GetTransferFunc()->GetIdentity())
97 m_pDIBBase = m_pLoader->TranslateImage(state.GetTransferFunc());
98 }
99 m_FillArgb = 0;
100 m_bPatternColor = false;
101 m_pPattern = nullptr;
102 if (m_pDIBBase->IsMaskFormat()) {
103 const CPDF_Color* pColor = m_pImageObject->color_state().GetFillColor();
104 if (pColor && pColor->IsPattern()) {
105 m_pPattern = pColor->GetPattern();
106 if (m_pPattern)
107 m_bPatternColor = true;
108 }
109 m_FillArgb = m_pRenderStatus->GetFillArgb(m_pImageObject);
110 } else if (GetRenderOptions().ColorModeIs(CPDF_RenderOptions::kGray)) {
111 RetainPtr<CFX_DIBitmap> pClone = m_pDIBBase->Realize();
112 if (!pClone)
113 return false;
114
115 pClone->ConvertColorScale(0xffffff, 0);
116 m_pDIBBase = pClone;
117 }
118 m_ResampleOptions = FXDIB_ResampleOptions();
119 if (GetRenderOptions().GetOptions().bForceHalftone)
120 m_ResampleOptions.bHalftone = true;
121
122 if (m_pRenderStatus->GetRenderDevice()->GetDeviceType() !=
123 DeviceType::kDisplay) {
124 HandleFilters();
125 }
126
127 if (GetRenderOptions().GetOptions().bNoImageSmooth)
128 m_ResampleOptions.bNoSmoothing = true;
129 else if (m_pImageObject->GetImage()->IsInterpol())
130 m_ResampleOptions.bInterpolateBilinear = true;
131
132 if (m_pLoader->GetMask())
133 return DrawMaskedImage();
134
135 if (m_bPatternColor)
136 return DrawPatternImage();
137
138 if (m_Alpha != 1.0f || !state.HasRef() || !state.GetFillOP() ||
139 state.GetOPMode() != 0 || state.GetBlendType() != BlendMode::kNormal ||
140 state.GetStrokeAlpha() != 1.0f || state.GetFillAlpha() != 1.0f) {
141 return StartDIBBase();
142 }
143 CPDF_Document* pDocument = nullptr;
144 CPDF_Page* pPage = nullptr;
145 if (auto* pPageCache = m_pRenderStatus->GetContext()->GetPageCache()) {
146 pPage = pPageCache->GetPage();
147 pDocument = pPage->GetDocument();
148 } else {
149 pDocument = m_pImageObject->GetImage()->GetDocument();
150 }
151 RetainPtr<const CPDF_Dictionary> pPageResources =
152 pPage ? pPage->GetPageResources() : nullptr;
153 RetainPtr<const CPDF_Dictionary> pStreamDict =
154 m_pImageObject->GetImage()->GetStream()->GetDict();
155 RetainPtr<const CPDF_Object> pCSObj =
156 pStreamDict->GetDirectObjectFor("ColorSpace");
157 auto* pData = CPDF_DocPageData::FromDocument(pDocument);
158 RetainPtr<CPDF_ColorSpace> pColorSpace =
159 pData->GetColorSpace(pCSObj.Get(), pPageResources);
160 if (pColorSpace) {
161 CPDF_ColorSpace::Family format = pColorSpace->GetFamily();
165 m_BlendType = BlendMode::kDarken;
166 }
167 }
168 return StartDIBBase();
169}
170
171bool CPDF_ImageRenderer::Start(CPDF_ImageObject* pImageObject,
172 const CFX_Matrix& mtObj2Device,
173 bool bStdCS,
174 BlendMode blendType) {
175 DCHECK(pImageObject);
176 m_bStdCS = bStdCS;
177 m_pImageObject = pImageObject;
178 m_BlendType = blendType;
179 m_mtObj2Device = mtObj2Device;
180 RetainPtr<const CPDF_Dictionary> pOC = m_pImageObject->GetImage()->GetOC();
181 if (pOC && !GetRenderOptions().CheckOCGDictVisible(pOC))
182 return false;
183
184 m_ImageMatrix = m_pImageObject->matrix() * mtObj2Device;
185 if (StartLoadDIBBase())
186 return true;
187
188 return StartRenderDIBBase();
189}
190
192 FX_ARGB bitmap_argb,
193 const CFX_Matrix& mtImage2Device,
194 const FXDIB_ResampleOptions& options,
195 bool bStdCS) {
196 m_pDIBBase = std::move(pDIBBase);
197 m_FillArgb = bitmap_argb;
198 m_Alpha = 1.0f;
199 m_ImageMatrix = mtImage2Device;
200 m_ResampleOptions = options;
201 m_bStdCS = bStdCS;
202 m_BlendType = BlendMode::kNormal;
203 return StartDIBBase();
204}
205
206bool CPDF_ImageRenderer::NotDrawing() const {
207 return m_pRenderStatus->IsPrint() &&
208 !(m_pRenderStatus->GetRenderDevice()->GetRenderCaps() &
210}
211
212FX_RECT CPDF_ImageRenderer::GetDrawRect() const {
213 FX_RECT rect = m_ImageMatrix.GetUnitRect().GetOuterRect();
214 rect.Intersect(m_pRenderStatus->GetRenderDevice()->GetClipBox());
215 return rect;
216}
217
218CFX_Matrix CPDF_ImageRenderer::GetDrawMatrix(const FX_RECT& rect) const {
219 CFX_Matrix new_matrix = m_ImageMatrix;
220 new_matrix.Translate(-rect.left, -rect.top);
221 return new_matrix;
222}
223
224void CPDF_ImageRenderer::CalculateDrawImage(
225 CFX_DefaultRenderDevice* pBitmapDevice1,
226 CFX_DefaultRenderDevice* pBitmapDevice2,
227 RetainPtr<CFX_DIBBase> pDIBBase,
228 const CFX_Matrix& mtNewMatrix,
229 const FX_RECT& rect) const {
230 CPDF_RenderStatus bitmap_render(m_pRenderStatus->GetContext(),
231 pBitmapDevice2);
232 bitmap_render.SetDropObjects(m_pRenderStatus->GetDropObjects());
233 bitmap_render.SetStdCS(true);
234 bitmap_render.Initialize(nullptr, nullptr);
235
236 CPDF_ImageRenderer image_render(&bitmap_render);
237 if (image_render.Start(std::move(pDIBBase), 0xffffffff, mtNewMatrix,
238 m_ResampleOptions, true)) {
239 image_render.Continue(nullptr);
240 }
241 if (m_pLoader->MatteColor() == 0xffffffff)
242 return;
243 int matte_r = FXARGB_R(m_pLoader->MatteColor());
244 int matte_g = FXARGB_G(m_pLoader->MatteColor());
245 int matte_b = FXARGB_B(m_pLoader->MatteColor());
246 for (int row = 0; row < rect.Height(); row++) {
247 uint8_t* dest_scan =
248 pBitmapDevice1->GetBitmap()->GetWritableScanline(row).data();
249 const uint8_t* mask_scan =
250 pBitmapDevice2->GetBitmap()->GetScanline(row).data();
251 for (int col = 0; col < rect.Width(); col++) {
252 int alpha = *mask_scan++;
253 if (!alpha) {
254 dest_scan += 4;
255 continue;
256 }
257 int orig = (*dest_scan - matte_b) * 255 / alpha + matte_b;
258 *dest_scan++ = std::clamp(orig, 0, 255);
259 orig = (*dest_scan - matte_g) * 255 / alpha + matte_g;
260 *dest_scan++ = std::clamp(orig, 0, 255);
261 orig = (*dest_scan - matte_r) * 255 / alpha + matte_r;
262 *dest_scan++ = std::clamp(orig, 0, 255);
263 dest_scan++;
264 }
265 }
266}
267
268const CPDF_RenderOptions& CPDF_ImageRenderer::GetRenderOptions() const {
269 return m_pRenderStatus->GetRenderOptions();
270}
271
272bool CPDF_ImageRenderer::DrawPatternImage() {
273 if (NotDrawing()) {
274 m_Result = false;
275 return false;
276 }
277
278 FX_RECT rect = GetDrawRect();
279 if (rect.IsEmpty())
280 return false;
281
282 CFX_Matrix new_matrix = GetDrawMatrix(rect);
283 CFX_DefaultRenderDevice bitmap_device1;
284 if (!bitmap_device1.Create(rect.Width(), rect.Height(), FXDIB_Format::kArgb,
285 nullptr)) {
286 return true;
287 }
288
289 CPDF_RenderStatus bitmap_render(m_pRenderStatus->GetContext(),
290 &bitmap_device1);
291 bitmap_render.SetOptions(GetRenderOptions());
292 bitmap_render.SetDropObjects(m_pRenderStatus->GetDropObjects());
293 bitmap_render.SetStdCS(true);
294 bitmap_render.Initialize(nullptr, nullptr);
295
296 CFX_Matrix patternDevice = m_mtObj2Device;
297 patternDevice.Translate(static_cast<float>(-rect.left),
298 static_cast<float>(-rect.top));
299 if (CPDF_TilingPattern* pTilingPattern = m_pPattern->AsTilingPattern()) {
300 bitmap_render.DrawTilingPattern(pTilingPattern, m_pImageObject,
301 patternDevice, false);
302 } else if (CPDF_ShadingPattern* pShadingPattern =
303 m_pPattern->AsShadingPattern()) {
304 bitmap_render.DrawShadingPattern(pShadingPattern, m_pImageObject,
305 patternDevice, false);
306 }
307
308 CFX_DefaultRenderDevice bitmap_device2;
309 if (!bitmap_device2.Create(rect.Width(), rect.Height(),
310 FXDIB_Format::k8bppRgb, nullptr)) {
311 return true;
312 }
313 CalculateDrawImage(&bitmap_device1, &bitmap_device2, m_pDIBBase, new_matrix,
314 rect);
315 bitmap_device2.GetBitmap()->ConvertFormat(FXDIB_Format::k8bppMask);
316 bitmap_device1.GetBitmap()->MultiplyAlphaMask(bitmap_device2.GetBitmap());
317 m_pRenderStatus->GetRenderDevice()->SetDIBitsWithBlend(
318 bitmap_device1.GetBitmap(), rect.left, rect.top, m_BlendType);
319 return false;
320}
321
322bool CPDF_ImageRenderer::DrawMaskedImage() {
323 if (NotDrawing()) {
324 m_Result = false;
325 return false;
326 }
327
328 FX_RECT rect = GetDrawRect();
329 if (rect.IsEmpty())
330 return false;
331
332 CFX_Matrix new_matrix = GetDrawMatrix(rect);
333 CFX_DefaultRenderDevice bitmap_device1;
334 if (!bitmap_device1.Create(rect.Width(), rect.Height(), FXDIB_Format::kRgb32,
335 nullptr)) {
336 return true;
337 }
338 bitmap_device1.Clear(0xffffffff);
339 CPDF_RenderStatus bitmap_render(m_pRenderStatus->GetContext(),
340 &bitmap_device1);
341 bitmap_render.SetDropObjects(m_pRenderStatus->GetDropObjects());
342 bitmap_render.SetStdCS(true);
343 bitmap_render.Initialize(nullptr, nullptr);
344 CPDF_ImageRenderer image_render(&bitmap_render);
345 if (image_render.Start(m_pDIBBase, 0, new_matrix, m_ResampleOptions, true)) {
346 image_render.Continue(nullptr);
347 }
348 CFX_DefaultRenderDevice bitmap_device2;
349 if (!bitmap_device2.Create(rect.Width(), rect.Height(),
350 FXDIB_Format::k8bppRgb, nullptr)) {
351 return true;
352 }
353 CalculateDrawImage(&bitmap_device1, &bitmap_device2, m_pLoader->GetMask(),
354 new_matrix, rect);
355 DCHECK(!bitmap_device2.GetBitmap()->HasPalette());
356 bitmap_device2.GetBitmap()->ConvertFormat(FXDIB_Format::k8bppMask);
357#if defined(PDF_USE_SKIA)
358 if (CFX_DefaultRenderDevice::UseSkiaRenderer() &&
359 m_pRenderStatus->GetRenderDevice()->SetBitsWithMask(
360 bitmap_device1.GetBitmap(), bitmap_device2.GetBitmap(), rect.left,
361 rect.top, m_Alpha, m_BlendType)) {
362 return false;
363 }
364#endif
365 bitmap_device1.GetBitmap()->MultiplyAlphaMask(bitmap_device2.GetBitmap());
366 bitmap_device1.GetBitmap()->MultiplyAlpha(m_Alpha);
367 m_pRenderStatus->GetRenderDevice()->SetDIBitsWithBlend(
368 bitmap_device1.GetBitmap(), rect.left, rect.top, m_BlendType);
369 return false;
370}
371
372bool CPDF_ImageRenderer::StartDIBBase() {
373 if (m_pDIBBase->GetBPP() > 1) {
374 FX_SAFE_SIZE_T image_size = m_pDIBBase->GetBPP();
375 image_size /= 8;
376 image_size *= m_pDIBBase->GetWidth();
377 image_size *= m_pDIBBase->GetHeight();
378 if (!image_size.IsValid())
379 return false;
380
381 if (image_size.ValueOrDie() > kHugeImageSize &&
382 !m_ResampleOptions.bHalftone) {
383 m_ResampleOptions.bInterpolateBilinear = true;
384 }
385 }
386 if (m_pRenderStatus->GetRenderDevice()->StartDIBitsWithBlend(
387 m_pDIBBase, m_Alpha, m_FillArgb, m_ImageMatrix, m_ResampleOptions,
388 &m_DeviceHandle, m_BlendType)) {
389 if (m_DeviceHandle) {
390 m_Mode = Mode::kBlend;
391 return true;
392 }
393 return false;
394 }
395
396 if ((fabs(m_ImageMatrix.b) >= 0.5f || m_ImageMatrix.a == 0) ||
397 (fabs(m_ImageMatrix.c) >= 0.5f || m_ImageMatrix.d == 0)) {
398 if (NotDrawing()) {
399 m_Result = false;
400 return false;
401 }
402
403 absl::optional<FX_RECT> image_rect = GetUnitRect();
404 if (!image_rect.has_value())
405 return false;
406
407 FX_RECT clip_box = m_pRenderStatus->GetRenderDevice()->GetClipBox();
408 clip_box.Intersect(image_rect.value());
409 m_Mode = Mode::kTransform;
410 m_pTransformer = std::make_unique<CFX_ImageTransformer>(
411 m_pDIBBase, m_ImageMatrix, m_ResampleOptions, &clip_box);
412 return true;
413 }
414
415 absl::optional<FX_RECT> image_rect = GetUnitRect();
416 if (!image_rect.has_value())
417 return false;
418
419 int dest_left;
420 int dest_top;
421 int dest_width;
422 int dest_height;
423 if (!GetDimensionsFromUnitRect(image_rect.value(), &dest_left, &dest_top,
424 &dest_width, &dest_height)) {
425 return false;
426 }
427
428 if (m_pDIBBase->IsOpaqueImage() && m_Alpha == 1.0f) {
429 if (m_pRenderStatus->GetRenderDevice()->StretchDIBitsWithFlagsAndBlend(
430 m_pDIBBase, dest_left, dest_top, dest_width, dest_height,
431 m_ResampleOptions, m_BlendType)) {
432 return false;
433 }
434 }
435 if (m_pDIBBase->IsMaskFormat()) {
436 if (m_Alpha != 1.0f) {
437 m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, FXSYS_roundf(m_Alpha * 255));
438 }
439 if (m_pRenderStatus->GetRenderDevice()->StretchBitMaskWithFlags(
440 m_pDIBBase, dest_left, dest_top, dest_width, dest_height,
441 m_FillArgb, m_ResampleOptions)) {
442 return false;
443 }
444 }
445 if (NotDrawing()) {
446 m_Result = false;
447 return true;
448 }
449
450 FX_RECT clip_box = m_pRenderStatus->GetRenderDevice()->GetClipBox();
451 FX_RECT dest_rect = clip_box;
452 dest_rect.Intersect(image_rect.value());
453 FX_RECT dest_clip(
454 dest_rect.left - image_rect->left, dest_rect.top - image_rect->top,
455 dest_rect.right - image_rect->left, dest_rect.bottom - image_rect->top);
456 RetainPtr<CFX_DIBitmap> pStretched = m_pDIBBase->StretchTo(
457 dest_width, dest_height, m_ResampleOptions, &dest_clip);
458 if (pStretched) {
459 m_pRenderStatus->CompositeDIBitmap(pStretched, dest_rect.left,
460 dest_rect.top, m_FillArgb, m_Alpha,
461 m_BlendType, CPDF_Transparency());
462 }
463 return false;
464}
465
466bool CPDF_ImageRenderer::StartBitmapAlpha() {
467 if (m_pDIBBase->IsOpaqueImage()) {
468 CFX_Path path;
469 path.AppendRect(0, 0, 1, 1);
470 path.Transform(m_ImageMatrix);
471 const int bitmap_alpha = FXSYS_roundf(m_Alpha * 255);
472 uint32_t fill_color =
473 ArgbEncode(0xff, bitmap_alpha, bitmap_alpha, bitmap_alpha);
474 m_pRenderStatus->GetRenderDevice()->DrawPath(
475 path, nullptr, nullptr, fill_color, 0,
476 CFX_FillRenderOptions::WindingOptions());
477 return false;
478 }
479
480 RetainPtr<CFX_DIBBase> alpha_mask =
481 m_pDIBBase->IsMaskFormat() ? m_pDIBBase : m_pDIBBase->CloneAlphaMask();
482 if (fabs(m_ImageMatrix.b) >= 0.5f || fabs(m_ImageMatrix.c) >= 0.5f) {
483 int left;
484 int top;
485 alpha_mask = alpha_mask->TransformTo(m_ImageMatrix, &left, &top);
486 if (!alpha_mask) {
487 return true;
488 }
489
490 const int bitmap_alpha = FXSYS_roundf(m_Alpha * 255);
491 m_pRenderStatus->GetRenderDevice()->SetBitMask(
492 std::move(alpha_mask), left, top,
493 ArgbEncode(0xff, bitmap_alpha, bitmap_alpha, bitmap_alpha));
494 return false;
495 }
496
497 absl::optional<FX_RECT> image_rect = GetUnitRect();
498 if (!image_rect.has_value())
499 return false;
500
501 int left;
502 int top;
503 int dest_width;
504 int dest_height;
505 if (!GetDimensionsFromUnitRect(image_rect.value(), &left, &top, &dest_width,
506 &dest_height)) {
507 return false;
508 }
509
510 const int bitmap_alpha = FXSYS_roundf(m_Alpha * 255);
511 m_pRenderStatus->GetRenderDevice()->StretchBitMask(
512 std::move(alpha_mask), left, top, dest_width, dest_height,
513 ArgbEncode(0xff, bitmap_alpha, bitmap_alpha, bitmap_alpha));
514 return false;
515}
516
518 switch (m_Mode) {
519 case Mode::kNone:
520 return false;
521 case Mode::kDefault:
522 return ContinueDefault(pPause);
523 case Mode::kBlend:
524 return ContinueBlend(pPause);
525 case Mode::kTransform:
526 return ContinueTransform(pPause);
527 }
528}
529
530bool CPDF_ImageRenderer::ContinueDefault(PauseIndicatorIface* pPause) {
531 if (m_pLoader->Continue(pPause))
532 return true;
533
534 if (!StartRenderDIBBase())
535 return false;
536
537 if (m_Mode == Mode::kDefault)
538 return false;
539
540 return Continue(pPause);
541}
542
543bool CPDF_ImageRenderer::ContinueBlend(PauseIndicatorIface* pPause) {
544 return m_pRenderStatus->GetRenderDevice()->ContinueDIBits(
545 m_DeviceHandle.get(), pPause);
546}
547
548bool CPDF_ImageRenderer::ContinueTransform(PauseIndicatorIface* pPause) {
549 if (m_pTransformer->Continue(pPause))
550 return true;
551
552 RetainPtr<CFX_DIBitmap> pBitmap = m_pTransformer->DetachBitmap();
553 if (!pBitmap)
554 return false;
555
556 if (pBitmap->IsMaskFormat()) {
557 if (m_Alpha != 1.0f) {
558 m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, FXSYS_roundf(m_Alpha * 255));
559 }
560 m_Result = m_pRenderStatus->GetRenderDevice()->SetBitMask(
561 pBitmap, m_pTransformer->result().left, m_pTransformer->result().top,
562 m_FillArgb);
563 } else {
564 pBitmap->MultiplyAlpha(m_Alpha);
565 m_Result = m_pRenderStatus->GetRenderDevice()->SetDIBitsWithBlend(
566 pBitmap, m_pTransformer->result().left, m_pTransformer->result().top,
567 m_BlendType);
568 }
569 return false;
570}
571
572void CPDF_ImageRenderer::HandleFilters() {
573 absl::optional<DecoderArray> decoder_array =
574 GetDecoderArray(m_pImageObject->GetImage()->GetStream()->GetDict());
575 if (!decoder_array.has_value())
576 return;
577
578 for (const auto& decoder : decoder_array.value()) {
579 if (decoder.first == "DCTDecode" || decoder.first == "JPXDecode") {
580 m_ResampleOptions.bLossy = true;
581 return;
582 }
583 }
584}
585
586absl::optional<FX_RECT> CPDF_ImageRenderer::GetUnitRect() const {
587 CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect();
588 FX_RECT image_rect = image_rect_f.GetOuterRect();
589 if (!image_rect.Valid())
590 return absl::nullopt;
591 return image_rect;
592}
593
594bool CPDF_ImageRenderer::GetDimensionsFromUnitRect(const FX_RECT& rect,
595 int* left,
596 int* top,
597 int* width,
598 int* height) const {
599 DCHECK(rect.Valid());
600
601 int dest_width = rect.Width();
602 int dest_height = rect.Height();
603 if (IsImageValueTooBig(dest_width) || IsImageValueTooBig(dest_height))
604 return false;
605
606 if (m_ImageMatrix.a < 0)
607 dest_width = -dest_width;
608
609 if (m_ImageMatrix.d > 0)
610 dest_height = -dest_height;
611
612 int dest_left = dest_width > 0 ? rect.left : rect.right;
613 int dest_top = dest_height > 0 ? rect.top : rect.bottom;
614 if (IsImageValueTooBig(dest_left) || IsImageValueTooBig(dest_top))
615 return false;
616
617 *left = dest_left;
618 *top = dest_top;
619 *width = dest_width;
620 *height = dest_height;
621 return true;
622}
bool Create(int width, int height, FXDIB_Format format, RetainPtr< CFX_DIBitmap > pBackdropBitmap)
FX_RECT GetOuterRect() const
CFX_Matrix & operator=(const CFX_Matrix &other)=default
void Translate(int32_t x, int32_t y)
CFX_FloatRect GetUnitRect() const
void Translate(float x, float y)
void Transform(const CFX_Matrix &matrix)
Definition cfx_path.cpp:392
void AppendRect(float left, float bottom, float right, float top)
Definition cfx_path.cpp:309
bool IsPattern() const
static CPDF_DocPageData * FromDocument(const CPDF_Document *pDoc)
float GetStrokeAlpha() const
BlendMode GetBlendType() const
CPDF_ImageRenderer(CPDF_RenderStatus *pStatus)
bool Start(RetainPtr< CFX_DIBBase > pDIBBase, FX_ARGB bitmap_argb, const CFX_Matrix &mtImage2Device, const FXDIB_ResampleOptions &options, bool bStdCS)
bool Continue(PauseIndicatorIface *pPause)
bool Start(CPDF_ImageObject *pImageObject, const CFX_Matrix &mtObj2Device, bool bStdCS, BlendMode blendType)
CPDF_Document * GetDocument() const override
Definition cpdf_page.cpp:51
const Options & GetOptions() const
bool CheckOCGDictVisible(const CPDF_Dictionary *pOC) const
bool ColorModeIs(Type mode) const
void SetOptions(const CPDF_RenderOptions &options)
void SetStdCS(bool bStdCS)
void Initialize(const CPDF_RenderStatus *pParentStatus, const CPDF_GraphicStates *pInitialStates)
#define FXARGB_MUL_ALPHA(argb, alpha)
Definition fx_dib.h:128
BlendMode
Definition fx_dib.h:49
#define FXARGB_B(argb)
Definition fx_dib.h:127
#define FXARGB_G(argb)
Definition fx_dib.h:126
constexpr FX_ARGB ArgbEncode(uint32_t a, uint32_t r, uint32_t g, uint32_t b)
Definition fx_dib.h:118
#define FXARGB_R(argb)
Definition fx_dib.h:125
FXDIB_Format
Definition fx_dib.h:19
int FXSYS_roundf(float f)
Definition fx_system.cpp:92
#define FXRC_BLEND_MODE
bool bInterpolateBilinear
Definition fx_dib.h:41
int Height() const
int32_t bottom
int32_t right
int Width() const
int32_t top
int32_t left
bool IsEmpty() const