Dear Poppler developers,

Albert Astals Cid schrieb:
> El Dimarts, 18 de novembre de 2014, a les 12:52:34, Volker Grabsch va 
> escriure:
> > Dear Poppler developers,
> > 
> > I have the task to render PDF documents and to trace back each output
> > pixel to the object(s) that were rendered at this place.  To achieve
> > this, Poppler is a great help, so I'd like to contribute something
> > back.  Attached is the second smallest patch (see below) I came up
> > with.
> > 
> > Do you think it makes sense to include this feature in Poppler?
> 
> Thanks for the patch :)

Attached is an improved version of the patch.  There was one nasty
typo, and I adjusted the interface so it transports the source alpha
in addition to the coordinates.

(I needed the alpha because there are lots of pixels "drawn" with
source alpha == 0, so a pixel tracer must be able to filter these
out.)

> I am not totally sure it makes sense, seems a bit of a corner case feature 
> and 
> the more code we include the more maintainance overhead we have (and we are 
> really low on manpower).

I believe it would be nice if a PDF viewer could highlight individual
PDF objects - in their original form as well as what's left after
being overlapped by other objects.

Nevertheless, this feature is quite special, that's for sure.

> What do other think?

Indeed, it would be nice to read some more opinions on that!


Gruß
Volker

-- 
Volker Grabsch
---<<(())>>---
commit 68dc615001052d11f7744d2ce4beed441a9daf44
Author: Volker Grabsch <[email protected]>
Date:   Fri Nov 14 14:54:58 2014 +0100

    Add support for pixel tracer in SplashOutputDev

diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc
index 0eaeb79..ee1d7dd 100644
--- a/poppler/SplashOutputDev.cc
+++ b/poppler/SplashOutputDev.cc
@@ -1733,6 +1733,10 @@ void SplashOutputDev::setOverprintMask(GfxColorSpace *colorSpace,
 #endif
 }
 
+void SplashOutputDev::setPixelTracer(SplashPixelTracer *pixelTracer) {
+  splash->setPixelTracer(pixelTracer);
+}
+
 void SplashOutputDev::updateBlendMode(GfxState *state) {
   splash->setBlendFunc(splashOutBlendFuncs[state->getBlendMode()]);
 }
diff --git a/poppler/SplashOutputDev.h b/poppler/SplashOutputDev.h
index efbb865..2f72089 100644
--- a/poppler/SplashOutputDev.h
+++ b/poppler/SplashOutputDev.h
@@ -52,6 +52,7 @@ class SplashFont;
 class T3FontCache;
 struct T3FontCacheTag;
 struct T3GlyphStack;
+struct SplashPixelTracer;
 struct SplashTransparencyGroup;
 
 //------------------------------------------------------------------------
@@ -361,6 +362,8 @@ public:
 
   void setFreeTypeHinting(GBool enable, GBool enableSlightHinting);
 
+  void setPixelTracer(SplashPixelTracer *pixelTracer);
+
 protected:
   void doUpdateFont(GfxState *state);
 
diff --git a/splash/Splash.cc b/splash/Splash.cc
index fde272a..375d581 100644
--- a/splash/Splash.cc
+++ b/splash/Splash.cc
@@ -163,6 +163,9 @@ struct SplashPipe {
 
   // the "run" function
   void (Splash::*run)(SplashPipe *pipe);
+
+  // the original "run" function if pixel tracer is present
+  void (Splash::*origRun)(SplashPipe *pipe);
 };
 
 SplashPipeResultColorCtrl Splash::pipeResultColorNoAlphaBlend[] = {
@@ -339,6 +342,12 @@ inline void Splash::pipeInit(SplashPipe *pipe, int x, int y,
 #endif
     }
   }
+
+  // inject pixel tracer if present
+  if (pixelTracer != NULL) {
+      pipe->origRun = pipe->run;
+      pipe->run = &Splash::pipeRunPixelTracer;
+  }
 }
 
 // general case
@@ -1320,6 +1329,15 @@ void Splash::pipeRunAADeviceN8(SplashPipe *pipe) {
 }
 #endif
 
+// run pixel tracer, then call original "run" function
+void Splash::pipeRunPixelTracer(SplashPipe *pipe) {
+  unsigned char alpha = pipe->aInput;
+  if (state->softMask) alpha = div255(alpha * (*pipe->softMaskPtr));
+  if (pipe->usesShape) alpha = div255(alpha * pipe->shape);
+  pixelTracer->tracePixel(pipe->x, pipe->y, alpha);
+  (this->*pipe->origRun)(pipe);
+}
+
 inline void Splash::pipeSetXY(SplashPipe *pipe, int x, int y) {
   pipe->x = x;
   pipe->y = y;
@@ -1606,6 +1624,7 @@ Splash::Splash(SplashBitmap *bitmapA, GBool vectorAntialiasA,
   clearModRegion();
   debugMode = gFalse;
   alpha0Bitmap = NULL;
+  pixelTracer = NULL;
 }
 
 Splash::Splash(SplashBitmap *bitmapA, GBool vectorAntialiasA,
@@ -1634,6 +1653,7 @@ Splash::Splash(SplashBitmap *bitmapA, GBool vectorAntialiasA,
   clearModRegion();
   debugMode = gFalse;
   alpha0Bitmap = NULL;
+  pixelTracer = NULL;
 }
 
 Splash::~Splash() {
diff --git a/splash/Splash.h b/splash/Splash.h
index cf98e6c..12f2809 100644
--- a/splash/Splash.h
+++ b/splash/Splash.h
@@ -81,6 +81,15 @@ enum SplashPipeResultColorCtrl {
 };
 
 //------------------------------------------------------------------------
+
+class SplashPixelTracer {
+public:
+  SplashPixelTracer() {}
+  virtual ~SplashPixelTracer() {}
+  virtual void tracePixel(std::size_t x, std::size_t y, unsigned char alpha) = 0;
+};
+
+//------------------------------------------------------------------------
 // Splash
 //------------------------------------------------------------------------
 
@@ -280,6 +289,9 @@ public:
   // Draw a gouraud triangle shading.
   GBool gouraudTriangleShadedFill(SplashGouraudColor *shading);
 
+  // Set pixel tracer
+  void setPixelTracer(SplashPixelTracer *pixelTracerA) { pixelTracer = pixelTracerA; }
+
 private:
 
   void pipeInit(SplashPipe *pipe, int x, int y,
@@ -306,6 +318,7 @@ private:
   void pipeRunAACMYK8(SplashPipe *pipe);
   void pipeRunAADeviceN8(SplashPipe *pipe);
 #endif
+  void pipeRunPixelTracer(SplashPipe *pipe);
   void pipeSetXY(SplashPipe *pipe, int x, int y);
   void pipeIncX(SplashPipe *pipe);
   void drawPixel(SplashPipe *pipe, int x, int y, GBool noClip);
@@ -421,6 +434,7 @@ private:
   GBool vectorAntialias;
   GBool inShading;
   GBool debugMode;
+  SplashPixelTracer *pixelTracer;
 };
 
 #endif
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to