1 | //======================================================================== |
2 | // |
3 | // Splash.h |
4 | // |
5 | //======================================================================== |
6 | |
7 | //======================================================================== |
8 | // |
9 | // Modified under the Poppler project - http://poppler.freedesktop.org |
10 | // |
11 | // All changes made under the Poppler project to this file are licensed |
12 | // under GPL version 2 or later |
13 | // |
14 | // Copyright (C) 2005 Marco Pesenti Gritti <mpg@redhat.com> |
15 | // Copyright (C) 2007, 2011, 2018, 2019, 2021, 2022 Albert Astals Cid <aacid@kde.org> |
16 | // Copyright (C) 2010-2013, 2015 Thomas Freitag <Thomas.Freitag@alfa.de> |
17 | // Copyright (C) 2010 Christian Feuersänger <cfeuersaenger@googlemail.com> |
18 | // Copyright (C) 2012, 2017 Adrian Johnson <ajohnson@redneon.com> |
19 | // Copyright (C) 2020 Oliver Sander <oliver.sander@tu-dresden.de> |
20 | // Copyright (C) 2020 Tobias Deiminger <haxtibal@posteo.de> |
21 | // |
22 | // To see a description of the changes please see the Changelog file that |
23 | // came with your tarball or type make ChangeLog if you are building from git |
24 | // |
25 | //======================================================================== |
26 | |
27 | #ifndef SPLASH_H |
28 | #define SPLASH_H |
29 | |
30 | #include <cstddef> |
31 | #include "SplashTypes.h" |
32 | #include "SplashClip.h" |
33 | #include "SplashPattern.h" |
34 | #include "poppler_private_export.h" |
35 | |
36 | class SplashBitmap; |
37 | struct SplashGlyphBitmap; |
38 | class SplashState; |
39 | class SplashScreen; |
40 | class SplashPath; |
41 | class SplashXPath; |
42 | class SplashFont; |
43 | struct SplashPipe; |
44 | |
45 | //------------------------------------------------------------------------ |
46 | |
47 | // Retrieves the next line of pixels in an image mask. Normally, |
48 | // fills in *<line> and returns true. If the image stream is |
49 | // exhausted, returns false. |
50 | typedef bool (*SplashImageMaskSource)(void *data, SplashColorPtr pixel); |
51 | |
52 | // Retrieves the next line of pixels in an image. Normally, fills in |
53 | // *<line> and returns true. If the image stream is exhausted, |
54 | // returns false. |
55 | typedef bool (*SplashImageSource)(void *data, SplashColorPtr colorLine, unsigned char *alphaLine); |
56 | |
57 | // Use ICCColorSpace to transform a bitmap |
58 | typedef void (*SplashICCTransform)(void *data, SplashBitmap *bitmap); |
59 | |
60 | //------------------------------------------------------------------------ |
61 | |
62 | enum SplashPipeResultColorCtrl |
63 | { |
64 | splashPipeResultColorNoAlphaBlendCMYK, |
65 | splashPipeResultColorNoAlphaBlendDeviceN, |
66 | splashPipeResultColorNoAlphaBlendRGB, |
67 | splashPipeResultColorNoAlphaBlendMono, |
68 | splashPipeResultColorAlphaNoBlendMono, |
69 | splashPipeResultColorAlphaNoBlendRGB, |
70 | splashPipeResultColorAlphaNoBlendCMYK, |
71 | splashPipeResultColorAlphaNoBlendDeviceN, |
72 | splashPipeResultColorAlphaBlendMono, |
73 | splashPipeResultColorAlphaBlendRGB, |
74 | splashPipeResultColorAlphaBlendCMYK, |
75 | splashPipeResultColorAlphaBlendDeviceN |
76 | }; |
77 | |
78 | //------------------------------------------------------------------------ |
79 | // Splash |
80 | //------------------------------------------------------------------------ |
81 | |
82 | class POPPLER_PRIVATE_EXPORT Splash |
83 | { |
84 | public: |
85 | // Create a new rasterizer object. |
86 | Splash(SplashBitmap *bitmapA, bool vectorAntialiasA, SplashScreenParams *screenParams = nullptr); |
87 | Splash(SplashBitmap *bitmapA, bool vectorAntialiasA, SplashScreen *screenA); |
88 | |
89 | ~Splash(); |
90 | |
91 | Splash(const Splash &) = delete; |
92 | Splash &operator=(const Splash &) = delete; |
93 | |
94 | //----- state read |
95 | |
96 | SplashCoord *getMatrix(); |
97 | SplashPattern *getStrokePattern(); |
98 | SplashPattern *getFillPattern(); |
99 | SplashScreen *getScreen(); |
100 | SplashBlendFunc getBlendFunc(); |
101 | SplashCoord getStrokeAlpha(); |
102 | SplashCoord getFillAlpha(); |
103 | SplashCoord getLineWidth(); |
104 | int getLineCap(); |
105 | int getLineJoin(); |
106 | SplashCoord getMiterLimit(); |
107 | SplashCoord getFlatness(); |
108 | SplashCoord getLineDashPhase(); |
109 | bool getStrokeAdjust(); |
110 | SplashClip *getClip(); |
111 | SplashBitmap *getSoftMask(); |
112 | bool getInNonIsolatedGroup(); |
113 | |
114 | //----- state write |
115 | |
116 | void setMatrix(SplashCoord *matrix); |
117 | void setStrokePattern(SplashPattern *strokePattern); |
118 | void setFillPattern(SplashPattern *fillPattern); |
119 | void setScreen(SplashScreen *screen); |
120 | void setBlendFunc(SplashBlendFunc func); |
121 | void setStrokeAlpha(SplashCoord alpha); |
122 | void setFillAlpha(SplashCoord alpha); |
123 | void setPatternAlpha(SplashCoord strokeAlpha, SplashCoord fillAlpha); |
124 | void clearPatternAlpha(); |
125 | void setFillOverprint(bool fop); |
126 | void setStrokeOverprint(bool sop); |
127 | void setOverprintMode(int opm); |
128 | void setLineWidth(SplashCoord lineWidth); |
129 | void setLineCap(int lineCap); |
130 | void setLineJoin(int lineJoin); |
131 | void setMiterLimit(SplashCoord miterLimit); |
132 | void setFlatness(SplashCoord flatness); |
133 | // the <lineDash> array will be copied |
134 | void setLineDash(std::vector<SplashCoord> &&lineDash, SplashCoord lineDashPhase); |
135 | void setStrokeAdjust(bool strokeAdjust); |
136 | // NB: uses transformed coordinates. |
137 | void clipResetToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1); |
138 | // NB: uses transformed coordinates. |
139 | SplashError clipToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1); |
140 | // NB: uses untransformed coordinates. |
141 | SplashError clipToPath(SplashPath *path, bool eo); |
142 | void setSoftMask(SplashBitmap *softMask); |
143 | void setInNonIsolatedGroup(SplashBitmap *alpha0BitmapA, int alpha0XA, int alpha0YA); |
144 | void setTransfer(unsigned char *red, unsigned char *green, unsigned char *blue, unsigned char *gray); |
145 | void setOverprintMask(unsigned int overprintMask, bool additive); |
146 | |
147 | //----- state save/restore |
148 | |
149 | void saveState(); |
150 | SplashError restoreState(); |
151 | |
152 | //----- drawing operations |
153 | |
154 | // Fill the bitmap with <color>. This is not subject to clipping. |
155 | void clear(SplashColorPtr color, unsigned char alpha = 0x00); |
156 | |
157 | // Stroke a path using the current stroke pattern. |
158 | SplashError stroke(SplashPath *path); |
159 | |
160 | // Fill a path using the current fill pattern. |
161 | SplashError fill(SplashPath *path, bool eo); |
162 | |
163 | // Fill a path, XORing with the current fill pattern. |
164 | SplashError xorFill(SplashPath *path, bool eo); |
165 | |
166 | // Draw a character, using the current fill pattern. |
167 | SplashError fillChar(SplashCoord x, SplashCoord y, int c, SplashFont *font); |
168 | |
169 | // Draw a glyph, using the current fill pattern. This function does |
170 | // not free any data, i.e., it ignores glyph->freeData. |
171 | void fillGlyph(SplashCoord x, SplashCoord y, SplashGlyphBitmap *glyph); |
172 | |
173 | // Draws an image mask using the fill color. This will read <h> |
174 | // lines of <w> pixels from <src>, starting with the top line. "1" |
175 | // pixels will be drawn with the current fill color; "0" pixels are |
176 | // transparent. The matrix: |
177 | // [ mat[0] mat[1] 0 ] |
178 | // [ mat[2] mat[3] 0 ] |
179 | // [ mat[4] mat[5] 1 ] |
180 | // maps a unit square to the desired destination for the image, in |
181 | // PostScript style: |
182 | // [x' y' 1] = [x y 1] * mat |
183 | // Note that the Splash y axis points downward, and the image source |
184 | // is assumed to produce pixels in raster order, starting from the |
185 | // top line. |
186 | SplashError fillImageMask(SplashImageMaskSource src, void *srcData, int w, int h, SplashCoord *mat, bool glyphMode); |
187 | |
188 | // Draw an image. This will read <h> lines of <w> pixels from |
189 | // <src>, starting with the top line. These pixels are assumed to |
190 | // be in the source mode, <srcMode>. If <srcAlpha> is true, the |
191 | // alpha values returned by <src> are used; otherwise they are |
192 | // ignored. The following combinations of source and target modes |
193 | // are supported: |
194 | // source target |
195 | // ------ ------ |
196 | // Mono1 Mono1 |
197 | // Mono8 Mono1 -- with dithering |
198 | // Mono8 Mono8 |
199 | // RGB8 RGB8 |
200 | // BGR8 BGR8 |
201 | // CMYK8 CMYK8 |
202 | // The matrix behaves as for fillImageMask. |
203 | SplashError drawImage(SplashImageSource src, SplashICCTransform tf, void *srcData, SplashColorMode srcMode, bool srcAlpha, int w, int h, SplashCoord *mat, bool interpolate, bool tilingPattern = false); |
204 | |
205 | // Composite a rectangular region from <src> onto this Splash |
206 | // object. |
207 | SplashError composite(SplashBitmap *src, int xSrc, int ySrc, int xDest, int yDest, int w, int h, bool noClip, bool nonIsolated, bool knockout = false, SplashCoord knockoutOpacity = 1.0); |
208 | |
209 | // Composite this Splash object onto a background color. The |
210 | // background alpha is assumed to be 1. |
211 | void compositeBackground(SplashColorConstPtr color); |
212 | |
213 | // Copy a rectangular region from <src> onto the bitmap belonging to |
214 | // this Splash object. The destination alpha values are all set to |
215 | // zero. |
216 | SplashError blitTransparent(SplashBitmap *src, int xSrc, int ySrc, int xDest, int yDest, int w, int h); |
217 | void blitImage(SplashBitmap *src, bool srcAlpha, int xDest, int yDest); |
218 | |
219 | //----- misc |
220 | |
221 | // Construct a path for a stroke, given the path to be stroked and |
222 | // the line width <w>. All other stroke parameters are taken from |
223 | // the current state. If <flatten> is true, this function will |
224 | // first flatten the path and handle the linedash. |
225 | SplashPath *makeStrokePath(SplashPath *path, SplashCoord w, bool flatten = true); |
226 | |
227 | // Return the associated bitmap. |
228 | SplashBitmap *getBitmap() { return bitmap; } |
229 | |
230 | // Set the minimum line width. |
231 | void setMinLineWidth(SplashCoord w) { minLineWidth = w; } |
232 | |
233 | // Setter/Getter for thin line mode |
234 | void setThinLineMode(SplashThinLineMode thinLineModeA) { thinLineMode = thinLineModeA; } |
235 | SplashThinLineMode getThinLineMode() { return thinLineMode; } |
236 | |
237 | // Get clipping status for the last drawing operation subject to |
238 | // clipping. |
239 | SplashClipResult getClipRes() { return opClipRes; } |
240 | |
241 | // Toggle debug mode on or off. |
242 | void setDebugMode(bool debugModeA) { debugMode = debugModeA; } |
243 | |
244 | #if 1 //~tmp: turn off anti-aliasing temporarily |
245 | void setInShading(bool sh) { inShading = sh; } |
246 | bool getVectorAntialias() { return vectorAntialias; } |
247 | void setVectorAntialias(bool vaa) { vectorAntialias = vaa; } |
248 | #endif |
249 | |
250 | // Do shaded fills with dynamic patterns |
251 | // |
252 | // clipToStrokePath: Whether the current clip region is a stroke path. |
253 | // In that case, strokeAlpha is used rather than fillAlpha. |
254 | SplashError shadedFill(SplashPath *path, bool hasBBox, SplashPattern *pattern, bool clipToStrokePath); |
255 | // Draw a gouraud triangle shading. |
256 | bool gouraudTriangleShadedFill(SplashGouraudColor *shading); |
257 | |
258 | private: |
259 | void pipeInit(SplashPipe *pipe, int x, int y, SplashPattern *pattern, SplashColorPtr cSrc, unsigned char aInput, bool usesShape, bool nonIsolatedGroup, bool knockout = false, unsigned char knockoutOpacity = 255); |
260 | void pipeRun(SplashPipe *pipe); |
261 | void pipeRunSimpleMono1(SplashPipe *pipe); |
262 | void pipeRunSimpleMono8(SplashPipe *pipe); |
263 | void pipeRunSimpleRGB8(SplashPipe *pipe); |
264 | void pipeRunSimpleXBGR8(SplashPipe *pipe); |
265 | void pipeRunSimpleBGR8(SplashPipe *pipe); |
266 | void pipeRunSimpleCMYK8(SplashPipe *pipe); |
267 | void pipeRunSimpleDeviceN8(SplashPipe *pipe); |
268 | void pipeRunAAMono1(SplashPipe *pipe); |
269 | void pipeRunAAMono8(SplashPipe *pipe); |
270 | void pipeRunAARGB8(SplashPipe *pipe); |
271 | void pipeRunAAXBGR8(SplashPipe *pipe); |
272 | void pipeRunAABGR8(SplashPipe *pipe); |
273 | void pipeRunAACMYK8(SplashPipe *pipe); |
274 | void pipeRunAADeviceN8(SplashPipe *pipe); |
275 | void pipeSetXY(SplashPipe *pipe, int x, int y); |
276 | void pipeIncX(SplashPipe *pipe); |
277 | void drawPixel(SplashPipe *pipe, int x, int y, bool noClip); |
278 | void drawAAPixelInit(); |
279 | void drawAAPixel(SplashPipe *pipe, int x, int y); |
280 | void drawSpan(SplashPipe *pipe, int x0, int x1, int y, bool noClip); |
281 | void drawAALine(SplashPipe *pipe, int x0, int x1, int y, bool adjustLine = false, unsigned char lineOpacity = 0); |
282 | void transform(const SplashCoord *matrix, SplashCoord xi, SplashCoord yi, SplashCoord *xo, SplashCoord *yo); |
283 | void strokeNarrow(SplashPath *path); |
284 | void strokeWide(SplashPath *path, SplashCoord w); |
285 | SplashPath *flattenPath(SplashPath *path, SplashCoord *matrix, SplashCoord flatness); |
286 | void flattenCurve(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1, SplashCoord x2, SplashCoord y2, SplashCoord x3, SplashCoord y3, SplashCoord *matrix, SplashCoord flatness2, SplashPath *fPath); |
287 | SplashPath *makeDashedPath(SplashPath *xPath); |
288 | void getBBoxFP(SplashPath *path, SplashCoord *xMinA, SplashCoord *yMinA, SplashCoord *xMaxA, SplashCoord *yMaxA); |
289 | SplashError fillWithPattern(SplashPath *path, bool eo, SplashPattern *pattern, SplashCoord alpha); |
290 | bool pathAllOutside(SplashPath *path); |
291 | void fillGlyph2(int x0, int y0, SplashGlyphBitmap *glyph, bool noclip); |
292 | void arbitraryTransformMask(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, SplashCoord *mat, bool glyphMode); |
293 | SplashBitmap *scaleMask(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight); |
294 | void scaleMaskYdownXdown(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest); |
295 | void scaleMaskYdownXup(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest); |
296 | void scaleMaskYupXdown(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest); |
297 | void scaleMaskYupXup(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest); |
298 | void blitMask(SplashBitmap *src, int xDest, int yDest, SplashClipResult clipRes); |
299 | SplashError arbitraryTransformImage(SplashImageSource src, SplashICCTransform tf, void *srcData, SplashColorMode srcMode, int nComps, bool srcAlpha, int srcWidth, int srcHeight, SplashCoord *mat, bool interpolate, |
300 | bool tilingPattern = false); |
301 | SplashBitmap *scaleImage(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, bool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, bool interpolate, bool tilingPattern = false); |
302 | bool scaleImageYdownXdown(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, bool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest); |
303 | bool scaleImageYdownXup(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, bool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest); |
304 | bool scaleImageYupXdown(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, bool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest); |
305 | bool scaleImageYupXup(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, bool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest); |
306 | bool scaleImageYupXupBilinear(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, bool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest); |
307 | void vertFlipImage(SplashBitmap *img, int width, int height, int nComps); |
308 | void blitImage(SplashBitmap *src, bool srcAlpha, int xDest, int yDest, SplashClipResult clipRes); |
309 | void blitImageClipped(SplashBitmap *src, bool srcAlpha, int xSrc, int ySrc, int xDest, int yDest, int w, int h); |
310 | void dumpPath(SplashPath *path); |
311 | void dumpXPath(SplashXPath *path); |
312 | |
313 | static SplashPipeResultColorCtrl pipeResultColorNoAlphaBlend[]; |
314 | static SplashPipeResultColorCtrl pipeResultColorAlphaNoBlend[]; |
315 | static SplashPipeResultColorCtrl pipeResultColorAlphaBlend[]; |
316 | static int pipeNonIsoGroupCorrection[]; |
317 | |
318 | SplashBitmap *bitmap; |
319 | SplashState *state; |
320 | SplashBitmap *aaBuf; |
321 | int aaBufY; |
322 | SplashBitmap *alpha0Bitmap; // for non-isolated groups, this is the |
323 | // bitmap containing the alpha0 values |
324 | int alpha0X, alpha0Y; // offset within alpha0Bitmap |
325 | SplashCoord aaGamma[splashAASize * splashAASize + 1]; |
326 | SplashCoord minLineWidth; |
327 | SplashThinLineMode thinLineMode; |
328 | SplashClipResult opClipRes; |
329 | bool vectorAntialias; |
330 | bool inShading; |
331 | bool debugMode; |
332 | }; |
333 | |
334 | #endif |
335 | |