poppler: add new axial and radialShadedFill parameters
[swftools.git] / lib / pdf / BitmapOutputDev.cc
index a858765..b94fcde 100644 (file)
 #include <stdio.h>
 #include <memory.h>
 #include <assert.h>
-#include "config.h"
 #include "BitmapOutputDev.h"
 #include "GFXOutputDev.h"
-#include "SplashBitmap.h"
-#include "SplashPattern.h"
-#include "Splash.h"
+
+#ifdef HAVE_POPPLER
+  #include "splash/SplashBitmap.h"
+  #include "splash/SplashPattern.h"
+  #include "splash/Splash.h"
+#else
+  #include "xpdf/config.h"
+  #include "SplashBitmap.h"
+  #include "SplashPattern.h"
+  #include "Splash.h"
+#endif
+
 #include "../log.h"
 #include "../png.h"
 #include "../devices/record.h"
@@ -350,7 +358,7 @@ void writeMonoBitmap(SplashBitmap*btm, char*filename)
             }
         }
     }
-    writePNG(filename, (unsigned char*)b, width, height);
+    png_write(filename, (unsigned char*)b, width, height);
     free(b);
 }
 
@@ -379,7 +387,7 @@ void writeBitmap(SplashBitmap*bitmap, char*filename)
            line[x].a =  bitmap->getAlpha(x,y);
        }
     }
-    writePNG(filename, (unsigned char*)data, width, height);
+    png_write(filename, (unsigned char*)data, width, height);
     free(data);
 }
 
@@ -407,7 +415,7 @@ void writeAlpha(SplashBitmap*bitmap, char*filename)
            line[x].a = a;
        }
     }
-    writePNG(filename, (unsigned char*)data, width, height);
+    png_write(filename, (unsigned char*)data, width, height);
     free(data);
 }
 
@@ -851,12 +859,24 @@ GBool BitmapOutputDev::intersection(SplashBitmap*boolpoly, SplashBitmap*booltext
     }
 }
 
+GBool BitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI,
+             int rotate, GBool useMediaBox, GBool crop,
+             int sliceX, int sliceY, int sliceW, int sliceH,
+             GBool printing, Catalog *catalog,
+             GBool (*abortCheckCbk)(void *data),
+             void *abortCheckCbkData)
+{
+    this->setPage(page);
+    gfxdev->setPage(page);
+    return gTrue;
+}
 
-void BitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
+void BitmapOutputDev::startPage(int pageNum, GfxState *state)
 {
+    PDFRectangle *r = this->page->getCropBox();
     double x1,y1,x2,y2;
-    state->transform(crop_x1,crop_y1,&x1,&y1);
-    state->transform(crop_x2,crop_y2,&x2,&y2);
+    state->transform(r->x1,r->y1,&x1,&y1);
+    state->transform(r->x2,r->y2,&x2,&y2);
     if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
     if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
     
@@ -872,12 +892,12 @@ void BitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, do
     this->width = (int)(x2-x1);
     this->height = (int)(y2-y1);
 
-    rgbdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
-    boolpolydev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
-    booltextdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
-    clip0dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
-    clip1dev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
-    gfxdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
+    rgbdev->startPage(pageNum, state);
+    boolpolydev->startPage(pageNum, state);
+    booltextdev->startPage(pageNum, state);
+    clip0dev->startPage(pageNum, state);
+    clip1dev->startPage(pageNum, state);
+    gfxdev->startPage(pageNum, state);
 
     boolpolybitmap = boolpolydev->getBitmap();
     stalepolybitmap = new SplashBitmap(boolpolybitmap->getWidth(), boolpolybitmap->getHeight(), 1, boolpolybitmap->getMode(), 0);
@@ -990,15 +1010,6 @@ GBool BitmapOutputDev::needNonText()
     clip1dev->needNonText();
     return rgbdev->needNonText();
 }
