1 //========================================================================
5 //========================================================================
7 //========================================================================
9 // Modified under the Poppler project - http://poppler.freedesktop.org
11 // All changes made under the Poppler project to this file are licensed
12 // under GPL version 2 or later
14 // Copyright (C) 2005 Marco Pesenti Gritti <mpg@redhat.com>
15 // Copyright (C) 2007, 2011 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 Adrian Johnson <ajohnson@redneon.com>
20 // To see a description of the changes please see the Changelog file that
21 // came with your tarball or type make ChangeLog if you are building from git
23 //========================================================================
28 #ifdef USE_GCC_PRAGMAS
33 #include "SplashTypes.h"
34 #include "SplashClip.h"
35 #include "SplashPattern.h"
38 struct SplashGlyphBitmap
;
46 //------------------------------------------------------------------------
48 // Retrieves the next line of pixels in an image mask. Normally,
49 // fills in *<line> and returns true. If the image stream is
50 // exhausted, returns false.
51 typedef GBool (*SplashImageMaskSource
)(void *data
, SplashColorPtr pixel
);
53 // Retrieves the next line of pixels in an image. Normally, fills in
54 // *<line> and returns true. If the image stream is exhausted,
56 typedef GBool (*SplashImageSource
)(void *data
, SplashColorPtr colorLine
,
59 // Use ICCColorSpace to transform a bitmap
60 typedef void (*SplashICCTransform
)(void *data
, SplashBitmap
*bitmap
);
62 //------------------------------------------------------------------------
64 enum SplashPipeResultColorCtrl
{
66 splashPipeResultColorNoAlphaBlendCMYK
,
67 splashPipeResultColorNoAlphaBlendDeviceN
,
69 splashPipeResultColorNoAlphaBlendRGB
,
70 splashPipeResultColorNoAlphaBlendMono
,
71 splashPipeResultColorAlphaNoBlendMono
,
72 splashPipeResultColorAlphaNoBlendRGB
,
74 splashPipeResultColorAlphaNoBlendCMYK
,
75 splashPipeResultColorAlphaNoBlendDeviceN
,
77 splashPipeResultColorAlphaBlendMono
,
78 splashPipeResultColorAlphaBlendRGB
81 splashPipeResultColorAlphaBlendCMYK
,
82 splashPipeResultColorAlphaBlendDeviceN
86 //------------------------------------------------------------------------
88 //------------------------------------------------------------------------
93 // Create a new rasterizer object.
94 Splash(SplashBitmap
*bitmapA
, GBool vectorAntialiasA
,
95 SplashScreenParams
*screenParams
= NULL
);
96 Splash(SplashBitmap
*bitmapA
, GBool vectorAntialiasA
,
97 SplashScreen
*screenA
);
103 SplashCoord
*getMatrix();
104 SplashPattern
*getStrokePattern();
105 SplashPattern
*getFillPattern();
106 SplashScreen
*getScreen();
107 SplashBlendFunc
getBlendFunc();
108 SplashCoord
getStrokeAlpha();
109 SplashCoord
getFillAlpha();
110 SplashCoord
getLineWidth();
113 SplashCoord
getMiterLimit();
114 SplashCoord
getFlatness();
115 SplashCoord
*getLineDash();
116 int getLineDashLength();
117 SplashCoord
getLineDashPhase();
118 GBool
getStrokeAdjust();
119 SplashClip
*getClip();
120 SplashBitmap
*getSoftMask();
121 GBool
getInNonIsolatedGroup();
125 void setMatrix(SplashCoord
*matrix
);
126 void setStrokePattern(SplashPattern
*strokeColor
);
127 void setFillPattern(SplashPattern
*fillColor
);
128 void setScreen(SplashScreen
*screen
);
129 void setBlendFunc(SplashBlendFunc func
);
130 void setStrokeAlpha(SplashCoord alpha
);
131 void setFillAlpha(SplashCoord alpha
);
132 void setPatternAlpha(SplashCoord strokeAlpha
, SplashCoord fillAlpha
);
133 void clearPatternAlpha();
134 void setFillOverprint(GBool fop
);
135 void setStrokeOverprint(GBool sop
);
136 void setOverprintMode(int opm
);
137 void setLineWidth(SplashCoord lineWidth
);
138 void setLineCap(int lineCap
);
139 void setLineJoin(int lineJoin
);
140 void setMiterLimit(SplashCoord miterLimit
);
141 void setFlatness(SplashCoord flatness
);
142 // the <lineDash> array will be copied
143 void setLineDash(SplashCoord
*lineDash
, int lineDashLength
,
144 SplashCoord lineDashPhase
);
145 void setStrokeAdjust(GBool strokeAdjust
);
146 // NB: uses transformed coordinates.
147 void clipResetToRect(SplashCoord x0
, SplashCoord y0
,
148 SplashCoord x1
, SplashCoord y1
);
149 // NB: uses transformed coordinates.
150 SplashError
clipToRect(SplashCoord x0
, SplashCoord y0
,
151 SplashCoord x1
, SplashCoord y1
);
152 // NB: uses untransformed coordinates.
153 SplashError
clipToPath(SplashPath
*path
, GBool eo
);
154 void setSoftMask(SplashBitmap
*softMask
);
155 void setInNonIsolatedGroup(SplashBitmap
*alpha0BitmapA
,
156 int alpha0XA
, int alpha0YA
);
157 void setTransfer(Guchar
*red
, Guchar
*green
, Guchar
*blue
, Guchar
*gray
);
158 void setOverprintMask(Guint overprintMask
, GBool additive
);
160 //----- state save/restore
163 SplashError
restoreState();
165 //----- drawing operations
167 // Fill the bitmap with <color>. This is not subject to clipping.
168 void clear(SplashColorPtr color
, Guchar alpha
= 0x00);
170 // Stroke a path using the current stroke pattern.
171 SplashError
stroke(SplashPath
*path
);
173 // Fill a path using the current fill pattern.
174 SplashError
fill(SplashPath
*path
, GBool eo
);
176 // Fill a path, XORing with the current fill pattern.
177 SplashError
xorFill(SplashPath
*path
, GBool eo
);
179 // Draw a character, using the current fill pattern.
180 SplashError
fillChar(SplashCoord x
, SplashCoord y
, int c
, SplashFont
*font
);
182 // Draw a glyph, using the current fill pattern. This function does
183 // not free any data, i.e., it ignores glyph->freeData.
184 void fillGlyph(SplashCoord x
, SplashCoord y
,
185 SplashGlyphBitmap
*glyph
);
187 // Draws an image mask using the fill color. This will read <h>
188 // lines of <w> pixels from <src>, starting with the top line. "1"
189 // pixels will be drawn with the current fill color; "0" pixels are
190 // transparent. The matrix:
191 // [ mat[0] mat[1] 0 ]
192 // [ mat[2] mat[3] 0 ]
193 // [ mat[4] mat[5] 1 ]
194 // maps a unit square to the desired destination for the image, in
196 // [x' y' 1] = [x y 1] * mat
197 // Note that the Splash y axis points downward, and the image source
198 // is assumed to produce pixels in raster order, starting from the
200 SplashError
fillImageMask(SplashImageMaskSource src
, void *srcData
,
201 int w
, int h
, SplashCoord
*mat
,
204 // Draw an image. This will read <h> lines of <w> pixels from
205 // <src>, starting with the top line. These pixels are assumed to
206 // be in the source mode, <srcMode>. If <srcAlpha> is true, the
207 // alpha values returned by <src> are used; otherwise they are
208 // ignored. The following combinations of source and target modes
213 // Mono8 Mono1 -- with dithering
218 // The matrix behaves as for fillImageMask.
219 SplashError
drawImage(SplashImageSource src
, SplashICCTransform tf
, void *srcData
,
220 SplashColorMode srcMode
, GBool srcAlpha
,
221 int w
, int h
, SplashCoord
*mat
, GBool interpolate
,
222 GBool tilingPattern
= gFalse
);
224 // Composite a rectangular region from <src> onto this Splash
226 SplashError
composite(SplashBitmap
*src
, int xSrc
, int ySrc
,
227 int xDest
, int yDest
, int w
, int h
,
228 GBool noClip
, GBool nonIsolated
,
229 GBool knockout
= gFalse
, SplashCoord knockoutOpacity
= 1.0);
231 // Composite this Splash object onto a background color. The
232 // background alpha is assumed to be 1.
233 void compositeBackground(SplashColorPtr color
);
235 // Copy a rectangular region from <src> onto the bitmap belonging to
236 // this Splash object. The destination alpha values are all set to
238 SplashError
blitTransparent(SplashBitmap
*src
, int xSrc
, int ySrc
,
239 int xDest
, int yDest
, int w
, int h
);
240 void blitImage(SplashBitmap
*src
, GBool srcAlpha
, int xDest
, int yDest
);
244 // Construct a path for a stroke, given the path to be stroked and
245 // the line width <w>. All other stroke parameters are taken from
246 // the current state. If <flatten> is true, this function will
247 // first flatten the path and handle the linedash.
248 SplashPath
*makeStrokePath(SplashPath
*path
, SplashCoord w
,
249 GBool flatten
= gTrue
);
251 // Return the associated bitmap.
252 SplashBitmap
*getBitmap() { return bitmap
; }
254 // Set the minimum line width.
255 void setMinLineWidth(SplashCoord w
) { minLineWidth
= w
; }
257 // Setter/Getter for thin line mode
258 void setThinLineMode(SplashThinLineMode thinLineModeA
) { thinLineMode
= thinLineModeA
; }
259 SplashThinLineMode
getThinLineMode() { return thinLineMode
; }
261 // Get a bounding box which includes all modifications since the
262 // last call to clearModRegion.
263 void getModRegion(int *xMin
, int *yMin
, int *xMax
, int *yMax
)
264 { *xMin
= modXMin
; *yMin
= modYMin
; *xMax
= modXMax
; *yMax
= modYMax
; }
266 // Clear the modified region bounding box.
267 void clearModRegion();
269 // Get clipping status for the last drawing operation subject to
271 SplashClipResult
getClipRes() { return opClipRes
; }
273 // Toggle debug mode on or off.
274 void setDebugMode(GBool debugModeA
) { debugMode
= debugModeA
; }
276 #if 1 //~tmp: turn off anti-aliasing temporarily
277 void setInShading(GBool sh
) { inShading
= sh
; }
278 GBool
getVectorAntialias() { return vectorAntialias
; }
279 void setVectorAntialias(GBool vaa
) { vectorAntialias
= vaa
; }
282 // Do shaded fills with dynamic patterns
283 SplashError
shadedFill(SplashPath
*path
, GBool hasBBox
,
284 SplashPattern
*pattern
);
285 // Draw a gouraud triangle shading.
286 GBool
gouraudTriangleShadedFill(SplashGouraudColor
*shading
);
290 void pipeInit(SplashPipe
*pipe
, int x
, int y
,
291 SplashPattern
*pattern
, SplashColorPtr cSrc
,
292 Guchar aInput
, GBool usesShape
,
293 GBool nonIsolatedGroup
,
294 GBool knockout
= gFalse
, Guchar knockoutOpacity
= 255);
295 void pipeRun(SplashPipe
*pipe
);
296 void pipeRunSimpleMono1(SplashPipe
*pipe
);
297 void pipeRunSimpleMono8(SplashPipe
*pipe
);
298 void pipeRunSimpleRGB8(SplashPipe
*pipe
);
299 void pipeRunSimpleXBGR8(SplashPipe
*pipe
);
300 void pipeRunSimpleBGR8(SplashPipe
*pipe
);
302 void pipeRunSimpleCMYK8(SplashPipe
*pipe
);
303 void pipeRunSimpleDeviceN8(SplashPipe
*pipe
);
305 void pipeRunAAMono1(SplashPipe
*pipe
);
306 void pipeRunAAMono8(SplashPipe
*pipe
);
307 void pipeRunAARGB8(SplashPipe
*pipe
);
308 void pipeRunAAXBGR8(SplashPipe
*pipe
);
309 void pipeRunAABGR8(SplashPipe
*pipe
);
311 void pipeRunAACMYK8(SplashPipe
*pipe
);
312 void pipeRunAADeviceN8(SplashPipe
*pipe
);
314 void pipeSetXY(SplashPipe
*pipe
, int x
, int y
);
315 void pipeIncX(SplashPipe
*pipe
);
316 void drawPixel(SplashPipe
*pipe
, int x
, int y
, GBool noClip
);
317 void drawAAPixelInit();
318 void drawAAPixel(SplashPipe
*pipe
, int x
, int y
);
319 void drawSpan(SplashPipe
*pipe
, int x0
, int x1
, int y
, GBool noClip
);
320 void drawAALine(SplashPipe
*pipe
, int x0
, int x1
, int y
, GBool adjustLine
= gFalse
, Guchar lineOpacity
= 0);
321 void transform(SplashCoord
*matrix
, SplashCoord xi
, SplashCoord yi
,
322 SplashCoord
*xo
, SplashCoord
*yo
);
323 void updateModX(int x
);
324 void updateModY(int y
);
325 void strokeNarrow(SplashPath
*path
);
326 void strokeWide(SplashPath
*path
, SplashCoord w
);
327 SplashPath
*flattenPath(SplashPath
*path
, SplashCoord
*matrix
,
328 SplashCoord flatness
);
329 void flattenCurve(SplashCoord x0
, SplashCoord y0
,
330 SplashCoord x1
, SplashCoord y1
,
331 SplashCoord x2
, SplashCoord y2
,
332 SplashCoord x3
, SplashCoord y3
,
333 SplashCoord
*matrix
, SplashCoord flatness2
,
335 SplashPath
*makeDashedPath(SplashPath
*xPath
);
336 void getBBoxFP(SplashPath
*path
, SplashCoord
*xMinA
, SplashCoord
*yMinA
, SplashCoord
*xMaxA
, SplashCoord
*yMaxA
);
337 SplashError
fillWithPattern(SplashPath
*path
, GBool eo
,
338 SplashPattern
*pattern
, SplashCoord alpha
);
339 GBool
pathAllOutside(SplashPath
*path
);
340 void fillGlyph2(int x0
, int y0
, SplashGlyphBitmap
*glyph
, GBool noclip
);
341 void arbitraryTransformMask(SplashImageMaskSource src
, void *srcData
,
342 int srcWidth
, int srcHeight
,
343 SplashCoord
*mat
, GBool glyphMode
);
344 SplashBitmap
*scaleMask(SplashImageMaskSource src
, void *srcData
,
345 int srcWidth
, int srcHeight
,
346 int scaledWidth
, int scaledHeight
);
347 void scaleMaskYdXd(SplashImageMaskSource src
, void *srcData
,
348 int srcWidth
, int srcHeight
,
349 int scaledWidth
, int scaledHeight
,
351 void scaleMaskYdXu(SplashImageMaskSource src
, void *srcData
,
352 int srcWidth
, int srcHeight
,
353 int scaledWidth
, int scaledHeight
,
355 void scaleMaskYuXd(SplashImageMaskSource src
, void *srcData
,
356 int srcWidth
, int srcHeight
,
357 int scaledWidth
, int scaledHeight
,
359 void scaleMaskYuXu(SplashImageMaskSource src
, void *srcData
,
360 int srcWidth
, int srcHeight
,
361 int scaledWidth
, int scaledHeight
,
363 void blitMask(SplashBitmap
*src
, int xDest
, int yDest
,
364 SplashClipResult clipRes
);
365 SplashError
arbitraryTransformImage(SplashImageSource src
, SplashICCTransform tf
, void *srcData
,
366 SplashColorMode srcMode
, int nComps
,
368 int srcWidth
, int srcHeight
,
369 SplashCoord
*mat
, GBool interpolate
, GBool tilingPattern
= gFalse
);
370 SplashBitmap
*scaleImage(SplashImageSource src
, void *srcData
,
371 SplashColorMode srcMode
, int nComps
,
372 GBool srcAlpha
, int srcWidth
, int srcHeight
,
373 int scaledWidth
, int scaledHeight
, GBool interpolate
, GBool tilingPattern
= gFalse
);
374 void scaleImageYdXd(SplashImageSource src
, void *srcData
,
375 SplashColorMode srcMode
, int nComps
,
376 GBool srcAlpha
, int srcWidth
, int srcHeight
,
377 int scaledWidth
, int scaledHeight
,
379 void scaleImageYdXu(SplashImageSource src
, void *srcData
,
380 SplashColorMode srcMode
, int nComps
,
381 GBool srcAlpha
, int srcWidth
, int srcHeight
,
382 int scaledWidth
, int scaledHeight
,
384 void scaleImageYuXd(SplashImageSource src
, void *srcData
,
385 SplashColorMode srcMode
, int nComps
,
386 GBool srcAlpha
, int srcWidth
, int srcHeight
,
387 int scaledWidth
, int scaledHeight
,
389 void scaleImageYuXu(SplashImageSource src
, void *srcData
,
390 SplashColorMode srcMode
, int nComps
,
391 GBool srcAlpha
, int srcWidth
, int srcHeight
,
392 int scaledWidth
, int scaledHeight
,
394 void scaleImageYuXuBilinear(SplashImageSource src
, void *srcData
,
395 SplashColorMode srcMode
, int nComps
,
396 GBool srcAlpha
, int srcWidth
, int srcHeight
,
397 int scaledWidth
, int scaledHeight
,
399 void vertFlipImage(SplashBitmap
*img
, int width
, int height
,
401 void blitImage(SplashBitmap
*src
, GBool srcAlpha
, int xDest
, int yDest
,
402 SplashClipResult clipRes
);
403 void blitImageClipped(SplashBitmap
*src
, GBool srcAlpha
,
404 int xSrc
, int ySrc
, int xDest
, int yDest
,
406 void dumpPath(SplashPath
*path
);
407 void dumpXPath(SplashXPath
*path
);
409 static SplashPipeResultColorCtrl pipeResultColorNoAlphaBlend
[];
410 static SplashPipeResultColorCtrl pipeResultColorAlphaNoBlend
[];
411 static SplashPipeResultColorCtrl pipeResultColorAlphaBlend
[];
412 static int pipeNonIsoGroupCorrection
[];
414 SplashBitmap
*bitmap
;
418 SplashBitmap
*alpha0Bitmap
; // for non-isolated groups, this is the
419 // bitmap containing the alpha0 values
420 int alpha0X
, alpha0Y
; // offset within alpha0Bitmap
421 SplashCoord aaGamma
[splashAASize
* splashAASize
+ 1];
422 SplashCoord minLineWidth
;
423 SplashThinLineMode thinLineMode
;
424 int modXMin
, modYMin
, modXMax
, modYMax
;
425 SplashClipResult opClipRes
;
426 GBool vectorAntialias
;