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
cfx_agg_imagerenderer.cpp
Go to the documentation of this file.
1// Copyright 2017 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/fxge/agg/cfx_agg_imagerenderer.h"
8
9#include <math.h>
10
11#include <memory>
12#include <utility>
13
14#include "core/fxcrt/fx_system.h"
15#include "core/fxge/agg/cfx_agg_cliprgn.h"
16#include "core/fxge/dib/cfx_dibitmap.h"
17#include "core/fxge/dib/cfx_imagestretcher.h"
18#include "core/fxge/dib/cfx_imagetransformer.h"
19
21 const RetainPtr<CFX_DIBitmap>& pDevice,
22 const CFX_AggClipRgn* pClipRgn,
23 RetainPtr<const CFX_DIBBase> source,
24 float alpha,
25 uint32_t mask_color,
26 const CFX_Matrix& matrix,
27 const FXDIB_ResampleOptions& options,
28 bool bRgbByteOrder)
31 m_Matrix(matrix),
32 m_Alpha(alpha),
33 m_MaskColor(mask_color),
34 m_bRgbByteOrder(bRgbByteOrder) {
35 FX_RECT image_rect = m_Matrix.GetUnitRect().GetOuterRect();
36 m_ClipBox = pClipRgn
37 ? pClipRgn->GetBox()
38 : FX_RECT(0, 0, pDevice->GetWidth(), pDevice->GetHeight());
39 m_ClipBox.Intersect(image_rect);
40 if (m_ClipBox.IsEmpty())
41 return;
42
43 if ((fabs(m_Matrix.b) >= 0.5f || m_Matrix.a == 0) ||
44 (fabs(m_Matrix.c) >= 0.5f || m_Matrix.d == 0)) {
45 if (fabs(m_Matrix.a) < fabs(m_Matrix.b) / 20 &&
46 fabs(m_Matrix.d) < fabs(m_Matrix.c) / 20 && fabs(m_Matrix.a) < 0.5f &&
47 fabs(m_Matrix.d) < 0.5f) {
48 int dest_width = image_rect.Width();
49 int dest_height = image_rect.Height();
50 FX_RECT bitmap_clip = m_ClipBox;
51 bitmap_clip.Offset(-image_rect.left, -image_rect.top);
52 bitmap_clip = bitmap_clip.SwappedClipBox(dest_width, dest_height,
53 m_Matrix.c > 0, m_Matrix.b < 0);
54 const bool flip_x = m_Matrix.c > 0;
55 const bool flip_y = m_Matrix.b < 0;
56 m_Composer.Compose(pDevice, pClipRgn, alpha, mask_color, m_ClipBox,
57 /*bVertical=*/true, flip_x, flip_y, m_bRgbByteOrder,
58 BlendMode::kNormal);
59 m_Stretcher = std::make_unique<CFX_ImageStretcher>(
60 &m_Composer, std::move(source), dest_height, dest_width, bitmap_clip,
61 options);
62 if (m_Stretcher->Start())
63 m_State = State::kStretching;
64 return;
65 }
66 m_State = State::kTransforming;
67 m_pTransformer = std::make_unique<CFX_ImageTransformer>(
68 std::move(source), m_Matrix, options, &m_ClipBox);
69 return;
70 }
71
72 int dest_width = image_rect.Width();
73 if (m_Matrix.a < 0)
74 dest_width = -dest_width;
75
76 int dest_height = image_rect.Height();
77 if (m_Matrix.d > 0)
78 dest_height = -dest_height;
79
80 if (dest_width == 0 || dest_height == 0)
81 return;
82
83 FX_RECT bitmap_clip = m_ClipBox;
84 bitmap_clip.Offset(-image_rect.left, -image_rect.top);
85 m_Composer.Compose(pDevice, pClipRgn, alpha, mask_color, m_ClipBox,
86 /*bVertical=*/false, /*bFlipX=*/false, /*bFlipY=*/false,
87 m_bRgbByteOrder, BlendMode::kNormal);
88 m_State = State::kStretching;
89 m_Stretcher = std::make_unique<CFX_ImageStretcher>(
90 &m_Composer, std::move(source), dest_width, dest_height, bitmap_clip,
91 options);
92 m_Stretcher->Start();
93}
94
96
98 if (m_State == State::kStretching)
99 return m_Stretcher->Continue(pPause);
100 if (m_State != State::kTransforming)
101 return false;
102 if (m_pTransformer->Continue(pPause))
103 return true;
104
105 RetainPtr<CFX_DIBitmap> pBitmap = m_pTransformer->DetachBitmap();
106 if (!pBitmap || pBitmap->GetBuffer().empty())
107 return false;
108
109 if (pBitmap->IsMaskFormat()) {
110 if (m_Alpha != 1.0f) {
111 m_MaskColor = FXARGB_MUL_ALPHA(m_MaskColor, FXSYS_roundf(m_Alpha * 255));
112 }
113 m_pDevice->CompositeMask(m_pTransformer->result().left,
114 m_pTransformer->result().top, pBitmap->GetWidth(),
115 pBitmap->GetHeight(), pBitmap, m_MaskColor, 0, 0,
116 BlendMode::kNormal, m_pClipRgn, m_bRgbByteOrder);
117 } else {
118 pBitmap->MultiplyAlpha(m_Alpha);
119 m_pDevice->CompositeBitmap(
120 m_pTransformer->result().left, m_pTransformer->result().top,
121 pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, 0, 0,
122 BlendMode::kNormal, m_pClipRgn, m_bRgbByteOrder);
123 }
124 return false;
125}
bool Continue(PauseIndicatorIface *pPause)
CFX_AggImageRenderer(const RetainPtr< CFX_DIBitmap > &pDevice, const CFX_AggClipRgn *pClipRgn, RetainPtr< const CFX_DIBBase > source, float alpha, uint32_t mask_color, const CFX_Matrix &matrix, const FXDIB_ResampleOptions &options, bool bRgbByteOrder)
FX_RECT GetOuterRect() const
CFX_FloatRect GetUnitRect() const
CFX_Matrix(const CFX_Matrix &other)=default
#define FXARGB_MUL_ALPHA(argb, alpha)
Definition fx_dib.h:200
int FXSYS_roundf(float f)
void Offset(int dx, int dy)
FX_RECT & operator=(const FX_RECT &that)=default
int Height() const
int Width() const
int32_t top
FX_RECT SwappedClipBox(int width, int height, bool bFlipX, bool bFlipY) const
int32_t left
void Intersect(const FX_RECT &src)
bool IsEmpty() const