Fix slow rendering of pdf with a lot of image masks in pattern colorspace

Makes it around 8 times faster
diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc
index 32f01d3..b70183e 100644
--- a/poppler/CairoOutputDev.cc
+++ b/poppler/CairoOutputDev.cc
@@ -25,7 +25,7 @@
 // Copyright (C) 2008, 2009 Chris Wilson <chris@chris-wilson.co.uk>
 // Copyright (C) 2008 Hib Eris <hib@hiberis.nl>
 // Copyright (C) 2009, 2010 David Benjamin <davidben@mit.edu>
-// Copyright (C) 2011 Thomas Freitag <Thomas.Freitag@alfa.de>
+// Copyright (C) 2011, 2012 Thomas Freitag <Thomas.Freitag@alfa.de>
 // Copyright (C) 2012 Patrick Pfeifer <p2000@mailinator.com>
 //
 // To see a description of the changes please see the Changelog file that
@@ -1858,7 +1858,7 @@
 
 void CairoOutputDev::setSoftMaskFromImageMask(GfxState *state, Object *ref, Stream *str,
 				   int width, int height, GBool invert,
-				   GBool inlineImg) {
+				   GBool inlineImg, double *baseMatrix) {
 
   /* FIXME: Doesn't the image mask support any colorspace? */
   cairo_set_source (cairo, fill_pattern);
@@ -1922,7 +1922,7 @@
                          gTrue, gFalse, gFalse);
 }
 
-void CairoOutputDev::unsetSoftMaskFromImageMask(GfxState *state) {
+void CairoOutputDev::unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix) {
   double bbox[4] = {0,0,1,1}; // dummy
 
   endTransparencyGroup(state);
diff --git a/poppler/CairoOutputDev.h b/poppler/CairoOutputDev.h
index ae85433..df76975 100644
--- a/poppler/CairoOutputDev.h
+++ b/poppler/CairoOutputDev.h
@@ -20,7 +20,7 @@
 // Copyright (C) 2006-2011 Carlos Garcia Campos <carlosgc@gnome.org>
 // Copyright (C) 2008, 2009, 2011, 2012 Adrian Johnson <ajohnson@redneon.com>
 // Copyright (C) 2008 Michael Vrable <mvrable@cs.ucsd.edu>
-// Copyright (C) 2010, 2011 Thomas Freitag <Thomas.Freitag@alfa.de>
+// Copyright (C) 2010-2012 Thomas Freitag <Thomas.Freitag@alfa.de>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -202,8 +202,8 @@
   virtual void setSoftMaskFromImageMask(GfxState *state,
 					Object *ref, Stream *str,
 					int width, int height, GBool invert,
-					GBool inlineImg);
-  virtual void unsetSoftMaskFromImageMask(GfxState *state);
+					GBool inlineImg, double *baseMatrix);
+  virtual void unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix);
   void drawImageMaskPrescaled(GfxState *state, Object *ref, Stream *str,
 			      int width, int height, GBool invert, GBool interpolate,
 			      GBool inlineImg);
diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index e9d6ac3..7c0c88b 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -2030,7 +2030,7 @@
   saveState();
 
   out->setSoftMaskFromImageMask(state, ref, str,
-				width, height, invert, inlineImg);
+				width, height, invert, inlineImg, baseMatrix);
 
   state->clearPath();
   state->moveTo(0, 0);
@@ -2040,7 +2040,7 @@
   state->closePath();
   doPatternText();
 
-  out->unsetSoftMaskFromImageMask(state);
+  out->unsetSoftMaskFromImageMask(state, baseMatrix);
   restoreState();
 }
 
