PoDoFo  1.0.0-dev
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
15 struct jpeg_decompress_struct;
16 #endif // PODOFO_HAVE_JPEG_LIB
17 
18 namespace PoDoFo {
19 
20 class PdfDocument;
21 class InputStream;
22 
23 struct PODOFO_API PdfImageInfo final
24 {
25  PODOFO_STACK_ONLY
26 
27  unsigned Width = 0;
28  unsigned Height = 0;
29  nullable<PdfFilterList> Filters;
30  unsigned char BitsPerComponent = 0;
31  PdfColorSpaceInitializer ColorSpace;
32  std::vector<double> DecodeArray;
33 };
34 
43 class PODOFO_API PdfImage final : public PdfXObject
44 {
45  friend class PdfXObject;
46  friend class PdfDocument;
47 
48 private:
54  PdfImage(PdfDocument& doc);
55 
56 public:
57  void DecodeTo(charbuff& buff, PdfPixelFormat format, int scanLineSize = -1) const;
58  void DecodeTo(const bufferspan& buff, PdfPixelFormat format, int scanLineSize = -1) const;
59  void DecodeTo(OutputStream& stream, PdfPixelFormat format, int scanLineSize = -1) const;
60 
61  charbuff GetDecodedCopy(PdfPixelFormat format);
62 
67  void SetSoftMask(const PdfImage& softmask);
68 
78  void SetData(const bufferview& buffer, unsigned width, unsigned height,
79  PdfPixelFormat format, int rowSize = -1);
80 
89  void SetData(InputStream& stream, unsigned width, unsigned height,
90  PdfPixelFormat format, int rowSize = -1);
91 
97  void SetDataRaw(const bufferview& buffer, const PdfImageInfo& info);
98 
104  void SetDataRaw(InputStream& stream, const PdfImageInfo& info);
105 
110  void Load(const std::string_view& filepath, unsigned imageIndex = 0);
111 
116  void LoadFromBuffer(const bufferview& buffer, unsigned imageIndex = 0);
117 
118  void ExportTo(charbuff& buff, PdfExportFormat format, PdfArray args = {}) const;
119 
128  void SetChromaKeyMask(int64_t r, int64_t g, int64_t b, int64_t threshold = 0);
129 
136  void SetInterpolate(bool value);
137 
138  Rect GetRect() const override;
139 
143  const PdfColorSpaceFilter& GetColorSpace() const { return *m_ColorSpace; }
144 
148  unsigned GetWidth() const { return m_Width; }
149 
153  unsigned GetHeight() const { return m_Height; }
154 
155 private:
160  PdfImage(PdfObject& obj);
161 
162  unsigned getBufferSize(PdfPixelFormat format) const;
163 
164 #ifdef PODOFO_HAVE_JPEG_LIB
165  void loadFromJpegInfo(jpeg_decompress_struct& ctx, PdfImageInfo& info);
166  void exportToJpeg(charbuff& buff, const PdfArray& args) const;
170  void loadFromJpeg(const std::string_view& filename);
171 
176  void loadFromJpegData(const unsigned char* data, size_t len);
177 #endif // PODOFO_HAVE_JPEG_LIB
178 
179 #ifdef PODOFO_HAVE_TIFF_LIB
180  void loadFromTiffHandle(void* handle, unsigned imageIndex);
184  void loadFromTiff(const std::string_view& filename, unsigned imageIndex);
185 
190  void loadFromTiffData(const unsigned char* data, size_t len, unsigned imageIndex);
191 #endif // PODOFO_HAVE_TIFF_LIB
192 
193 #ifdef PODOFO_HAVE_PNG_LIB
194  void loadFromPngHandle(FILE* stream);
198  void loadFromPng(const std::string_view& filename);
199 
204  void loadFromPngData(const unsigned char* data, size_t len);
205 #endif // PODOFO_HAVE_PNG_LIB
206 
207 private:
208  PdfColorSpaceFilterPtr m_ColorSpace;
209  unsigned m_Width;
210  unsigned m_Height;
211  unsigned m_BitsPerComponent;
212 };
213 
214 };
215 
216 #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:31
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:44
const PdfColorSpaceFilter & GetColorSpace() const
Get the color space of the image.
Definition: PdfImage.h:143
unsigned GetWidth() const
Get the width of the image when drawn in PDF units.
Definition: PdfImage.h:148
unsigned GetHeight() const
Get the height of the image when drawn in PDF units.
Definition: PdfImage.h:153
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:30
A rectangle defined by position 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
@ Width
The glyph is accessed in the widths arrays (/Widths, /W1 keys)
std::shared_ptr< const PdfColorSpaceFilter > PdfColorSpaceFilterPtr
Convenience alias for a constant PdfColorSpaceFilter shared ptr.
Definition: PdfColorSpaceFilter.h:77
PdfExportFormat
Definition: PdfDeclarations.h:212
mspan< char > bufferspan
Convenient writable char buffer span.
Definition: basetypes.h:23
cspan< char > bufferview
Convenient read-only char buffer span.
Definition: basetypes.h:19
PdfPixelFormat
Definition: PdfDeclarations.h:346