PoDoFo 1.2.0
Loading...
Searching...
No Matches
PdfImage.h
1// SPDX-FileCopyrightText: 2005 Dominik Seichter <domseichter@web.de>
2// SPDX-FileCopyrightText: 2020 Francesco Pretto <ceztko@gmail.com>
3// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0
4
5#ifndef PDF_IMAGE_H
6#define PDF_IMAGE_H
7
8#include "PdfXObject.h"
9
10#include "PdfColorSpace.h"
11
12#ifdef PODOFO_HAVE_JPEG_LIB
13struct jpeg_decompress_struct;
14#endif // PODOFO_HAVE_JPEG_LIB
15
16struct png_struct_def;
17struct png_info_def;
18
19namespace PoDoFo {
20
21class PdfDocument;
22class InputStream;
23
24enum class PdfImageOrientation : uint8_t
25{
26 Unknown = 0,
27 TopLeft,
28 TopRight,
29 BottomRight,
30 BottomLeft,
31 LeftTop,
32 RightTop,
33 RightBottom,
34 LeftBottom
35};
36
37struct PODOFO_API PdfImageInfo final
38{
39 unsigned Width = 0;
40 unsigned Height = 0;
41 nullable<PdfFilterList> Filters;
42 unsigned char BitsPerComponent = 0;
43 PdfColorSpaceInitializer ColorSpace;
44 std::vector<double> DecodeArray;
45 PdfImageOrientation Orientation = PdfImageOrientation::TopLeft;
46};
47
49{
50 None = 0,
51 SkipTransform = 1,
52};
53
54struct PODOFO_API PdfImageLoadParams final
55{
56 unsigned ImageIndex = 0;
57 PdfImageLoadFlags Flags = PdfImageLoadFlags::None;
58};
59
67class PODOFO_API PdfImage final : public PdfXObject
68{
69 friend class PdfXObject;
70 friend class PdfDocument;
71
72private:
78
79public:
80 void DecodeTo(charbuff& buff, PdfPixelFormat format, int scanLineSize = -1) const;
81 void DecodeTo(const bufferspan& buff, PdfPixelFormat format, int scanLineSize = -1) const;
82 void DecodeTo(OutputStream& stream, PdfPixelFormat format, int scanLineSize = -1) const;
83
84 charbuff GetDecodedCopy(PdfPixelFormat format);
85
88 bool TryFetchRawImageInfo(PdfImageInfo& info);
89
93 void SetSoftMask(const PdfImage& softmask);
94
103 void SetData(const bufferview& buffer, unsigned width, unsigned height,
104 PdfPixelFormat format, int rowSize = -1);
105
113 void SetData(InputStream& stream, unsigned width, unsigned height,
114 PdfPixelFormat format, int rowSize = -1);
115
120 void SetDataRaw(const bufferview& buffer, const PdfImageInfo& info);
121
126 void SetDataRaw(InputStream& stream, const PdfImageInfo& info);
127
133 PdfImageInfo Load(const std::string_view& filepath, const PdfImageLoadParams& params = { });
134
140 PdfImageInfo LoadFromBuffer(const bufferview& buffer, const PdfImageLoadParams& params = { });
141
142 void ExportTo(charbuff& buff, PdfExportFormat format, PdfArray args = {}) const;
143
151 void SetChromaKeyMask(int64_t r, int64_t g, int64_t b, int64_t threshold = 0);
152
157 void SetInterpolate(bool value);
158
159 Rect GetRect() const override;
160
163 const PdfColorSpaceFilter& GetColorSpace() const { return *m_ColorSpace; }
164
167 unsigned GetWidth() const { return m_Width; }
168
171 unsigned GetHeight() const { return m_Height; }
172
173protected:
174 const PdfXObjectForm* GetForm() const override;
175
176private:
181
182 void setDataRaw(InputStream& stream, const PdfImageInfo& info, PdfImageLoadFlags flags);
183
184#ifdef PODOFO_HAVE_JPEG_LIB
185 void loadFromJpegInfo(jpeg_decompress_struct& ctx, PdfImageInfo& info);
186 void exportToJpeg(charbuff& buff, const PdfArray& args) const;
189 void loadFromJpeg(const std::string_view& filename, PdfImageInfo& info);
190
194 void loadFromJpegData(const unsigned char* data, size_t len, PdfImageInfo& info);
195#endif // PODOFO_HAVE_JPEG_LIB
196
197#ifdef PODOFO_HAVE_TIFF_LIB
198 void loadFromTiffHandle(void* handle, const PdfImageLoadParams& params, charbuff& buffer, PdfImageInfo& info);
201 void loadFromTiff(const std::string_view& filename, const PdfImageLoadParams& params, charbuff& buffer, PdfImageInfo& info);
202
206 void loadFromTiffData(const unsigned char* data, size_t len, const PdfImageLoadParams& params, charbuff& buffer, PdfImageInfo& info);
207#endif // PODOFO_HAVE_TIFF_LIB
208
209#ifdef PODOFO_HAVE_PNG_LIB
210 void loadFromPngHandle(FILE* stream, charbuff& buffer, PdfImageInfo& info);
213 void loadFromPng(const std::string_view& filename, charbuff& buffer, PdfImageInfo& info);
214
218 void loadFromPngData(const unsigned char* data, size_t len, charbuff& buffer, PdfImageInfo& info);
219
221#endif // PODOFO_HAVE_PNG_LIB
222
223 unsigned getBufferSize(PdfPixelFormat format) const;
224
225 std::unique_ptr<PdfXObjectForm> getTransformation(PdfImageOrientation orientation);
226
227private:
228 PdfColorSpaceFilterPtr m_ColorSpace;
229 unsigned m_Width;
230 unsigned m_Height;
231 unsigned char m_BitsPerComponent;
232 std::unique_ptr<PdfXObjectForm> m_Transformation;
233};
234
235};
236
237ENABLE_BITMASK_OPERATORS(PoDoFo::PdfImageLoadFlags);
238
239#endif // PDF_IMAGE_H
An interface for reading blocks of data from a data source.
Definition InputStream.h:17
An interface for writing blocks of data to a data source.
Definition OutputStream.h:15
This class represents a PdfArray Use it for all arrays that are written to a PDF file.
Definition PdfArray.h:76
A class that implements methods to sample colors from a scanline buffer.
Definition PdfColorSpaceFilter.h:27
PdfDocument is the core interface for working with PDF documents.
Definition PdfDocument.h:108
A PdfImage object is needed when ever you want to embed an image file into a PDF document.
Definition PdfImage.h:68
unsigned GetWidth() const
Get the width of the image when drawn in PDF units.
Definition PdfImage.h:167
const PdfColorSpaceFilter & GetColorSpace() const
Get the color space of the image.
Definition PdfImage.h:163
unsigned GetHeight() const
Get the height of the image when drawn in PDF units.
Definition PdfImage.h:171
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:31
A XObject is a content stream with several drawing commands and data which can be used throughout a P...
Definition PdfXObject.h:28
An normalized rectangle defined by position (left-bottom) and size.
Definition Rect.h:17
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:30
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13
PdfPixelFormat
Definition PdfDeclarations.h:349
std::shared_ptr< const PdfColorSpaceFilter > PdfColorSpaceFilterPtr
Convenience alias for a constant PdfColorSpaceFilter shared ptr.
Definition PdfColorSpaceFilter.h:71
mspan< char > bufferspan
Convenient writable char buffer span.
Definition basetypes.h:18
@ None
Do not add a default appearance.
PdfImageLoadFlags
Definition PdfImage.h:49
@ SkipTransform
Skip applying orientation transform.
PdfExportFormat
Definition PdfDeclarations.h:224
cspan< char > bufferview
Convenient read-only char buffer span.
Definition basetypes.h:15