poppler: fix tilingPatternFill()
[swftools.git] / lib / pdf / FullBitmapOutputDev.cc
index d35956d..90a3985 100644 (file)
 #include <stdlib.h>
 #include <stdio.h>
 #include <memory.h>
-#include "config.h"
 #include "FullBitmapOutputDev.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"
@@ -87,9 +95,9 @@ void FullBitmapOutputDev::setClip(int x1,int y1,int x2,int y2)
 void FullBitmapOutputDev::setParameter(const char*key, const char*value)
 {
 }
-void FullBitmapOutputDev::preparePage(int pdfpage, int outputpage)
+void FullBitmapOutputDev::setPageMap(int*pagemap, int pagemap_len)
 {
-    gfxdev->preparePage(pdfpage, outputpage);
+    gfxdev->setPageMap(pagemap, pagemap_len);
 }
 
 static void getBitmapBBox(Guchar*alpha, int width, int height, int*xmin, int*ymin, int*xmax, int*ymax)
@@ -167,13 +175,11 @@ void FullBitmapOutputDev::flushBitmap()
        gfxcolor_t*out = &img->data[y*rangex];
        Guchar*ain = &alpha[(y+ymin)*width+xmin];
        for(x=0;x<rangex;x++) {
-           /* according to endPage()/compositeBackground() in xpdf/SplashOutputDev.cc, we
-              have to premultiply alpha (mix background and pixel according to the alpha channel).
-           */
-           out[x].r = (in[x*3+0]*ain[x])/255;
-           out[x].g = (in[x*3+1]*ain[x])/255;
-           out[x].b = (in[x*3+2]*ain[x])/255;
-           out[x].a = ain[x];
+           // blend against a white background
+           out[x].r = (in[x*3+0]*ain[x])/255 + 255-ain[x];
+           out[x].g = (in[x*3+1]*ain[x])/255 + 255-ain[x];
+           out[x].b = (in[x*3+2]*ain[x])/255 + 255-ain[x];
+           out[x].a = 255;//ain[x];
        }
     }
     /* transform bitmap rectangle to "device space" */
@@ -192,17 +198,27 @@ void FullBitmapOutputDev::flushBitmap()
     dev->fillbitmap(dev, line, img, &m, 0);
     gfxline_free(line);
 
-    memset(rgbdev->getBitmap()->getAlphaPtr(), 0, rgbdev->getBitmap()->getWidth()*rgbdev->getBitmap()->getHeight());
-    memset(rgbdev->getBitmap()->getDataPtr(), 0, rgbdev->getBitmap()->getRowSize()*rgbdev->getBitmap()->getHeight());
-
     free(img->data);img->data=0;free(img);img=0;
 }
 
-void FullBitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
+GBool FullBitmapOutputDev::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 FullBitmapOutputDev::startPage(int pageNum, GfxState *state)
 {
     double x1,y1,x2,y2;
-    state->transform(crop_x1,crop_y1,&x1,&y1);
-    state->transform(crop_x2,crop_y2,&x2,&y2);
+    PDFRectangle *r = page->getCropBox();
+    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;}
     
@@ -219,8 +235,8 @@ void FullBitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1
     this->height = (int)(y2-y1);
 
     msg("<debug> startPage");
-    rgbdev->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);
+    gfxdev->startPage(pageNum, state);
 }
 
 void FullBitmapOutputDev::endPage()
@@ -400,27 +416,19 @@ void FullBitmapOutputDev::eoFill(GfxState *state)
     msg("<debug> eoFill");
     rgbdev->eoFill(state);
 }
-#if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
-void FullBitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
+POPPLER_TILING_PATERN_RETURN FullBitmapOutputDev::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");
-    rgbdev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
-}
-#else
-void FullBitmapOutputDev::tilingPatternFill(GfxState *state, Gfx *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");
-    rgbdev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
-}
+#ifdef HAVE_POPPLER
+    return
 #endif
+    rgbdev->tilingPatternFill(state, POPPLER_TILING_PATERN_GFX_ARG str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
+}
 
 GBool FullBitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading) 
 {
@@ -594,3 +602,6 @@ void FullBitmapOutputDev::clearSoftMask(GfxState *state)
     msg("<debug> clearSoftMask");
     rgbdev->clearSoftMask(state);
 }
+
+
+