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
52struct PODOFO_API PdfImageMetadata final
53{
54 PdfImageOrientation Orientation = PdfImageOrientation::Unknown;
55};
56
58{
59 None = 0,
60 SkipTransform = 1,
61};
62
63struct PODOFO_API PdfImageLoadParams final
64{
65 unsigned ImageIndex = 0;
66 PdfImageLoadFlags Flags = PdfImageLoadFlags::None;
67};
68
77class PODOFO_API PdfImage final : public PdfXObject
78{
79 friend class PdfXObject;
80 friend class PdfDocument;
81
82private:
89
90public:
91 void DecodeTo(charbuff& buff, PdfPixelFormat format, int scanLineSize = -1) const;
92 void DecodeTo(const bufferspan& buff, PdfPixelFormat format, int scanLineSize = -1) const;
93 void DecodeTo(OutputStream& stream, PdfPixelFormat format, int scanLineSize = -1) const;
94
95 charbuff GetDecodedCopy(PdfPixelFormat format);
96
101 void SetSoftMask(const PdfImage& softmask);
102
112 void SetData(const bufferview& buffer, unsigned width, unsigned height,
113 PdfPixelFormat format, int rowSize = -1);
114
123 void SetData(InputStream& stream, unsigned width, unsigned height,
124 PdfPixelFormat format, int rowSize = -1);
125
131 void SetDataRaw(const bufferview& buffer, const PdfImageInfo& info);
132
138 void SetDataRaw(InputStream& stream, const PdfImageInfo& info);
139
145 PdfImageMetadata Load(const std::string_view& filepath, const PdfImageLoadParams& params = { });
146
152 PdfImageMetadata LoadFromBuffer(const bufferview& buffer, const PdfImageLoadParams& params = { });
153
154 void ExportTo(charbuff& buff, PdfExportFormat format, PdfArray args = {}) const;
155
164 void SetChromaKeyMask(int64_t r, int64_t g, int64_t b, int64_t threshold = 0);
165
172 void SetInterpolate(bool value);
173
174 Rect GetRect() const override;
175
179 const PdfColorSpaceFilter& GetColorSpace() const { return *m_ColorSpace; }
180
184 unsigned GetWidth() const { return m_Width; }
185
189 unsigned GetHeight() const { return m_Height; }
190
191protected:
192 const PdfXObjectForm* GetForm() const override;
193
194private:
200
201 unsigned getBufferSize(PdfPixelFormat format) const;
202
203#ifdef PODOFO_HAVE_JPEG_LIB
204 void loadFromJpegInfo(jpeg_decompress_struct& ctx, PdfImageInfo& info);
205 void exportToJpeg(charbuff& buff, const PdfArray& args) const;
209 void loadFromJpeg(const std::string_view& filename);
210
215 void loadFromJpegData(const unsigned char* data, size_t len);
216#endif // PODOFO_HAVE_JPEG_LIB
217
218#ifdef PODOFO_HAVE_TIFF_LIB
219 void loadFromTiffHandle(void* handle, const PdfImageLoadParams& params, PdfImageMetadata& metadata);
223 void loadFromTiff(const std::string_view& filename, const PdfImageLoadParams& params, PdfImageMetadata& metadata);
224
229 void loadFromTiffData(const unsigned char* data, size_t len, const PdfImageLoadParams& params, PdfImageMetadata& metadata);
230#endif // PODOFO_HAVE_TIFF_LIB
231
232#ifdef PODOFO_HAVE_PNG_LIB
237 void loadFromPng(const std::string_view& filename);
238
243 void loadFromPngData(const unsigned char* data, size_t len);
244
246#endif // PODOFO_HAVE_PNG_LIB
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 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:78
unsigned GetWidth() const
Get the width of the image when drawn in PDF units.
Definition PdfImage.h:184
const PdfColorSpaceFilter & GetColorSpace() const
Get the color space of the image.
Definition PdfImage.h:179
unsigned GetHeight() const
Get the height of the image when drawn in PDF units.
Definition PdfImage.h:189
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:58
@ SkipTransform
Skip applying orientation transform.
PdfExportFormat
Definition PdfDeclarations.h:241
cspan< char > bufferview
Convenient read-only char buffer span.
Definition basetypes.h:19
Non PDF specific image metadata descriptors fetched from image codecs.
Definition PdfImage.h:53