1//========================================================================
2//
3// ImageOutputDev.h
4//
5// Copyright 1998-2003 Glyph & Cog, LLC
6//
7//========================================================================
8
9//========================================================================
10//
11// Modified under the Poppler project - http://poppler.freedesktop.org
12//
13// All changes made under the Poppler project to this file are licensed
14// under GPL version 2 or later
15//
16// Copyright (C) 2006 Rainer Keller <class321@gmx.de>
17// Copyright (C) 2008 Timothy Lee <timothy.lee@siriushk.com>
18// Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
19// Copyright (C) 2010 Jakob Voss <jakob.voss@gbv.de>
20// Copyright (C) 2012, 2013, 2017 Adrian Johnson <ajohnson@redneon.com>
21// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
22// Copyright (C) 2018, 2019, 2021, 2024 Albert Astals Cid <aacid@kde.org>
23// Copyright (C) 2024 Fernando Herrera <fherrera@onirica.com>
24// Copyright (C) 2024 Sebastian J. Bronner <waschtl@sbronner.com>
25//
26// To see a description of the changes please see the Changelog file that
27// came with your tarball or type make ChangeLog if you are building from git
28//
29//========================================================================
30
31#ifndef IMAGEOUTPUTDEV_H
32#define IMAGEOUTPUTDEV_H
33
34#include "poppler/poppler-config.h"
35
36#include <cstdio>
37#include "goo/ImgWriter.h"
38#include "OutputDev.h"
39
40class GfxState;
41
42//------------------------------------------------------------------------
43// ImageOutputDev
44//------------------------------------------------------------------------
45
46class ImageOutputDev : public OutputDev
47{
48public:
49 enum ImageType
50 {
51 imgImage,
52 imgStencil,
53 imgMask,
54 imgSmask
55 };
56 enum ImageFormat
57 {
58 imgRGB,
59 imgRGB48,
60 imgGray,
61 imgMonochrome,
62 imgCMYK
63 };
64
65 // Create an OutputDev which will write images to files named
66 // <fileRoot>-NNN.<type> or <fileRoot>-PPP-NNN.<type>, if
67 // <pageNames> is set. Normally, all images are written as PBM
68 // (.pbm) or PPM (.ppm) files unless PNG or Tiff output is enabled
69 // (PNG is used if both are enabled). If Jpeg is enabled, JPEG images
70 // are written as JPEG (.jpg) files.
71 ImageOutputDev(char *fileRootA, bool pageNamesA, bool listImagesA);
72
73 // Destructor.
74 ~ImageOutputDev() override;
75
76 // Use PNG format for output
77 void enablePNG(bool png) { outputPNG = png; }
78
79 // Use TIFF format for output
80 void enableTiff(bool tiff) { outputTiff = tiff; }
81
82 // Use Jpeg format for Jpeg files
83 void enableJpeg(bool jpeg) { dumpJPEG = jpeg; }
84
85 // Use Jpeg2000 format for Jpeg2000 files
86 void enableJpeg2000(bool jp2) { dumpJP2 = jp2; }
87
88 // Use JBIG2 format for JBIG2 files
89 void enableJBig2(bool jbig2) { dumpJBIG2 = jbig2; }
90
91 // Use CCITT format for CCITT files
92 void enableCCITT(bool ccitt) { dumpCCITT = ccitt; }
93
94 // Print filenames to stdout after writing
95 void enablePrintFilenames(bool filenames) { printFilenames = filenames; }
96
97 // Get the error code
98 // 0 = No error, 1 = Error opening a PDF file, 2 = Error opening an output file, 3 = Error related to PDF permissions, 99 = Other error.
99 int getErrorCode() const { return errorCode; }
100
101 // Check if file was successfully created.
102 virtual bool isOk() { return errorCode == 0; }
103
104 // Does this device use tilingPatternFill()? If this returns false,
105 // tiling pattern fills will be reduced to a series of other drawing
106 // operations.
107 bool useTilingPatternFill() override { return true; }
108
109 // Does this device use beginType3Char/endType3Char? Otherwise,
110 // text in Type 3 fonts will be drawn with drawChar/drawString.
111 bool interpretType3Chars() override { return false; }
112
113 // Does this device need non-text content?
114 bool needNonText() override { return true; }
115
116 // Start a page
117 void startPage(int pageNumA, GfxState *state, XRef *xref) override { pageNum = pageNumA; }
118
119 //---- get info about output device
120
121 // Does this device use upside-down coordinates?
122 // (Upside-down means (0,0) is the top left corner of the page.)
123 bool upsideDown() override { return true; }
124
125 // Does this device use drawChar() or drawString()?
126 bool useDrawChar() override { return false; }
127
128 //----- path painting
129 bool tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, GfxTilingPattern *tPat, const double *mat, int x0, int y0, int x1, int y1, double xStep, double yStep) override;
130
131 //----- image drawing
132 void drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, bool invert, bool interpolate, bool inlineImg) override;
133 void drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, const int *maskColors, bool inlineImg) override;
134 void drawMaskedImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, Stream *maskStr, int maskWidth, int maskHeight, bool maskInvert, bool maskInterpolate) override;
135 void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, Stream *maskStr, int maskWidth, int maskHeight, GfxImageColorMap *maskColorMap,
136 bool maskInterpolate) override;
137
138private:
139 // Sets the output filename with a given file extension
140 void setFilename(const char *fileExt);
141 void listImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, bool inlineImg, ImageType imageType);
142 void writeImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool inlineImg);
143 void writeRawImage(Stream *str, const char *ext);
144 void writeImageFile(ImgWriter *writer, ImageFormat format, const char *ext, Stream *str, int width, int height, GfxImageColorMap *colorMap);
145 long getInlineImageLength(Stream *str, int width, int height, GfxImageColorMap *colorMap);
146
147 char *fileRoot; // root of output file names
148 char *fileName; // buffer for output file names
149 bool listImages; // list images instead of dumping
150 bool dumpJPEG; // set to dump native JPEG files
151 bool dumpJP2; // set to dump native JPEG2000 files
152 bool dumpJBIG2; // set to dump native JBIG2 files
153 bool dumpCCITT; // set to dump native CCITT files
154 bool outputPNG; // set to output in PNG format
155 bool outputTiff; // set to output in TIFF format
156 bool pageNames; // set to include page number in file names
157 bool printFilenames; // set to print image filenames to stdout after writing
158 int pageNum; // current page number
159 int imgNum; // current image number
160 int errorCode; // code for any error creating the output files
161};
162
163#endif
164

source code of poppler/utils/ImageOutputDev.h