diff --git a/poppler/OutputDev.cc b/poppler/OutputDev.cc
index 43b7f5b..c52f611 100644
--- a/poppler/OutputDev.cc
+++ b/poppler/OutputDev.cc
@@ -18,6 +18,7 @@
 // Copyright (C) 2007 Adrian Johnson <ajohnson@redneon.com>
 // Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
 // Copyright (C) 2009 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2012 Thomas Freitag <Thomas.Freitag@alfa.de>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -111,11 +112,11 @@
 void OutputDev::setSoftMaskFromImageMask(GfxState *state,
 					 Object *ref, Stream *str,
 					 int width, int height, GBool invert,
-					 GBool inlineImg) {
+					 GBool inlineImg, double *baseMatrix) {
   drawImageMask(state, ref, str, width, height, invert, gFalse, inlineImg);
 }
 
-void OutputDev::unsetSoftMaskFromImageMask(GfxState *state) {
+void OutputDev::unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix) {
   return;
 }
 
diff --git a/poppler/OutputDev.h b/poppler/OutputDev.h
index d739625..803d922 100644
--- a/poppler/OutputDev.h
+++ b/poppler/OutputDev.h
@@ -17,7 +17,7 @@
 // Copyright (C) 2006 Thorkild Stray <thorkild@ifi.uio.no>
 // Copyright (C) 2007 Jeff Muizelaar <jeff@infidigm.net>
 // Copyright (C) 2007, 2011 Adrian Johnson <ajohnson@redneon.com>
-// Copyright (C) 2009-2011 Thomas Freitag <Thomas.Freitag@alfa.de>
+// Copyright (C) 2009-2012 Thomas Freitag <Thomas.Freitag@alfa.de>
 // Copyright (C) 2009, 2011 Carlos Garcia Campos <carlosgc@gnome.org>
 // Copyright (C) 2009 Albert Astals Cid <aacid@kde.org>
 // Copyright (C) 2010 Christian Feuersänger <cfeuersaenger@googlemail.com>
@@ -251,8 +251,8 @@
   virtual void setSoftMaskFromImageMask(GfxState *state,
 					Object *ref, Stream *str,
 					int width, int height, GBool invert,
-					GBool inlineImg);
-  virtual void unsetSoftMaskFromImageMask(GfxState *state);
+					GBool inlineImg, double *baseMatrix);
+  virtual void unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix);
   virtual void drawImage(GfxState *state, Object *ref, Stream *str,
 			 int width, int height, GfxImageColorMap *colorMap,
 			 GBool interpolate, int *maskColors, GBool inlineImg);
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 157b4b7..dac10d0 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -4946,13 +4946,13 @@
 
 void PSOutputDev::setSoftMaskFromImageMask(GfxState *state, Object *ref, Stream *str,
 				int width, int height, GBool invert,
-				GBool inlineImg) {
+				GBool inlineImg, double *baseMatrix) {
   if (level != psLevel1 && level != psLevel1Sep) {
     maskToClippingPath(str, width, height, invert);
   }
 }
 
-void PSOutputDev::unsetSoftMaskFromImageMask(GfxState * state) {
+void PSOutputDev::unsetSoftMaskFromImageMask(GfxState * state, double *baseMatrix) {
   if (level != psLevel1 && level != psLevel1Sep) {
     writePS("pdfImClipEnd\n");
   }
diff --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h
index 751ad8e..70aef9f 100644
--- a/poppler/PSOutputDev.h
+++ b/poppler/PSOutputDev.h
@@ -256,8 +256,8 @@
   virtual void setSoftMaskFromImageMask(GfxState *state,
 					Object *ref, Stream *str,
 					int width, int height, GBool invert,
-					GBool inlineImg);
-  virtual void unsetSoftMaskFromImageMask(GfxState *state);
+					GBool inlineImg, double *baseMatrix);
+  virtual void unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix);
   virtual void drawImage(GfxState *state, Object *ref, Stream *str,
 			 int width, int height, GfxImageColorMap *colorMap,
 			 GBool interpolate, int *maskColors, GBool inlineImg);
diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc
index 807e23a..0e956c7 100644
--- a/poppler/SplashOutputDev.cc
+++ b/poppler/SplashOutputDev.cc
@@ -2590,12 +2590,13 @@
 					       Object *ref, Stream *str,
 					       int width, int height,
 					       GBool invert,
