Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-11 10:26:10

0001 //========================================================================
0002 //
0003 // Splash.h
0004 //
0005 //========================================================================
0006 
0007 //========================================================================
0008 //
0009 // Modified under the Poppler project - http://poppler.freedesktop.org
0010 //
0011 // All changes made under the Poppler project to this file are licensed
0012 // under GPL version 2 or later
0013 //
0014 // Copyright (C) 2005 Marco Pesenti Gritti <mpg@redhat.com>
0015 // Copyright (C) 2007, 2011, 2018, 2019, 2021, 2022 Albert Astals Cid <aacid@kde.org>
0016 // Copyright (C) 2010-2013, 2015 Thomas Freitag <Thomas.Freitag@alfa.de>
0017 // Copyright (C) 2010 Christian Feuersänger <cfeuersaenger@googlemail.com>
0018 // Copyright (C) 2012, 2017 Adrian Johnson <ajohnson@redneon.com>
0019 // Copyright (C) 2020 Oliver Sander <oliver.sander@tu-dresden.de>
0020 // Copyright (C) 2020 Tobias Deiminger <haxtibal@posteo.de>
0021 //
0022 // To see a description of the changes please see the Changelog file that
0023 // came with your tarball or type make ChangeLog if you are building from git
0024 //
0025 //========================================================================
0026 
0027 #ifndef SPLASH_H
0028 #define SPLASH_H
0029 
0030 #include <cstddef>
0031 #include "SplashTypes.h"
0032 #include "SplashClip.h"
0033 #include "SplashPattern.h"
0034 #include "poppler_private_export.h"
0035 
0036 class SplashBitmap;
0037 struct SplashGlyphBitmap;
0038 class SplashState;
0039 class SplashScreen;
0040 class SplashPath;
0041 class SplashXPath;
0042 class SplashFont;
0043 struct SplashPipe;
0044 
0045 //------------------------------------------------------------------------
0046 
0047 // Retrieves the next line of pixels in an image mask.  Normally,
0048 // fills in *<line> and returns true.  If the image stream is
0049 // exhausted, returns false.
0050 typedef bool (*SplashImageMaskSource)(void *data, SplashColorPtr pixel);
0051 
0052 // Retrieves the next line of pixels in an image.  Normally, fills in
0053 // *<line> and returns true.  If the image stream is exhausted,
0054 // returns false.
0055 typedef bool (*SplashImageSource)(void *data, SplashColorPtr colorLine, unsigned char *alphaLine);
0056 
0057 // Use ICCColorSpace to transform a bitmap
0058 typedef void (*SplashICCTransform)(void *data, SplashBitmap *bitmap);
0059 
0060 //------------------------------------------------------------------------
0061 
0062 enum SplashPipeResultColorCtrl
0063 {
0064     splashPipeResultColorNoAlphaBlendCMYK,
0065     splashPipeResultColorNoAlphaBlendDeviceN,
0066     splashPipeResultColorNoAlphaBlendRGB,
0067     splashPipeResultColorNoAlphaBlendMono,
0068     splashPipeResultColorAlphaNoBlendMono,
0069     splashPipeResultColorAlphaNoBlendRGB,
0070     splashPipeResultColorAlphaNoBlendCMYK,
0071     splashPipeResultColorAlphaNoBlendDeviceN,
0072     splashPipeResultColorAlphaBlendMono,
0073     splashPipeResultColorAlphaBlendRGB,
0074     splashPipeResultColorAlphaBlendCMYK,
0075     splashPipeResultColorAlphaBlendDeviceN
0076 };
0077 
0078 //------------------------------------------------------------------------
0079 // Splash
0080 //------------------------------------------------------------------------
0081 
0082 class POPPLER_PRIVATE_EXPORT Splash
0083 {
0084 public:
0085     // Create a new rasterizer object.
0086     Splash(SplashBitmap *bitmapA, bool vectorAntialiasA, SplashScreenParams *screenParams = nullptr);
0087     Splash(SplashBitmap *bitmapA, bool vectorAntialiasA, SplashScreen *screenA);
0088 
0089     ~Splash();
0090 
0091     Splash(const Splash &) = delete;
0092     Splash &operator=(const Splash &) = delete;
0093 
0094     //----- state read
0095 
0096     SplashCoord *getMatrix();
0097     SplashPattern *getStrokePattern();
0098     SplashPattern *getFillPattern();
0099     SplashScreen *getScreen();
0100     SplashBlendFunc getBlendFunc();
0101     SplashCoord getStrokeAlpha();
0102     SplashCoord getFillAlpha();
0103     SplashCoord getLineWidth();
0104     int getLineCap();
0105     int getLineJoin();
0106     SplashCoord getMiterLimit();
0107     SplashCoord getFlatness();
0108     SplashCoord getLineDashPhase();
0109     bool getStrokeAdjust();
0110     SplashClip *getClip();
0111     SplashBitmap *getSoftMask();
0112     bool getInNonIsolatedGroup();
0113 
0114     //----- state write
0115 
0116     void setMatrix(SplashCoord *matrix);
0117     void setStrokePattern(SplashPattern *strokePattern);
0118     void setFillPattern(SplashPattern *fillPattern);
0119     void setScreen(SplashScreen *screen);
0120     void setBlendFunc(SplashBlendFunc func);
0121     void setStrokeAlpha(SplashCoord alpha);
0122     void setFillAlpha(SplashCoord alpha);
0123     void setPatternAlpha(SplashCoord strokeAlpha, SplashCoord fillAlpha);
0124     void clearPatternAlpha();
0125     void setFillOverprint(bool fop);
0126     void setStrokeOverprint(bool sop);
0127     void setOverprintMode(int opm);
0128     void setLineWidth(SplashCoord lineWidth);
0129     void setLineCap(int lineCap);
0130     void setLineJoin(int lineJoin);
0131     void setMiterLimit(SplashCoord miterLimit);
0132     void setFlatness(SplashCoord flatness);
0133     // the <lineDash> array will be copied
0134     void setLineDash(std::vector<SplashCoord> &&lineDash, SplashCoord lineDashPhase);
0135     void setStrokeAdjust(bool strokeAdjust);
0136     // NB: uses transformed coordinates.
0137     void clipResetToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1);
0138     // NB: uses transformed coordinates.
0139     SplashError clipToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1);
0140     // NB: uses untransformed coordinates.
0141     SplashError clipToPath(SplashPath *path, bool eo);
0142     void setSoftMask(SplashBitmap *softMask);
0143     void setInNonIsolatedGroup(SplashBitmap *alpha0BitmapA, int alpha0XA, int alpha0YA);
0144     void setTransfer(unsigned char *red, unsigned char *green, unsigned char *blue, unsigned char *gray);
0145     void setOverprintMask(unsigned int overprintMask, bool additive);
0146 
0147     //----- state save/restore
0148 
0149     void saveState();
0150     SplashError restoreState();
0151 
0152     //----- drawing operations
0153 
0154     // Fill the bitmap with <color>.  This is not subject to clipping.
0155     void clear(SplashColorPtr color, unsigned char alpha = 0x00);
0156 
0157     // Stroke a path using the current stroke pattern.
0158     SplashError stroke(SplashPath *path);
0159 
0160     // Fill a path using the current fill pattern.
0161     SplashError fill(SplashPath *path, bool eo);
0162 
0163     // Fill a path, XORing with the current fill pattern.
0164     SplashError xorFill(SplashPath *path, bool eo);
0165 
0166     // Draw a character, using the current fill pattern.
0167     SplashError fillChar(SplashCoord x, SplashCoord y, int c, SplashFont *font);
0168 
0169     // Draw a glyph, using the current fill pattern.  This function does
0170     // not free any data, i.e., it ignores glyph->freeData.
0171     void fillGlyph(SplashCoord x, SplashCoord y, SplashGlyphBitmap *glyph);
0172 
0173     // Draws an image mask using the fill color.  This will read <h>
0174     // lines of <w> pixels from <src>, starting with the top line.  "1"
0175     // pixels will be drawn with the current fill color; "0" pixels are
0176     // transparent.  The matrix:
0177     //    [ mat[0] mat[1] 0 ]
0178     //    [ mat[2] mat[3] 0 ]
0179     //    [ mat[4] mat[5] 1 ]
0180     // maps a unit square to the desired destination for the image, in
0181     // PostScript style:
0182     //    [x' y' 1] = [x y 1] * mat
0183     // Note that the Splash y axis points downward, and the image source
0184     // is assumed to produce pixels in raster order, starting from the
0185     // top line.
0186     SplashError fillImageMask(SplashImageMaskSource src, void *srcData, int w, int h, SplashCoord *mat, bool glyphMode);
0187 
0188     // Draw an image.  This will read <h> lines of <w> pixels from
0189     // <src>, starting with the top line.  These pixels are assumed to
0190     // be in the source mode, <srcMode>.  If <srcAlpha> is true, the
0191     // alpha values returned by <src> are used; otherwise they are
0192     // ignored.  The following combinations of source and target modes
0193     // are supported:
0194     //    source       target
0195     //    ------       ------
0196     //    Mono1        Mono1
0197     //    Mono8        Mono1   -- with dithering
0198     //    Mono8        Mono8
0199     //    RGB8         RGB8
0200     //    BGR8         BGR8
0201     //    CMYK8        CMYK8
0202     // The matrix behaves as for fillImageMask.
0203     SplashError drawImage(SplashImageSource src, SplashICCTransform tf, void *srcData, SplashColorMode srcMode, bool srcAlpha, int w, int h, SplashCoord *mat, bool interpolate, bool tilingPattern = false);
0204 
0205     // Composite a rectangular region from <src> onto this Splash
0206     // object.
0207     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);
0208 
0209     // Composite this Splash object onto a background color.  The
0210     // background alpha is assumed to be 1.
0211     void compositeBackground(SplashColorConstPtr color);
0212 
0213     // Copy a rectangular region from <src> onto the bitmap belonging to
0214     // this Splash object.  The destination alpha values are all set to
0215     // zero.
0216     SplashError blitTransparent(SplashBitmap *src, int xSrc, int ySrc, int xDest, int yDest, int w, int h);
0217     void blitImage(SplashBitmap *src, bool srcAlpha, int xDest, int yDest);
0218 
0219     //----- misc
0220 
0221     // Construct a path for a stroke, given the path to be stroked and
0222     // the line width <w>.  All other stroke parameters are taken from
0223     // the current state.  If <flatten> is true, this function will
0224     // first flatten the path and handle the linedash.
0225     SplashPath *makeStrokePath(SplashPath *path, SplashCoord w, bool flatten = true);
0226 
0227     // Return the associated bitmap.
0228     SplashBitmap *getBitmap() { return bitmap; }
0229 
0230     // Set the minimum line width.
0231     void setMinLineWidth(SplashCoord w) { minLineWidth = w; }
0232 
0233     // Setter/Getter for thin line mode
0234     void setThinLineMode(SplashThinLineMode thinLineModeA) { thinLineMode = thinLineModeA; }
0235     SplashThinLineMode getThinLineMode() { return thinLineMode; }
0236 
0237     // Get clipping status for the last drawing operation subject to
0238     // clipping.
0239     SplashClipResult getClipRes() { return opClipRes; }
0240 
0241     // Toggle debug mode on or off.
0242     void setDebugMode(bool debugModeA) { debugMode = debugModeA; }
0243 
0244 #if 1 //~tmp: turn off anti-aliasing temporarily
0245     void setInShading(bool sh) { inShading = sh; }
0246     bool getVectorAntialias() { return vectorAntialias; }
0247     void setVectorAntialias(bool vaa) { vectorAntialias = vaa; }
0248 #endif
0249 
0250     // Do shaded fills with dynamic patterns
0251     //
0252     // clipToStrokePath: Whether the current clip region is a stroke path.
0253     //   In that case, strokeAlpha is used rather than fillAlpha.
0254     SplashError shadedFill(SplashPath *path, bool hasBBox, SplashPattern *pattern, bool clipToStrokePath);
0255     // Draw a gouraud triangle shading.
0256     bool gouraudTriangleShadedFill(SplashGouraudColor *shading);
0257 
0258 private:
0259     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);
0260     void pipeRun(SplashPipe *pipe);
0261     void pipeRunSimpleMono1(SplashPipe *pipe);
0262     void pipeRunSimpleMono8(SplashPipe *pipe);
0263     void pipeRunSimpleRGB8(SplashPipe *pipe);
0264     void pipeRunSimpleXBGR8(SplashPipe *pipe);
0265     void pipeRunSimpleBGR8(SplashPipe *pipe);
0266     void pipeRunSimpleCMYK8(SplashPipe *pipe);
0267     void pipeRunSimpleDeviceN8(SplashPipe *pipe);
0268     void pipeRunAAMono1(SplashPipe *pipe);
0269     void pipeRunAAMono8(SplashPipe *pipe);
0270     void pipeRunAARGB8(SplashPipe *pipe);
0271     void pipeRunAAXBGR8(SplashPipe *pipe);
0272     void pipeRunAABGR8(SplashPipe *pipe);
0273     void pipeRunAACMYK8(SplashPipe *pipe);
0274     void pipeRunAADeviceN8(SplashPipe *pipe);
0275     void pipeSetXY(SplashPipe *pipe, int x, int y);
0276     void pipeIncX(SplashPipe *pipe);
0277     void drawPixel(SplashPipe *pipe, int x, int y, bool noClip);
0278     void drawAAPixelInit();
0279     void drawAAPixel(SplashPipe *pipe, int x, int y);
0280     void drawSpan(SplashPipe *pipe, int x0, int x1, int y, bool noClip);
0281     void drawAALine(SplashPipe *pipe, int x0, int x1, int y, bool adjustLine = false, unsigned char lineOpacity = 0);
0282     void transform(const SplashCoord *matrix, SplashCoord xi, SplashCoord yi, SplashCoord *xo, SplashCoord *yo);
0283     void strokeNarrow(SplashPath *path);
0284     void strokeWide(SplashPath *path, SplashCoord w);
0285     SplashPath *flattenPath(SplashPath *path, SplashCoord *matrix, SplashCoord flatness);
0286     void flattenCurve(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1, SplashCoord x2, SplashCoord y2, SplashCoord x3, SplashCoord y3, SplashCoord *matrix, SplashCoord flatness2, SplashPath *fPath);
0287     SplashPath *makeDashedPath(SplashPath *xPath);
0288     void getBBoxFP(SplashPath *path, SplashCoord *xMinA, SplashCoord *yMinA, SplashCoord *xMaxA, SplashCoord *yMaxA);
0289     SplashError fillWithPattern(SplashPath *path, bool eo, SplashPattern *pattern, SplashCoord alpha);
0290     bool pathAllOutside(SplashPath *path);
0291     void fillGlyph2(int x0, int y0, SplashGlyphBitmap *glyph, bool noclip);
0292     void arbitraryTransformMask(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, SplashCoord *mat, bool glyphMode);
0293     SplashBitmap *scaleMask(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight);
0294     void scaleMaskYdownXdown(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest);
0295     void scaleMaskYdownXup(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest);
0296     void scaleMaskYupXdown(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest);
0297     void scaleMaskYupXup(SplashImageMaskSource src, void *srcData, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest);
0298     void blitMask(SplashBitmap *src, int xDest, int yDest, SplashClipResult clipRes);
0299     SplashError arbitraryTransformImage(SplashImageSource src, SplashICCTransform tf, void *srcData, SplashColorMode srcMode, int nComps, bool srcAlpha, int srcWidth, int srcHeight, SplashCoord *mat, bool interpolate,
0300                                         bool tilingPattern = false);
0301     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);
0302     bool scaleImageYdownXdown(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, bool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest);
0303     bool scaleImageYdownXup(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, bool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest);
0304     bool scaleImageYupXdown(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, bool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest);
0305     bool scaleImageYupXup(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, bool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest);
0306     bool scaleImageYupXupBilinear(SplashImageSource src, void *srcData, SplashColorMode srcMode, int nComps, bool srcAlpha, int srcWidth, int srcHeight, int scaledWidth, int scaledHeight, SplashBitmap *dest);
0307     void vertFlipImage(SplashBitmap *img, int width, int height, int nComps);
0308     void blitImage(SplashBitmap *src, bool srcAlpha, int xDest, int yDest, SplashClipResult clipRes);
0309     void blitImageClipped(SplashBitmap *src, bool srcAlpha, int xSrc, int ySrc, int xDest, int yDest, int w, int h);
0310     void dumpPath(SplashPath *path);
0311     void dumpXPath(SplashXPath *path);
0312 
0313     static SplashPipeResultColorCtrl pipeResultColorNoAlphaBlend[];
0314     static SplashPipeResultColorCtrl pipeResultColorAlphaNoBlend[];
0315     static SplashPipeResultColorCtrl pipeResultColorAlphaBlend[];
0316     static int pipeNonIsoGroupCorrection[];
0317 
0318     SplashBitmap *bitmap;
0319     SplashState *state;
0320     SplashBitmap *aaBuf;
0321     int aaBufY;
0322     SplashBitmap *alpha0Bitmap; // for non-isolated groups, this is the
0323                                 //   bitmap containing the alpha0 values
0324     int alpha0X, alpha0Y; // offset within alpha0Bitmap
0325     SplashCoord aaGamma[splashAASize * splashAASize + 1];
0326     SplashCoord minLineWidth;
0327     SplashThinLineMode thinLineMode;
0328     SplashClipResult opClipRes;
0329     bool vectorAntialias;
0330     bool inShading;
0331     bool debugMode;
0332 };
0333 
0334 #endif