-/*GBool BitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI,
-                          int rotate, GBool useMediaBox, GBool crop,
-                          int sliceX, int sliceY, int sliceW, int sliceH,
-                          GBool printing, Catalog *catalog,
-                          GBool (*abortCheckCbk)(void *data),
-                          void *abortCheckCbkData)
-{
-    return gTrue;
-}*/
 void BitmapOutputDev::setDefaultCTM(double *ctm) 
 {
     boolpolydev->setDefaultCTM(ctm);
@@ -1397,33 +1408,24 @@ void BitmapOutputDev::eoFill(GfxState *state)
     rgbdev->eoFill(state);
     dbg_newdata("eofill");
 }
-#if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
-void BitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
-                              int paintType, Dict *resDict,
-                              double *mat, double *bbox,
-                              int x0, int y0, int x1, int y1,
-                              double xStep, double yStep)
-{
-    msg("<debug> tilingPatternFill");
-    boolpolydev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
-    checkNewBitmap(UNKNOWN_BOUNDING_BOX);
-    rgbdev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
-    dbg_newdata("tilingpatternfill");
-}
-#else
-void BitmapOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
+
+POPPLER_TILING_PATERN_RETURN BitmapOutputDev::tilingPatternFill(GfxState *state, POPPLER_TILING_PATERN_GFX Object *str,
                               int paintType, Dict *resDict,
                               double *mat, double *bbox,
                               int x0, int y0, int x1, int y1,
                               double xStep, double yStep) 
 {
     msg("<debug> tilingPatternFill");
-    boolpolydev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
+    boolpolydev->tilingPatternFill(state, POPPLER_TILING_PATERN_GFX_ARG str, paintType, resDict, mat,
+                                   bbox, x0, y0, x1, y1, xStep, yStep);
     checkNewBitmap(UNKNOWN_BOUNDING_BOX);
-    rgbdev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
+    rgbdev->tilingPatternFill(state, POPPLER_TILING_PATERN_GFX_ARG str, paintType, resDict, mat,
+                              bbox, x0, y0, x1, y1, xStep, yStep);
     dbg_newdata("tilingpatternfill");
-}
+#ifdef HAVE_POPPLER
+    return gTrue;
 #endif
+}
 
 GBool BitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading) 
 {
@@ -1432,19 +1434,21 @@ GBool BitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *s
     checkNewBitmap(UNKNOWN_BOUNDING_BOX);
     return rgbdev->functionShadedFill(state, shading);
 }
-GBool BitmapOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading)
+
+GBool BitmapOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading POPPLER_RAXIAL_MIN_MAX)
 {
     msg("<debug> axialShadedFill");
-    boolpolydev->axialShadedFill(state, shading);
+    boolpolydev->axialShadedFill(state, shading POPPLER_RAXIAL_MIN_MAX_ARG);
     checkNewBitmap(UNKNOWN_BOUNDING_BOX);
-    return rgbdev->axialShadedFill(state, shading);
+    return rgbdev->axialShadedFill(state, shading POPPLER_RAXIAL_MIN_MAX_ARG);
 }
-GBool BitmapOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading)
+
+GBool BitmapOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading POPPLER_RAXIAL_MIN_MAX)
 {
     msg("<debug> radialShadedFill");
-    boolpolydev->radialShadedFill(state, shading);
+    boolpolydev->radialShadedFill(state, shading POPPLER_RAXIAL_MIN_MAX_ARG);
     checkNewBitmap(UNKNOWN_BOUNDING_BOX);
-    return rgbdev->radialShadedFill(state, shading);
+    return rgbdev->radialShadedFill(state, shading POPPLER_RAXIAL_MIN_MAX_ARG);
 }
 
 SplashColor black = {0,0,0};
@@ -1711,7 +1715,7 @@ GBool invalid_size(int width, int height)
 }
 
 void BitmapOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