-					       GBool inlineImg) {
+					       GBool inlineImg, double *baseMatrix) {
   double *ctm;
   SplashCoord mat[6];
   SplashOutImageMaskData imgMaskData;
   Splash *maskSplash;
   SplashColor maskColor;
+  double bbox[4] = {0, 0, 1, 1}; // default;
 
   if (state->getFillColorSpace()->isNonMarking()) {
     return;
@@ -2605,6 +2606,12 @@
   for (int i = 0; i < 6; ++i) {
     if (!isfinite(ctm[i])) return;
   }
+  
+  beginTransparencyGroup(state, bbox, NULL, gFalse, gFalse, gFalse);
+  baseMatrix[4] -= transpGroupStack->tx;
+  baseMatrix[5] -= transpGroupStack->ty;
+
+  ctm = state->getCTM();
   mat[0] = ctm[0];
   mat[1] = ctm[1];
   mat[2] = -ctm[2];
@@ -2618,28 +2625,6 @@
   imgMaskData.height = height;
   imgMaskData.y = 0;
 
-  /* from beginTransparencyGroup: */
-  // push a new stack entry
-  SplashTransparencyGroup *transpGroup = new SplashTransparencyGroup();
-  transpGroup->tx = 0;
-  transpGroup->ty = 0;
-  transpGroup->blendingColorSpace = NULL;
-  transpGroup->isolated = gFalse;
-  transpGroup->next = transpGroupStack;
-  transpGroupStack = transpGroup;
-  // save state
-  transpGroup->origBitmap = bitmap;
-  transpGroup->origSplash = splash;
-  //~ this ignores the blendingColorSpace arg
-  // create the temporary bitmap
-  bitmap = new SplashBitmap(bitmap->getWidth(), bitmap->getHeight(), bitmapRowPad, colorMode, gTrue,
-                            bitmapTopDown);
-  splash = new Splash(bitmap, vectorAntialias,
-                      transpGroup->origSplash->getScreen());
-  splash->blitTransparent(transpGroup->origBitmap, 0, 0, 0, 0, bitmap->getWidth(), bitmap->getHeight());
-  splash->setInNonIsolatedGroup(transpGroup->origBitmap, 0, 0);
-  transpGroup->tBitmap = bitmap;
-
   maskBitmap = new SplashBitmap(bitmap->getWidth(), bitmap->getHeight(), 1, splashModeMono8, gFalse);
   maskSplash = new Splash(maskBitmap, vectorAntialias);
   maskColor[0] = 0;
@@ -2652,7 +2637,7 @@
   str->close();
 }
 
-void SplashOutputDev::unsetSoftMaskFromImageMask(GfxState *state) {
+void SplashOutputDev::unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix) {
   double bbox[4] = {0,0,1,1}; // dummy
 
   /* transfer mask to alpha channel! */
@@ -2666,6 +2651,8 @@
   delete maskBitmap;
   maskBitmap = NULL;
   endTransparencyGroup(state);
+  baseMatrix[4] += transpGroupStack->tx;
+  baseMatrix[5] += transpGroupStack->ty;
   paintTransparencyGroup(state, bbox);
 }
 
diff --git a/poppler/SplashOutputDev.h b/poppler/SplashOutputDev.h
index 95a7f65..b70ec38 100644
--- a/poppler/SplashOutputDev.h
+++ b/poppler/SplashOutputDev.h
@@ -266,8 +266,8 @@
   virtual void setSoftMaskFromImageMask(GfxState *state,
 					Object *ref, Stream *str,
 					int width, int height, GBool invert,
-					GBool inlineImg);
-  virtual void unsetSoftMaskFromImageMask(GfxState *state);
+					GBool inlineImg, double *baseMatrix);
+  virtual void unsetSoftMaskFromImageMask(GfxState *state, double *baseMatrix);
   virtual void drawImage(GfxState *state, Object *ref, Stream *str,
 			 int width, int height, GfxImageColorMap *colorMap,
 			 GBool interpolate, int *maskColors, GBool inlineImg);