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 setFillOverprint(GBool fop
);
133 void setStrokeOverprint(GBool sop
);
134 void setOverprintMode(int opm
);
135 void setLineWidth(SplashCoord lineWidth
);
136 void setLineCap(int lineCap
);
137 void setLineJoin(int lineJoin
);
138 void setMiterLimit(SplashCoord miterLimit
);
139 void setFlatness(SplashCoord flatness
);
140 // the <lineDash> array will be copied
141 void setLineDash(SplashCoord
*lineDash
, int lineDashLength
,
142 SplashCoord lineDashPhase
);
143 void setStrokeAdjust(GBool strokeAdjust
);
144 // NB: uses transformed coordinates.
145 void clipResetToRect(SplashCoord x0
, SplashCoord y0
,
146 SplashCoord x1
, SplashCoord y1
);
147 // NB: uses transformed coordinates.
148 SplashError
clipToRect(SplashCoord x0
, SplashCoord y0
,
149 SplashCoord x1
, SplashCoord y1
);
150 // NB: uses untransformed coordinates.
151 SplashError
clipToPath(SplashPath
*path
, GBool eo
);
152 void setSoftMask(SplashBitmap
*softMask
);
153 void setInNonIsolatedGroup(SplashBitmap
*alpha0BitmapA
,
154 int alpha0XA
, int alpha0YA
);
155 void setTransfer(Guchar
*red
, Guchar
*green
, Guchar
*blue
, Guchar
*gray
);
156 void setOverprintMask(Guint overprintMask
, GBool additive
);
158 //----- state save/restore
161 SplashError
restoreState();
163 //----- drawing operations
165 // Fill the bitmap with <color>. This is not subject to clipping.
166 void clear(SplashColorPtr color
, Guchar alpha
= 0x00);
168 // Stroke a path using the current stroke pattern.
169 SplashError
stroke(SplashPath
*path
);
171 // Fill a path using the current fill pattern.
172 SplashError
fill(SplashPath
*path
, GBool eo
);
174 // Fill a path, XORing with the current fill pattern.
175 SplashError
xorFill(SplashPath
*path
, GBool eo
);
177 // Draw a character, using the current fill pattern.
178 SplashError
fillChar(SplashCoord x
, SplashCoord y
, int c
, SplashFont
*font
);
180 // Draw a glyph, using the current fill pattern. This function does
181 // not free any data, i.e., it ignores glyph->freeData.
182 void fillGlyph(SplashCoord x
, SplashCoord y
,
183 SplashGlyphBitmap
*glyph
);
185 // Draws an image mask using the fill color. This will read <h>
186 // lines of <w> pixels from <src>, starting with the top line. "1"
187 // pixels will be drawn with the current fill color; "0" pixels are
188 // transparent. The matrix:
189 // [ mat[0] mat[1] 0 ]
190 // [ mat[2] mat[3] 0 ]
191 // [ mat[4] mat[5] 1 ]
192 // maps a unit square to the desired destination for the image, in
194 // [x' y' 1] = [x y 1] * mat
195 // Note that the Splash y axis points downward, and the image source
196 // is assumed to produce pixels in raster order, starting from the
198 SplashError
fillImageMask(SplashImageMaskSource src
, void *srcData
,
199 int w
, int h
, SplashCoord
*mat
,
202 // Draw an image. This will read <h> lines of <w> pixels from
203 // <src>, starting with the top line. These pixels are assumed to
204 // be in the source mode, <srcMode>. If <srcAlpha> is true, the
205 // alpha values returned by <src> are used; otherwise they are
206 // ignored. The following combinations of source and target modes
211 // Mono8 Mono1 -- with dithering
216 // The matrix behaves as for fillImageMask.
217 SplashError
drawImage(SplashImageSource src
, SplashICCTransform tf
, void *srcData
,
218 SplashColorMode srcMode
, GBool srcAlpha
,
219 int w
, int h
, SplashCoord
*mat
, GBool interpolate
,
220 GBool tilingPattern
= gFalse
);
222 // Composite a rectangular region from <src> onto this Splash
224 SplashError
composite(SplashBitmap
*src
, int xSrc
, int ySrc
,
225 int xDest
, int yDest
, int w
, int h
,
226 GBool noClip
, GBool nonIsolated
,
227 GBool knockout
= gFalse
, SplashCoord knockoutOpacity
= 1.0);
229 // Composite this Splash object onto a background color. The
230 // background alpha is assumed to be 1.
231 void compositeBackground(SplashColorPtr color
);
233 // Copy a rectangular region from <src> onto the bitmap belonging to
234 // this Splash object. The destination alpha values are all set to
236 SplashError
blitTransparent(SplashBitmap
*src
, int xSrc
, int ySrc
,
237 int xDest
, int yDest
, int w
, int h
);
238 void blitImage(SplashBitmap
*src
, GBool srcAlpha
, int xDest
, int yDest
);
242 // Construct a path for a stroke, given the path to be stroked and
243 // the line width <w>. All other stroke parameters are taken from
244 // the current state. If <flatten> is true, this function will
245 // first flatten the path and handle the linedash.
246 SplashPath
*makeStrokePath(SplashPath
*path
, SplashCoord w
,
247 GBool flatten
= gTrue
);
249 // Return the associated bitmap.
250 SplashBitmap
*getBitmap() { return bitmap
; }
252 // Set the minimum line width.
253 void setMinLineWidth(SplashCoord w
) { minLineWidth
= w
; }
255 // Setter/Getter for thin line mode
256 void setThinLineMode(SplashThinLineMode thinLineModeA
) { thinLineMode
= thinLineModeA
; }
257 SplashThinLineMode
getThinLineMode() { return thinLineMode
; }
259 // Get a bounding box which includes all modifications since the
260 // last call to clearModRegion.
261 void getModRegion(int *xMin
, int *yMin
, int *xMax
, int *yMax
)
262 { *xMin
= modXMin
; *yMin
= modYMin
; *xMax
= modXMax
; *yMax
= modYMax
; }
264 // Clear the modified region bounding box.
265 void clearModRegion();
267 // Get clipping status for the last drawing operation subject to
269 SplashClipResult
getClipRes() { return opClipRes
; }
271 // Toggle debug mode on or off.
272 void setDebugMode(GBool debugModeA
) { debugMode
= debugModeA
; }
274 #if 1 //~tmp: turn off anti-aliasing temporarily
275 void setInShading(GBool sh
) { inShading
= sh
; }
276 GBool
getVectorAntialias() { return vectorAntialias
; }
277 void setVectorAntialias(GBool vaa
) { vectorAntialias
= vaa
; }
280 // Do shaded fills with dynamic patterns
281 SplashError
shadedFill(SplashPath
*path
, GBool hasBBox
,
282 SplashPattern
*pattern
);
283 // Draw a gouraud triangle shading.
284 GBool
gouraudTriangleShadedFill(SplashGouraudColor
*shading
);
288 void pipeInit(SplashPipe
*pipe
, int x
, int y
,
289 SplashPattern
*pattern
, SplashColorPtr cSrc
,
290 Guchar aInput
, GBool usesShape
,
291 GBool nonIsolatedGroup
,
292 GBool knockout
= gFalse
, Guchar knockoutOpacity
= 255);
293 void pipeRun(SplashPipe
*pipe
);
294 void pipeRunSimpleMono1(SplashPipe
*pipe
);
295 void pipeRunSimpleMono8(SplashPipe
*pipe
);
296 void pipeRunSimpleRGB8(SplashPipe
*pipe
);
297 void pipeRunSimpleXBGR8(SplashPipe
*pipe
);
298 void pipeRunSimpleBGR8(SplashPipe
*pipe
);
300 void pipeRunSimpleCMYK8(SplashPipe
*pipe
);
301 void pipeRunSimpleDeviceN8(SplashPipe
*pipe
);
303 void pipeRunAAMono1(SplashPipe
*pipe
);
304 void pipeRunAAMono8(SplashPipe
*pipe
);
305 void pipeRunAARGB8(SplashPipe
*pipe
);
306 void pipeRunAAXBGR8(SplashPipe
*pipe
);
307 void pipeRunAABGR8(SplashPipe
*pipe
);
309 void pipeRunAACMYK8(SplashPipe
*pipe
);
310 void pipeRunAADeviceN8(SplashPipe
*pipe
);
312 void pipeSetXY(SplashPipe
*pipe
, int x
, int y
);
313 void pipeIncX(SplashPipe
*pipe
);
314 void drawPixel(SplashPipe
*pipe
, int x
, int y
, GBool noClip
);
315 void drawAAPixelInit();
316 void drawAAPixel(SplashPipe
*pipe
, int x
, int y
);
317 void drawSpan(SplashPipe
*pipe
, int x0
, int x1
, int y
, GBool noClip
);
318 void drawAALine(SplashPipe
*pipe
, int x0
, int x1
, int y
, GBool adjustLine
= gFalse
, Guchar lineOpacity
= 0);
319 void transform(SplashCoord
*matrix
, SplashCoord xi
, SplashCoord yi
,
320 SplashCoord
*xo
, SplashCoord
*yo
);
321 void updateModX(int x
);
322 void updateModY(int y
);
323 void strokeNarrow(SplashPath
*path
);
324 void strokeWide(SplashPath
*path
, SplashCoord w
);
325 SplashPath
*flattenPath(SplashPath
*path
, SplashCoord
*matrix
,
326 SplashCoord flatness
);
327 void flattenCurve(SplashCoord x0
, SplashCoord y0
,
328 SplashCoord x1
, SplashCoord y1
,
329 SplashCoord x2
, SplashCoord y2
,
330 SplashCoord x3
, SplashCoord y3
,
331 SplashCoord
*matrix
, SplashCoord flatness2
,
333 SplashPath
*makeDashedPath(SplashPath
*xPath
);
334 void getBBoxFP(SplashPath
*path
, SplashCoord
*xMinA
, SplashCoord
*yMinA
, SplashCoord
*xMaxA
, SplashCoord
*yMaxA
);
335 SplashError
fillWithPattern(SplashPath
*path
, GBool eo
,
336 SplashPattern
*pattern
, SplashCoord alpha
);
337 GBool
pathAllOutside(SplashPath
*path
);
338 void fillGlyph2(int x0
, int y0
, SplashGlyphBitmap
*glyph
, GBool noclip
);
339 void arbitraryTransformMask(SplashImageMaskSource src
, void *srcData
,
340 int srcWidth
, int srcHeight
,
341 SplashCoord
*mat
, GBool glyphMode
);
342 SplashBitmap
*scaleMask(SplashImageMaskSource src
, void *srcData
,
343 int srcWidth
, int srcHeight
,
344 int scaledWidth
, int scaledHeight
);
345 void scaleMaskYdXd(SplashImageMaskSource src
, void *srcData
,
346 int srcWidth
, int srcHeight
,
347 int scaledWidth
, int scaledHeight
,
349 void scaleMaskYdXu(SplashImageMaskSource src
, void *srcData
,
350 int srcWidth
, int srcHeight
,
351 int scaledWidth
, int scaledHeight
,
353 void scaleMaskYuXd(SplashImageMaskSource src
, void *srcData
,
354 int srcWidth
, int srcHeight
,
355 int scaledWidth
, int scaledHeight
,
357 void scaleMaskYuXu(SplashImageMaskSource src
, void *srcData
,
358 int srcWidth
, int srcHeight
,
359 int scaledWidth
, int scaledHeight
,
361 void blitMask(SplashBitmap
*src
, int xDest
, int yDest
,
362 SplashClipResult clipRes
);
363 SplashError
arbitraryTransformImage(SplashImageSource src
, SplashICCTransform tf
, void *srcData
,
364 SplashColorMode srcMode
, int nComps
,
366 int srcWidth
, int srcHeight
,
367 SplashCoord
*mat
, GBool interpolate
, GBool tilingPattern
= gFalse
);
368 SplashBitmap
*scaleImage(SplashImageSource src
, void *srcData
,
369 SplashColorMode srcMode
, int nComps
,
370 GBool srcAlpha
, int srcWidth
, int srcHeight
,
371 int scaledWidth
, int scaledHeight
, GBool interpolate
, GBool tilingPattern
= gFalse
);
372 void scaleImageYdXd(SplashImageSource src
, void *srcData
,
373 SplashColorMode srcMode
, int nComps
,
374 GBool srcAlpha
, int srcWidth
, int srcHeight
,
375 int scaledWidth
, int scaledHeight
,
377 void scaleImageYdXu(SplashImageSource src
, void *srcData
,
378 SplashColorMode srcMode
, int nComps
,
379 GBool srcAlpha
, int srcWidth
, int srcHeight
,
380 int scaledWidth
, int scaledHeight
,
382 void scaleImageYuXd(SplashImageSource src
, void *srcData
,
383 SplashColorMode srcMode
, int nComps
,
384 GBool srcAlpha
, int srcWidth
, int srcHeight
,
385 int scaledWidth
, int scaledHeight
,
387 void scaleImageYuXu(SplashImageSource src
, void *srcData
,
388 SplashColorMode srcMode
, int nComps
,
389 GBool srcAlpha
, int srcWidth
, int srcHeight
,
390 int scaledWidth
, int scaledHeight
,
392 void scaleImageYuXuBilinear(SplashImageSource src
, void *srcData
,
393 SplashColorMode srcMode
, int nComps
,
394 GBool srcAlpha
, int srcWidth
, int srcHeight
,
395 int scaledWidth
, int scaledHeight
,
397 void vertFlipImage(SplashBitmap
*img
, int width
, int height
,
399 void blitImage(SplashBitmap
*src
, GBool srcAlpha
, int xDest
, int yDest
,
400 SplashClipResult clipRes
);
401 void blitImageClipped(SplashBitmap
*src
, GBool srcAlpha
,
402 int xSrc
, int ySrc
, int xDest
, int yDest
,
404 void dumpPath(SplashPath
*path
);
405 void dumpXPath(SplashXPath
*path
);
407 static SplashPipeResultColorCtrl pipeResultColorNoAlphaBlend
[];
408 static SplashPipeResultColorCtrl pipeResultColorAlphaNoBlend
[];
409 static SplashPipeResultColorCtrl pipeResultColorAlphaBlend
[];
410 static int pipeNonIsoGroupCorrection
[];
412 SplashBitmap
*bitmap
;
416 SplashBitmap
*alpha0Bitmap
; // for non-isolated groups, this is the
417 // bitmap containing the alpha0 values
418 int alpha0X
, alpha0Y
; // offset within alpha0Bitmap
419 SplashCoord aaGamma
[splashAASize
* splashAASize
+ 1];
420 SplashCoord minLineWidth
;
421 SplashThinLineMode thinLineMode
;
422 int modXMin
, modYMin
, modXMax
, modYMax
;
423 SplashClipResult opClipRes
;
424 GBool vectorAntialias
;