-                          int width, int height, GBool invert,
+                          int width, int height, GBool invert, POPPLER_INTERPOLATE
                           GBool inlineImg)
 {
     msg("<debug> drawImageMask streamkind=%d", str->getKind());
@@ -1720,15 +1724,16 @@ void BitmapOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
     CopyStream*cpystr = new CopyStream(str, height * ((width + 7) / 8));
     str = cpystr->getStream();
     
-    boolpolydev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
+    boolpolydev->drawImageMask(state, ref, str, width, height, invert, POPPLER_INTERPOLATE_ARG inlineImg);
     gfxbbox_t bbox = getImageBBox(state);
     checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
-    rgbdev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
+    rgbdev->drawImageMask(state, ref, str, width, height, invert, POPPLER_INTERPOLATE_ARG inlineImg);
     delete cpystr;
     dbg_newdata("imagemask");
 }
 void BitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
                       int width, int height, GfxImageColorMap *colorMap,
+                      POPPLER_INTERPOLATE
                       int *maskColors, GBool inlineImg)
 {
     msg("<debug> drawImage streamkind=%d", str->getKind());
@@ -1737,18 +1742,19 @@ void BitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
     CopyStream*cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
     str = cpystr->getStream();
 
-    boolpolydev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
+    boolpolydev->drawImage(state, ref, str, width, height, colorMap, POPPLER_INTERPOLATE_ARG maskColors, inlineImg);
     gfxbbox_t bbox=getImageBBox(state);
     checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
-    rgbdev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
+    rgbdev->drawImage(state, ref, str, width, height, colorMap, POPPLER_INTERPOLATE_ARG maskColors, inlineImg);
     delete cpystr;
     dbg_newdata("image");
 }
 void BitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
                             int width, int height,
                             GfxImageColorMap *colorMap,
+                            POPPLER_INTERPOLATE
                             Stream *maskStr, int maskWidth, int maskHeight,
-                            GBool maskInvert)
+                            GBool maskInvert POPPLER_MASK_INTERPOLATE)
 {
     msg("<debug> drawMaskedImage streamkind=%d", str->getKind());
     if(invalid_size(width,height)) return;
@@ -1756,19 +1762,20 @@ void BitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
     CopyStream*cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
     str = cpystr->getStream();
 
-    boolpolydev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
+    boolpolydev->drawMaskedImage(state, ref, str, width, height, colorMap, POPPLER_INTERPOLATE_ARG maskStr, maskWidth, maskHeight, maskInvert POPPLER_MASK_INTERPOLATE_ARG);
     gfxbbox_t bbox=getImageBBox(state);
     checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
-    rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
+    rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap, POPPLER_INTERPOLATE_ARG maskStr, maskWidth, maskHeight, maskInvert POPPLER_MASK_INTERPOLATE_ARG);
     delete cpystr;
     dbg_newdata("maskedimage");
 }
 void BitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
                                 int width, int height,
                                 GfxImageColorMap *colorMap,
+                                POPPLER_INTERPOLATE
                                 Stream *maskStr,
                                 int maskWidth, int maskHeight,
-                                GfxImageColorMap *maskColorMap)
+                                GfxImageColorMap *maskColorMap POPPLER_MASK_INTERPOLATE)
 {
     msg("<debug> drawSoftMaskedImage %dx%d (%dx%d) streamkind=%d", width, height, maskWidth, maskHeight, str->getKind());
     if(invalid_size(width,height)) return;
@@ -1776,10 +1783,10 @@ void BitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *
     CopyStream*cpystr = new CopyStream(str, height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8));
     str = cpystr->getStream();
 
-    boolpolydev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
+    boolpolydev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, POPPLER_INTERPOLATE_ARG maskStr, maskWidth, maskHeight, maskColorMap POPPLER_MASK_INTERPOLATE_ARG);
     gfxbbox_t bbox=getImageBBox(state);
     checkNewBitmap(bbox.xmin, bbox.ymin, ceil(bbox.xmax), ceil(bbox.ymax));
-    rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
+    rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, POPPLER_INTERPOLATE_ARG maskStr, maskWidth, maskHeight, maskColorMap POPPLER_MASK_INTERPOLATE_ARG);
     delete cpystr;
     dbg_newdata("softmaskimage");
 }