"Fossies" - the Fresh Open Source Software Archive

Member "xpdf-4.02/splash/Splash.h" (25 Sep 2019, 17844 Bytes) of package /linux/misc/xpdf-4.02.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Splash.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 4.01.01_vs_4.02.

    1 //========================================================================
    2 //
    3 // Splash.h
    4 //
    5 // Copyright 2003-2013 Glyph & Cog, LLC
    6 //
    7 //========================================================================
    8 
    9 #ifndef SPLASH_H
   10 #define SPLASH_H
   11 
   12 #include <aconf.h>
   13 
   14 #ifdef USE_GCC_PRAGMAS
   15 #pragma interface
   16 #endif
   17 
   18 #include "SplashTypes.h"
   19 #include "SplashClip.h"
   20 
   21 class GString;
   22 class Splash;
   23 class SplashBitmap;
   24 struct SplashGlyphBitmap;
   25 class SplashState;
   26 class SplashPattern;
   27 class SplashScreen;
   28 class SplashPath;
   29 class SplashXPath;
   30 class SplashFont;
   31 struct SplashPipe;
   32 
   33 //------------------------------------------------------------------------
   34 
   35 // Retrieves the next line of pixels in an image mask.  Normally,
   36 // fills in *<line> and returns true.  If the image stream is
   37 // exhausted, returns false.
   38 typedef GBool (*SplashImageMaskSource)(void *data, Guchar *pixel);
   39 
   40 // Retrieves the next line of pixels in an image.  Normally, fills in
   41 // *<line> and returns true.  If the image stream is exhausted,
   42 // returns false.
   43 typedef GBool (*SplashImageSource)(void *data, SplashColorPtr colorLine,
   44                    Guchar *alphaLine);
   45 
   46 
   47 //------------------------------------------------------------------------
   48 
   49 enum SplashPipeResultColorCtrl {
   50   splashPipeResultColorNoAlphaBlendMono,
   51   splashPipeResultColorNoAlphaBlendRGB,
   52 #if SPLASH_CMYK
   53   splashPipeResultColorNoAlphaBlendCMYK,
   54 #endif
   55   splashPipeResultColorAlphaNoBlendMono,
   56   splashPipeResultColorAlphaNoBlendRGB,
   57 #if SPLASH_CMYK
   58   splashPipeResultColorAlphaNoBlendCMYK,
   59 #endif
   60   splashPipeResultColorAlphaBlendMono,
   61   splashPipeResultColorAlphaBlendRGB
   62 #if SPLASH_CMYK
   63   ,
   64   splashPipeResultColorAlphaBlendCMYK
   65 #endif
   66 };
   67 
   68 //------------------------------------------------------------------------
   69 // SplashImageCache
   70 //------------------------------------------------------------------------
   71 
   72 // This holds a cached image, and is shared by multiple Splash objects
   73 // in the same thread.
   74 class SplashImageCache {
   75 public:
   76 
   77   SplashImageCache();
   78   ~SplashImageCache();
   79   void incRefCount();
   80   void decRefCount();
   81 
   82   GString *tag;
   83   GBool isMask;
   84   int width;
   85   int height;
   86   SplashColorMode mode;
   87   GBool alpha;
   88   GBool interpolate;
   89   GBool vertFlip;
   90   GBool horizFlip;
   91   SplashBitmap *image;
   92 
   93   int refCount;
   94 };
   95 
   96 //------------------------------------------------------------------------
   97 // Splash
   98 //------------------------------------------------------------------------
   99 
  100 class Splash {
  101 public:
  102 
  103   // Create a new rasterizer object.
  104   Splash(SplashBitmap *bitmapA, GBool vectorAntialiasA,
  105      SplashImageCache *imageCacheA,
  106      SplashScreenParams *screenParams = NULL);
  107   Splash(SplashBitmap *bitmapA, GBool vectorAntialiasA,
  108      SplashImageCache *imageCacheA, SplashScreen *screenA);
  109 
  110   ~Splash();
  111 
  112   //----- state read
  113 
  114   SplashCoord *getMatrix();
  115   SplashPattern *getStrokePattern();
  116   SplashPattern *getFillPattern();
  117   SplashScreen *getScreen();
  118   SplashBlendFunc getBlendFunc();
  119   SplashCoord getStrokeAlpha();
  120   SplashCoord getFillAlpha();
  121   SplashCoord getLineWidth();
  122   int getLineCap();
  123   int getLineJoin();
  124   SplashCoord getMiterLimit();
  125   SplashCoord getFlatness();
  126   SplashCoord *getLineDash();
  127   int getLineDashLength();
  128   SplashCoord getLineDashPhase();
  129   SplashStrokeAdjustMode getStrokeAdjust();
  130   SplashClip *getClip();
  131   SplashBitmap *getSoftMask();
  132   GBool getInNonIsolatedGroup();
  133   GBool getInKnockoutGroup();
  134 
  135   //----- state write
  136 
  137   void setMatrix(SplashCoord *matrix);
  138   void setStrokePattern(SplashPattern *strokeColor);
  139   void setFillPattern(SplashPattern *fillColor);
  140   void setScreen(SplashScreen *screen);
  141   void setBlendFunc(SplashBlendFunc func);
  142   void setStrokeAlpha(SplashCoord alpha);
  143   void setFillAlpha(SplashCoord alpha);
  144   void setLineWidth(SplashCoord lineWidth);
  145   void setLineCap(int lineCap);
  146   void setLineJoin(int lineJoin);
  147   void setMiterLimit(SplashCoord miterLimit);
  148   void setFlatness(SplashCoord flatness);
  149   // the <lineDash> array will be copied
  150   void setLineDash(SplashCoord *lineDash, int lineDashLength,
  151            SplashCoord lineDashPhase);
  152   void setStrokeAdjust(SplashStrokeAdjustMode strokeAdjust);
  153   // NB: uses transformed coordinates.
  154   void clipResetToRect(SplashCoord x0, SplashCoord y0,
  155                SplashCoord x1, SplashCoord y1);
  156   // NB: uses transformed coordinates.
  157   SplashError clipToRect(SplashCoord x0, SplashCoord y0,
  158              SplashCoord x1, SplashCoord y1);
  159   // NB: uses untransformed coordinates.
  160   SplashError clipToPath(SplashPath *path, GBool eo);
  161   void setSoftMask(SplashBitmap *softMask);
  162   void setInTransparencyGroup(SplashBitmap *groupBackBitmapA,
  163                   int groupBackXA, int groupBackYA,
  164                   GBool nonIsolated, GBool knockout);
  165   void setTransfer(Guchar *red, Guchar *green, Guchar *blue, Guchar *gray);
  166   void setOverprintMask(Guint overprintMask);
  167   void setEnablePathSimplification(GBool en);
  168 
  169   //----- state save/restore
  170 
  171   void saveState();
  172   SplashError restoreState();
  173 
  174   //----- drawing operations
  175 
  176   // Fill the bitmap with <color>.  This is not subject to clipping.
  177   void clear(SplashColorPtr color, Guchar alpha = 0x00);
  178 
  179   // Stroke a path using the current stroke pattern.
  180   SplashError stroke(SplashPath *path);
  181 
  182   // Fill a path using the current fill pattern.
  183   SplashError fill(SplashPath *path, GBool eo);
  184 
  185   // Draw a character, using the current fill pattern.
  186   SplashError fillChar(SplashCoord x, SplashCoord y, int c, SplashFont *font);
  187 
  188   // Draw a glyph, using the current fill pattern.  This function does
  189   // not free any data, i.e., it ignores glyph->freeData.
  190   SplashError fillGlyph(SplashCoord x, SplashCoord y,
  191             SplashGlyphBitmap *glyph);
  192 
  193   // Draws an image mask using the fill color.  This will read <h>
  194   // lines of <w> pixels from <src>, starting with the top line.  "1"
  195   // pixels will be drawn with the current fill color; "0" pixels are
  196   // transparent.  The matrix:
  197   //    [ mat[0] mat[1] 0 ]
  198   //    [ mat[2] mat[3] 0 ]
  199   //    [ mat[4] mat[5] 1 ]
  200   // maps a unit square to the desired destination for the image, in
  201   // PostScript style:
  202   //    [x' y' 1] = [x y 1] * mat
  203   // Note that the Splash y axis points downward, and the image source
  204   // is assumed to produce pixels in raster order, starting from the
  205   // top line.
  206   SplashError fillImageMask(GString *imageTag,
  207                 SplashImageMaskSource src, void *srcData,
  208                 int w, int h, SplashCoord *mat,
  209                 GBool glyphMode, GBool interpolate);
  210 
  211   // Draw an image.  This will read <h> lines of <w> pixels from
  212   // <src>, starting with the top line.  These pixels are assumed to
  213   // be in the source mode, <srcMode>.  If <srcAlpha> is true, the
  214   // alpha values returned by <src> are used; otherwise they are
  215   // ignored.  The following combinations of source and target modes
  216   // are supported:
  217   //    source       target
  218   //    ------       ------
  219   //    Mono8        Mono1   -- with dithering
  220   //    Mono8        Mono8
  221   //    RGB8         RGB8
  222   //    BGR8         RGB8
  223   //    CMYK8        CMYK8
  224   // The matrix behaves as for fillImageMask.
  225   SplashError drawImage(GString *imageTag,
  226             SplashImageSource src, void *srcData,
  227             SplashColorMode srcMode, GBool srcAlpha,
  228             int w, int h, SplashCoord *mat,
  229             GBool interpolate);
  230 
  231   // Composite a rectangular region from <src> onto this Splash
  232   // object.
  233   SplashError composite(SplashBitmap *src, int xSrc, int ySrc,
  234             int xDest, int yDest, int w, int h,
  235             GBool noClip, GBool nonIsolated);
  236 
  237   // Composite this Splash object onto a background color.  The
  238   // background alpha is assumed to be 1.
  239   void compositeBackground(SplashColorPtr color);
  240 
  241   // Copy a rectangular region from <src> onto the bitmap belonging to
  242   // this Splash object.  The destination alpha values are all set to
  243   // zero.
  244   SplashError blitTransparent(SplashBitmap *src, int xSrc, int ySrc,
  245                   int xDest, int yDest, int w, int h);
  246 
  247   // Copy a rectangular region from the bitmap belonging to this
  248   // Splash object to <dest>.  The alpha values are corrected for a
  249   // non-isolated group.
  250   SplashError blitCorrectedAlpha(SplashBitmap *dest, int xSrc, int ySrc,
  251                  int xDest, int yDest, int w, int h);
  252 
  253   //----- misc
  254 
  255   // Construct a path for a stroke, given the path to be stroked and
  256   // the line width <w>.  All other stroke parameters are taken from
  257   // the current state.  If <flatten> is true, this function will
  258   // first flatten the path and handle the linedash.
  259   SplashPath *makeStrokePath(SplashPath *path, SplashCoord w,
  260                  int lineCap, int lineJoin,
  261                  GBool flatten = gTrue);
  262 
  263   // Reduce the size of a rectangle as much as possible by moving any
  264   // edges that are completely outside the clip region.  Returns the
  265   // clipping status of the resulting rectangle.
  266   SplashClipResult limitRectToClipRect(int *xMin, int *yMin,
  267                        int *xMax, int *yMax);
  268 
  269   // Return the associated bitmap.
  270   SplashBitmap *getBitmap() { return bitmap; }
  271 
  272   // Set the minimum line width.
  273   void setMinLineWidth(SplashCoord w) { minLineWidth = w; }
  274 
  275   // Get a bounding box which includes all modifications since the
  276   // last call to clearModRegion.
  277   void getModRegion(int *xMin, int *yMin, int *xMax, int *yMax)
  278     { *xMin = modXMin; *yMin = modYMin; *xMax = modXMax; *yMax = modYMax; }
  279 
  280   // Clear the modified region bounding box.
  281   void clearModRegion();
  282 
  283   // Get clipping status for the last drawing operation subject to
  284   // clipping.
  285   SplashClipResult getClipRes() { return opClipRes; }
  286 
  287   // Toggle debug mode on or off.
  288   void setDebugMode(GBool debugModeA) { debugMode = debugModeA; }
  289 
  290   SplashImageCache *getImageCache() { return imageCache; }
  291 
  292 #if 1 //~tmp: turn off anti-aliasing temporarily
  293   void setInShading(GBool sh) { inShading = sh; }
  294 #endif
  295 
  296 
  297 private:
  298 
  299   void pipeInit(SplashPipe *pipe, SplashPattern *pattern,
  300         Guchar aInput, GBool usesShape,
  301         GBool nonIsolatedGroup);
  302   void pipeRun(SplashPipe *pipe, int x0, int x1, int y,
  303            Guchar *shapePtr, SplashColorPtr cSrcPtr);
  304   void pipeRunSimpleMono1(SplashPipe *pipe, int x0, int x1, int y,
  305               Guchar *shapePtr, SplashColorPtr cSrcPtr);
  306   void pipeRunSimpleMono8(SplashPipe *pipe, int x0, int x1, int y,
  307               Guchar *shapePtr, SplashColorPtr cSrcPtr);
  308   void pipeRunSimpleRGB8(SplashPipe *pipe, int x0, int x1, int y,
  309              Guchar *shapePtr, SplashColorPtr cSrcPtr);
  310   void pipeRunSimpleBGR8(SplashPipe *pipe, int x0, int x1, int y,
  311              Guchar *shapePtr, SplashColorPtr cSrcPtr);
  312 #if SPLASH_CMYK
  313   void pipeRunSimpleCMYK8(SplashPipe *pipe, int x0, int x1, int y,
  314               Guchar *shapePtr, SplashColorPtr cSrcPtr);
  315 #endif
  316   void pipeRunShapeMono1(SplashPipe *pipe, int x0, int x1, int y,
  317              Guchar *shapePtr, SplashColorPtr cSrcPtr);
  318   void pipeRunShapeMono8(SplashPipe *pipe, int x0, int x1, int y,
  319              Guchar *shapePtr, SplashColorPtr cSrcPtr);
  320   void pipeRunShapeRGB8(SplashPipe *pipe, int x0, int x1, int y,
  321             Guchar *shapePtr, SplashColorPtr cSrcPtr);
  322   void pipeRunShapeBGR8(SplashPipe *pipe, int x0, int x1, int y,
  323             Guchar *shapePtr, SplashColorPtr cSrcPtr);
  324 #if SPLASH_CMYK
  325   void pipeRunShapeCMYK8(SplashPipe *pipe, int x0, int x1, int y,
  326              Guchar *shapePtr, SplashColorPtr cSrcPtr);
  327 #endif
  328   void pipeRunAAMono1(SplashPipe *pipe, int x0, int x1, int y,
  329               Guchar *shapePtr, SplashColorPtr cSrcPtr);
  330   void pipeRunAAMono8(SplashPipe *pipe, int x0, int x1, int y,
  331               Guchar *shapePtr, SplashColorPtr cSrcPtr);
  332   void pipeRunAARGB8(SplashPipe *pipe, int x0, int x1, int y,
  333              Guchar *shapePtr, SplashColorPtr cSrcPtr);
  334   void pipeRunAABGR8(SplashPipe *pipe, int x0, int x1, int y,
  335              Guchar *shapePtr, SplashColorPtr cSrcPtr);
  336 #if SPLASH_CMYK
  337   void pipeRunAACMYK8(SplashPipe *pipe, int x0, int x1, int y,
  338               Guchar *shapePtr, SplashColorPtr cSrcPtr);
  339 #endif
  340   void pipeRunNonIsoMono8(SplashPipe *pipe, int x0, int x1, int y,
  341               Guchar *shapePtr, SplashColorPtr cSrcPtr);
  342   void pipeRunNonIsoRGB8(SplashPipe *pipe, int x0, int x1, int y,
  343              Guchar *shapePtr, SplashColorPtr cSrcPtr);
  344   void pipeRunNonIsoBGR8(SplashPipe *pipe, int x0, int x1, int y,
  345              Guchar *shapePtr, SplashColorPtr cSrcPtr);
  346 #if SPLASH_CMYK
  347   void pipeRunNonIsoCMYK8(SplashPipe *pipe, int x0, int x1, int y,
  348               Guchar *shapePtr, SplashColorPtr cSrcPtr);
  349 #endif
  350   void transform(SplashCoord *matrix, SplashCoord xi, SplashCoord yi,
  351          SplashCoord *xo, SplashCoord *yo);
  352   void updateModX(int x);
  353   void updateModY(int y);
  354   void strokeNarrow(SplashPath *path);
  355   void drawStrokeSpan(SplashPipe *pipe, int x0, int x1, int y, GBool noClip);
  356   void strokeWide(SplashPath *path, SplashCoord w,
  357           int lineCap, int lineJoin);
  358   SplashPath *flattenPath(SplashPath *path, SplashCoord *matrix,
  359               SplashCoord flatness);
  360   void flattenCurve(SplashCoord x0, SplashCoord y0,
  361             SplashCoord x1, SplashCoord y1,
  362             SplashCoord x2, SplashCoord y2,
  363             SplashCoord x3, SplashCoord y3,
  364             SplashCoord *matrix, SplashCoord flatness2,
  365             SplashPath *fPath);
  366   SplashPath *makeDashedPath(SplashPath *xPath);
  367   SplashError fillWithPattern(SplashPath *path, GBool eo,
  368                   SplashPattern *pattern, SplashCoord alpha);
  369   SplashPath *tweakFillPath(SplashPath *path);
  370   GBool pathAllOutside(SplashPath *path);
  371   SplashError fillGlyph2(int x0, int y0, SplashGlyphBitmap *glyph);
  372   void getImageBounds(SplashCoord xyMin, SplashCoord xyMax,
  373               int *xyMinI, int *xyMaxI);
  374   void upscaleMask(SplashImageMaskSource src, void *srcData,
  375            int srcWidth, int srcHeight,
  376            SplashCoord *mat, GBool glyphMode,
  377            GBool interpolate);
  378   void arbitraryTransformMask(GString *imageTag,
  379                   SplashImageMaskSource src, void *srcData,
  380                   int srcWidth, int srcHeight,
  381                   SplashCoord *mat, GBool glyphMode,
  382                   GBool interpolate);
  383   SplashBitmap *scaleMask(GString *imageTag,
  384               SplashImageMaskSource src, void *srcData,
  385               int srcWidth, int srcHeight,
  386               int scaledWidth, int scaledHeight,
  387               GBool interpolate);
  388   void scaleMaskYdXd(SplashImageMaskSource src, void *srcData,
  389              int srcWidth, int srcHeight,
  390              int scaledWidth, int scaledHeight,
  391              SplashBitmap *dest);
  392   void scaleMaskYdXu(SplashImageMaskSource src, void *srcData,
  393              int srcWidth, int srcHeight,
  394              int scaledWidth, int scaledHeight,
  395              SplashBitmap *dest);
  396   void scaleMaskYuXd(SplashImageMaskSource src, void *srcData,
  397              int srcWidth, int srcHeight,
  398              int scaledWidth, int scaledHeight,
  399              SplashBitmap *dest);
  400   void scaleMaskYuXu(SplashImageMaskSource src, void *srcData,
  401              int srcWidth, int srcHeight,
  402              int scaledWidth, int scaledHeight,
  403              SplashBitmap *dest);
  404   void scaleMaskYuXuI(SplashImageMaskSource src, void *srcData,
  405               int srcWidth, int srcHeight,
  406               int scaledWidth, int scaledHeight,
  407               SplashBitmap *dest);
  408   void blitMask(SplashBitmap *src, int xDest, int yDest,
  409         SplashClipResult clipRes);
  410   void upscaleImage(SplashImageSource src, void *srcData,
  411             SplashColorMode srcMode, int nComps,
  412             GBool srcAlpha, int srcWidth, int srcHeight,
  413             SplashCoord *mat, GBool interpolate);
  414   void arbitraryTransformImage(GString *imageTag,
  415                    SplashImageSource src, void *srcData,
  416                    SplashColorMode srcMode, int nComps,
  417                    GBool srcAlpha,
  418                    int srcWidth, int srcHeight,
  419                    SplashCoord *mat, GBool interpolate);
  420   SplashBitmap *scaleImage(GString *imageTag,
  421                SplashImageSource src, void *srcData,
  422                SplashColorMode srcMode, int nComps,
  423                GBool srcAlpha, int srcWidth, int srcHeight,
  424                int scaledWidth, int scaledHeight,
  425                GBool interpolate);
  426   void scaleImageYdXd(SplashImageSource src, void *srcData,
  427               SplashColorMode srcMode, int nComps,
  428               GBool srcAlpha, int srcWidth, int srcHeight,
  429               int scaledWidth, int scaledHeight,
  430               SplashBitmap *dest);
  431   void scaleImageYdXu(SplashImageSource src, void *srcData,
  432               SplashColorMode srcMode, int nComps,
  433               GBool srcAlpha, int srcWidth, int srcHeight,
  434               int scaledWidth, int scaledHeight,
  435               SplashBitmap *dest);
  436   void scaleImageYuXd(SplashImageSource src, void *srcData,
  437               SplashColorMode srcMode, int nComps,
  438               GBool srcAlpha, int srcWidth, int srcHeight,
  439               int scaledWidth, int scaledHeight,
  440               SplashBitmap *dest);
  441   void scaleImageYuXu(SplashImageSource src, void *srcData,
  442               SplashColorMode srcMode, int nComps,
  443               GBool srcAlpha, int srcWidth, int srcHeight,
  444               int scaledWidth, int scaledHeight,
  445               SplashBitmap *dest);
  446   void scaleImageYuXuI(SplashImageSource src, void *srcData,
  447                SplashColorMode srcMode, int nComps,
  448                GBool srcAlpha, int srcWidth, int srcHeight,
  449                int scaledWidth, int scaledHeight,
  450                SplashBitmap *dest);
  451   void vertFlipImage(SplashBitmap *img, int width, int height,
  452              int nComps);
  453   void horizFlipImage(SplashBitmap *img, int width, int height,
  454               int nComps);
  455   void blitImage(SplashBitmap *src, GBool srcAlpha, int xDest, int yDest,
  456          SplashClipResult clipRes);
  457   void blitImageClipped(SplashBitmap *src, GBool srcAlpha,
  458             int xSrc, int ySrc, int xDest, int yDest,
  459             int w, int h);
  460   void dumpPath(SplashPath *path);
  461   void dumpXPath(SplashXPath *path);
  462 
  463 
  464   static SplashPipeResultColorCtrl pipeResultColorNoAlphaBlend[];
  465   static SplashPipeResultColorCtrl pipeResultColorAlphaNoBlend[];
  466   static SplashPipeResultColorCtrl pipeResultColorAlphaBlend[];
  467   static int pipeNonIsoGroupCorrection[];
  468 
  469   SplashBitmap *bitmap;
  470   int bitmapComps;
  471   SplashState *state;
  472   Guchar *scanBuf;
  473   Guchar *scanBuf2;
  474   SplashBitmap          // for transparency groups, this is the bitmap
  475     *groupBackBitmap;       //   containing the alpha0/color0 values
  476   int groupBackX, groupBackY;   // offset within groupBackBitmap
  477   SplashCoord minLineWidth;
  478   int modXMin, modYMin, modXMax, modYMax;
  479   SplashClipResult opClipRes;
  480   GBool vectorAntialias;
  481   GBool inShading;
  482   GBool debugMode;
  483 
  484   SplashImageCache *imageCache;
  485 };
  486 
  487 #endif