PoDoFo 1.0.0-dev
Loading...
Searching...
No Matches
PdfImage.h
1
7#ifndef PDF_IMAGE_H
8#define PDF_IMAGE_H
9
10#include "PdfXObject.h"
11
12#include "PdfColorSpace.h"
13
14#ifdef PODOFO_HAVE_JPEG_LIB
15struct jpeg_decompress_struct;
16#endif // PODOFO_HAVE_JPEG_LIB
17
18struct png_struct_def;
19struct png_info_def;
20
21namespace PoDoFo {
22
23class PdfDocument;
24class InputStream;
25
26enum class PdfImageOrientation : uint8_t
27{
28 Unknown = 0,
29 TopLeft,
30 TopRight,
31 BottomRight,
32 BottomLeft,
33 LeftTop,
34 RightTop,
35 RightBottom,
36 LeftBottom
37};
38
39struct PODOFO_API PdfImageInfo final
40{
41 unsigned Width = 0;
42 unsigned Height = 0;
43 nullable<PdfFilterList> Filters;
44 unsigned char BitsPerComponent = 0;
45 PdfColorSpaceInitializer ColorSpace;
46 std::vector<double> DecodeArray;
47 PdfImageOrientation Orientation = PdfImageOrientation::TopLeft;
48};
49
51{
52 None = 0,
53 SkipTransform = 1,
54};
55
56struct PODOFO_API PdfImageLoadParams final
57{
58 unsigned ImageIndex = 0;
59 PdfImageLoadFlags Flags = PdfImageLoadFlags::None;
60};
61
70class PODOFO_API PdfImage final : public PdfXObject
71{
72 friend class PdfXObject;
73 friend class PdfDocument;
74
75private:
82
83public:
84 void DecodeTo(charbuff& buff, PdfPixelFormat format, int scanLineSize = -1) const;
85 void DecodeTo(const bufferspan& buff, PdfPixelFormat format, int scanLineSize = -1) const;
86 void DecodeTo(OutputStream& stream, PdfPixelFormat format, int scanLineSize = -1) const;
87
88 charbuff GetDecodedCopy(PdfPixelFormat format);
89
93 bool TryFetchRawImageInfo(PdfImageInfo& info);
94
99 void SetSoftMask(const PdfImage& softmask);
100
110 void SetData(const bufferview& buffer, unsigned width, unsigned height,
111 PdfPixelFormat format, int rowSize = -1);
112
121 void SetData(InputStream& stream, unsigned width, unsigned height,
122 PdfPixelFormat format, int rowSize = -1);
123
129 void SetDataRaw(const bufferview& buffer, const PdfImageInfo& info);
130
136 void SetDataRaw(InputStream& stream, const PdfImageInfo& info);
137
143 PdfImageInfo Load(const std::string_view& filepath, const PdfImageLoadParams& params = { });
144
150 PdfImageInfo LoadFromBuffer(const bufferview& buffer, const PdfImageLoadParams& params = { });
151
152 void ExportTo(charbuff& buff, PdfExportFormat format, PdfArray args = {}) const;
153
162 void SetChromaKeyMask(int64_t r, int64_t g, int64_t b, int64_t threshold = 0);
163
170 void SetInterpolate(bool value);
171
172 Rect GetRect() const override;
173
177 const PdfColorSpaceFilter& GetColorSpace() const { return *m_ColorSpace; }
178
182 unsigned GetWidth() const { return m_Width; }
183
187 unsigned GetHeight() const { return m_Height; }
188
189protected:
190 const PdfXObjectForm* GetForm() const override;
191
192private:
198
199 void setDataRaw(InputStream& stream, const PdfImageInfo& info, PdfImageLoadFlags flags);
200
201#ifdef PODOFO_HAVE_JPEG_LIB
202 void loadFromJpegInfo(jpeg_decompress_struct& ctx, PdfImageInfo& info);
203 void exportToJpeg(charbuff& buff, const PdfArray& args) const;
207 void loadFromJpeg(const std::string_view& filename, PdfImageInfo& info);
208
213 void loadFromJpegData(const unsigned char* data, size_t len, PdfImageInfo& info);
214#endif // PODOFO_HAVE_JPEG_LIB
215
216#ifdef PODOFO_HAVE_TIFF_LIB
217 void loadFromTiffHandle(void* handle, const PdfImageLoadParams& params, charbuff& buffer, PdfImageInfo& info);
221 void loadFromTiff(const std::string_view& filename, const PdfImageLoadParams& params, charbuff& buffer, PdfImageInfo& info);
222
227 void loadFromTiffData(const unsigned char* data, size_t len, const PdfImageLoadParams& params, charbuff& buffer, PdfImageInfo& info);
228#endif // PODOFO_HAVE_TIFF_LIB
229
230#ifdef PODOFO_HAVE_PNG_LIB
231 void loadFromPngHandle(FILE* stream, charbuff& buffer, PdfImageInfo& info);
235 void loadFromPng(const std::string_view& filename, charbuff& buffer, PdfImageInfo& info);
236
241 void loadFromPngData(const unsigned char* data, size_t len, charbuff& buffer, PdfImageInfo& info);
242
244#endif // PODOFO_HAVE_PNG_LIB
245
246 unsigned getBufferSize(PdfPixelFormat format) const;
247
248 std::unique_ptr<PdfXObjectForm> getTransformation(PdfImageOrientation orientation);
249
250private:
251 PdfColorSpaceFilterPtr m_ColorSpace;
252 unsigned m_Width;
253 unsigned m_Height;
254 unsigned char m_BitsPerComponent;
255 std::unique_ptr<PdfXObjectForm> m_Transformation;
256};
257
258};
259
260ENABLE_BITMASK_OPERATORS(PoDoFo::PdfImageLoadFlags);
261
262#endif // PDF_IMAGE_H
An interface for reading blocks of data from a data source.
Definition InputStream.h:20
An interface for writing blocks of data to a data source.
Definition OutputStream.h:18
This class represents a PdfArray Use it for all arrays that are written to a PDF file.
Definition PdfArray.h:81
A class that implements methods to sample colors from a scanline buffer.
Definition PdfColorSpaceFilter.h:32
PdfDocument is the core interface for working with PDF documents.
Definition PdfDocument.h:111
A PdfImage object is needed when ever you want to embed an image file into a PDF document.
Definition PdfImage.h:71
unsigned GetWidth() const
Get the width of the image when drawn in PDF units.
Definition PdfImage.h:182
const PdfColorSpaceFilter & GetColorSpace() const
Get the color space of the image.
Definition PdfImage.h:177
unsigned GetHeight() const
Get the height of the image when drawn in PDF units.
Definition PdfImage.h:187
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:35
A XObject is a content stream with several drawing commands and data which can be used throughout a P...
Definition PdfXObject.h:31
An normalized rectangle defined by position (left-bottom) and size.
Definition Rect.h:20
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:38
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition basetypes.h:16
PdfPixelFormat
Definition PdfDeclarations.h:375
std::shared_ptr< const PdfColorSpaceFilter > PdfColorSpaceFilterPtr
Convenience alias for a constant PdfColorSpaceFilter shared ptr.
Definition PdfColorSpaceFilter.h:85
mspan< char > bufferspan
Convenient writable char buffer span.
Definition basetypes.h:23
@ None
Do not add a default appearrance.
PdfImageLoadFlags
Definition PdfImage.h:51
@ SkipTransform
Skip applying orientation transform.
PdfExportFormat
Definition PdfDeclarations.h:241
cspan< char > bufferview
Convenient read-only char buffer span.
Definition basetypes.h:19