[poppler] Blend mode enhancements for splash, patch for CMYK branch

Thomas Freitag Thomas.Freitag at kabelmail.de
Fri Jul 13 01:04:53 PDT 2012


Hi Albert,

After commiting the patch for Bug #49523 I can now continue to process 
my splash queue:
When implementing DeviceN support for splash I already encountered, that 
the blend mode support in the CMYK branch is somewhat less than perfect. 
But this has nothing to do with DeviceN itself, and because it is just a 
small change I continue with this one.
The attached patch improves the blend mode handling in splash in the 
CMYK branch. You can test it i.e. with the -jpegcmyk option of pdftoppm 
and see the improvements for standard separable blend modes on 
1und1_DSL_Flyer_partner.pdf, which uses at least 5 different standard 
separable blend modes as far as I can remember.
The changes for the standard nonseparable blend modes just repair the 
changes necessary for the standard separable blend modes so that the 
output for them is still the same. You can check that at least with some 
of the modes with the test_*alex*.pdf files I sent You a few month ago 
in private.

Cheers,
Thomas

-------------- next part --------------
diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc
index abdcea4..9e07060 100644
--- a/poppler/SplashOutputDev.cc
+++ b/poppler/SplashOutputDev.cc
@@ -661,11 +661,6 @@ static void splashOutBlendSoftLight(SplashColorPtr src, SplashColorPtr dest,
     SplashColor rgbSrc;
     SplashColor rgbDest;
     SplashColor rgbBlend;
-    for (i = 0; i < 4; i++) {
-      // convert back to subtractive (s. Splash.cc)
-      src[i] = 0xff - src[i];
-      dest[i] = 0xff - dest[i];
-    }
     cmykToRGB(src, rgbSrc);
     cmykToRGB(dest, rgbDest);
     for (i = 0; i < 3; ++i) {
@@ -681,10 +676,6 @@ static void splashOutBlendSoftLight(SplashColorPtr src, SplashColorPtr dest,
       }
     }
     rgbToCMYK(rgbBlend, blend);
-    for (i = 0; i < 4; i++) {
-      // convert back to additive (s. Splash.cc)
-      blend[i] = 0xff - blend[i];
-    }
   } else
 #endif
   {
@@ -848,6 +839,8 @@ static void splashOutBlendHue(SplashColorPtr src, SplashColorPtr dest,
   Guchar r0, g0, b0;
 #ifdef SPLASH_CMYK
   Guchar r1, g1, b1;
+  int i;
+  SplashColor src2, dest2;
 #endif
 
   switch (cm) {
@@ -866,15 +859,24 @@ static void splashOutBlendHue(SplashColorPtr src, SplashColorPtr dest,
     break;
 #if SPLASH_CMYK
   case splashModeCMYK8:
+    for (i = 0; i < 4; i++) {
+      // convert to additive
+      src2[i] = 0xff - src[i];
+      dest2[i] = 0xff - dest[i];
+    }
     // NB: inputs have already been converted to additive mode
-    setSat(src[0], src[1], src[2], getSat(dest[0], dest[1], dest[2]),
+    setSat(src2[0], src2[1], src2[2], getSat(dest2[0], dest2[1], dest2[2]),
 	   &r0, &g0, &b0);
-    setLum(r0, g0, b0, getLum(dest[0], dest[1], dest[2]),
+    setLum(r0, g0, b0, getLum(dest2[0], dest2[1], dest2[2]),
 	   &r1, &g1, &b1);
     blend[0] = r1;
     blend[1] = g1;
     blend[2] = b1;
-    blend[3] = dest[3];
+    blend[3] = dest2[3];
+    for (i = 0; i < 4; i++) {
+      // convert back to subtractive
+      blend[i] = 0xff - blend[i];
+    }
     break;
 #endif
   }
@@ -886,6 +888,8 @@ static void splashOutBlendSaturation(SplashColorPtr src, SplashColorPtr dest,
   Guchar r0, g0, b0;
 #ifdef SPLASH_CMYK
   Guchar r1, g1, b1;
+  int i;
+  SplashColor src2, dest2;
 #endif
 
   switch (cm) {
@@ -904,15 +908,23 @@ static void splashOutBlendSaturation(SplashColorPtr src, SplashColorPtr dest,
     break;
 #if SPLASH_CMYK
   case splashModeCMYK8:
-    // NB: inputs have already been converted to additive mode
-    setSat(dest[0], dest[1], dest[2], getSat(src[0], src[1], src[2]),
+    for (i = 0; i < 4; i++) {
+      // convert to additive
+      src2[i] = 0xff - src[i];
+      dest2[i] = 0xff - dest[i];
+    }
+    setSat(dest2[0], dest2[1], dest2[2], getSat(src2[0], src2[1], src2[2]),
 	   &r0, &g0, &b0);
-    setLum(r0, g0, b0, getLum(dest[0], dest[1], dest[2]),
+    setLum(r0, g0, b0, getLum(dest2[0], dest2[1], dest2[2]),
 	   &r1, &g1, &b1);
     blend[0] = r1;
     blend[1] = g1;
     blend[2] = b1;
-    blend[3] = dest[3];
+    blend[3] = dest2[3];
+    for (i = 0; i < 4; i++) {
+      // convert back to subtractive
+      blend[i] = 0xff - blend[i];
+    }
     break;
 #endif
   }
@@ -922,6 +934,8 @@ static void splashOutBlendColor(SplashColorPtr src, SplashColorPtr dest,
 				SplashColorPtr blend, SplashColorMode cm) {
 #if SPLASH_CMYK
   Guchar r, g, b;
+  int i;
+  SplashColor src2, dest2;
 #endif
 
   switch (cm) {
@@ -938,13 +952,21 @@ static void splashOutBlendColor(SplashColorPtr src, SplashColorPtr dest,
     break;
 #if SPLASH_CMYK
   case splashModeCMYK8:
-    // NB: inputs have already been converted to additive mode
-    setLum(src[0], src[1], src[2], getLum(dest[0], dest[1], dest[2]),
+    for (i = 0; i < 4; i++) {
+      // convert to additive
+      src2[i] = 0xff - src[i];
+      dest2[i] = 0xff - dest[i];
+    }
+    setLum(src2[0], src2[1], src2[2], getLum(dest2[0], dest2[1], dest2[2]),
 	   &r, &g, &b);
     blend[0] = r;
     blend[1] = g;
     blend[2] = b;
-    blend[3] = dest[3];
+    blend[3] = dest2[3];
+    for (i = 0; i < 4; i++) {
+      // convert back to subtractive
+      blend[i] = 0xff - blend[i];
+    }
     break;
 #endif
   }
@@ -955,6 +977,8 @@ static void splashOutBlendLuminosity(SplashColorPtr src, SplashColorPtr dest,
 				     SplashColorMode cm) {
 #if SPLASH_CMYK
   Guchar r, g, b;
+  int i;
+  SplashColor src2, dest2;
 #endif
 
   switch (cm) {
@@ -971,13 +995,21 @@ static void splashOutBlendLuminosity(SplashColorPtr src, SplashColorPtr dest,
     break;
 #if SPLASH_CMYK
   case splashModeCMYK8:
-    // NB: inputs have already been converted to additive mode
-    setLum(dest[0], dest[1], dest[2], getLum(src[0], src[1], src[2]),
+    for (i = 0; i < 4; i++) {
+      // convert to additive
+      src2[i] = 0xff - src[i];
+      dest2[i] = 0xff - dest[i];
+    }
+    setLum(dest2[0], dest2[1], dest2[2], getLum(src2[0], src2[1], src2[2]),
 	   &r, &g, &b);
     blend[0] = r;
     blend[1] = g;
     blend[2] = b;
-    blend[3] = src[3];
+    blend[3] = src2[3];
+    for (i = 0; i < 4; i++) {
+      // convert back to subtractive
+      blend[i] = 0xff - blend[i];
+    }
     break;
 #endif
   }
diff --git a/splash/Splash.cc b/splash/Splash.cc
index b927e5e..d2d965a 100644
--- a/splash/Splash.cc
+++ b/splash/Splash.cc
@@ -337,9 +337,6 @@ void Splash::pipeRun(SplashPipe *pipe) {
   SplashColorPtr cSrc;
   Guchar cResult0, cResult1, cResult2, cResult3;
   int t;
-#if SPLASH_CMYK
-  SplashColor cSrc2, cDest2;
-#endif
 
   //----- source color
 
@@ -521,25 +518,6 @@ void Splash::pipeRun(SplashPipe *pipe) {
     //----- blend function
 
     if (state->blendFunc) {
-#if SPLASH_CMYK
-      if (bitmap->mode == splashModeCMYK8) {
-	// convert colors to additive
-	cSrc2[0] = 0xff - cSrc[0];
-	cSrc2[1] = 0xff - cSrc[1];
-	cSrc2[2] = 0xff - cSrc[2];
-	cSrc2[3] = 0xff - cSrc[3];
-	cDest2[0] = 0xff - cDest[0];
-	cDest2[1] = 0xff - cDest[1];
-	cDest2[2] = 0xff - cDest[2];
-	cDest2[3] = 0xff - cDest[3];
-	(*state->blendFunc)(cSrc2, cDest2, cBlend, bitmap->mode);
-	// convert result back to subtractive
-	cBlend[0] = 0xff - cBlend[0];
-	cBlend[1] = 0xff - cBlend[1];
-	cBlend[2] = 0xff - cBlend[2];
-	cBlend[3] = 0xff - cBlend[3];
-      } else
-#endif
       (*state->blendFunc)(cSrc, cDest, cBlend, bitmap->mode);
     }
 


More information about the poppler mailing list