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_imageobject.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/page/cpdf_imageobject.h"
8
9#include <utility>
10
11#include "core/fpdfapi/page/cpdf_docpagedata.h"
12#include "core/fpdfapi/page/cpdf_image.h"
13#include "core/fpdfapi/parser/cpdf_stream.h"
14#include "core/fxcrt/fx_coordinates.h"
15#include "core/fxge/dib/cfx_dibbase.h"
16#include "core/fxge/dib/cfx_dibitmap.h"
17
18CPDF_ImageObject::CPDF_ImageObject(int32_t content_stream)
19 : CPDF_PageObject(content_stream) {}
20
21CPDF_ImageObject::CPDF_ImageObject() : CPDF_ImageObject(kNoContentStream) {}
22
23CPDF_ImageObject::~CPDF_ImageObject() {
24 MaybePurgeCache();
25}
26
27CPDF_PageObject::Type CPDF_ImageObject::GetType() const {
28 return Type::kImage;
29}
30
31void CPDF_ImageObject::Transform(const CFX_Matrix& matrix) {
32 m_Matrix.Concat(matrix);
34 SetDirty(true);
35}
36
37bool CPDF_ImageObject::IsImage() const {
38 return true;
39}
40
41CPDF_ImageObject* CPDF_ImageObject::AsImage() {
42 return this;
43}
44
45const CPDF_ImageObject* CPDF_ImageObject::AsImage() const {
46 return this;
47}
48
49void CPDF_ImageObject::CalcBoundingBox() {
50 static constexpr CFX_FloatRect kRect(0.0f, 0.0f, 1.0f, 1.0f);
51 SetOriginalRect(kRect);
52 SetRect(m_Matrix.TransformRect(kRect));
53}
54
55void CPDF_ImageObject::SetImage(RetainPtr<CPDF_Image> pImage) {
56 MaybePurgeCache();
57 m_pImage = std::move(pImage);
58}
59
60RetainPtr<CPDF_Image> CPDF_ImageObject::GetImage() const {
61 return m_pImage;
62}
63
64RetainPtr<CFX_DIBitmap> CPDF_ImageObject::GetIndependentBitmap() const {
65 RetainPtr<CFX_DIBBase> pSource = GetImage()->LoadDIBBase();
66
67 // Realize() is non-virtual, and can't be overloaded by CPDF_DIB to
68 // return a full-up CPDF_DIB subclass. Instead, it only works upon the
69 // CFX_DIBBase, which is convenient since none of its members point to
70 // objects owned by |this| or the form containing |this|. As a result,
71 // the new bitmap may outlive them, giving the "independent" property
72 // this method is named after.
73 return pSource ? pSource->Realize() : nullptr;
74}
75
76void CPDF_ImageObject::SetImageMatrix(const CFX_Matrix& matrix) {
77 m_Matrix = matrix;
79}
80
81void CPDF_ImageObject::MaybePurgeCache() {
82 if (!m_pImage)
83 return;
84
85 RetainPtr<const CPDF_Stream> pStream = m_pImage->GetStream();
86 if (!pStream)
87 return;
88
89 uint32_t objnum = pStream->GetObjNum();
90 if (!objnum)
91 return;
92
93 auto* pDoc = m_pImage->GetDocument();
94 CHECK(pDoc);
95
96 m_pImage.Reset(); // Clear my reference before asking the cache.
97 pDoc->MaybePurgeImage(objnum);
98}
constexpr CFX_FloatRect(float l, float b, float r, float t)
CFX_Matrix & operator=(const CFX_Matrix &other)=default
CFX_FloatRect TransformRect(const CFX_FloatRect &rect) const
void Concat(const CFX_Matrix &right)
void Transform(const CFX_Matrix &matrix) override
bool IsImage() const override
CPDF_ImageObject * AsImage() override
const CPDF_ImageObject * AsImage() const override
RetainPtr< CPDF_Image > GetImage() const
CPDF_ImageObject(int32_t content_stream)
void SetImage(RetainPtr< CPDF_Image > pImage)
~CPDF_ImageObject() override
RetainPtr< CFX_DIBitmap > GetIndependentBitmap() const
Type GetType() const override
void SetImageMatrix(const CFX_Matrix &matrix)
void SetRect(const CFX_FloatRect &rect)
void SetDirty(bool value)
CPDF_PageObject(int32_t content_stream)
void SetOriginalRect(const CFX_FloatRect &rect)
static constexpr int32_t kNoContentStream
#define CHECK(cvref)