r23589 by jghali - #16086: Unblend colors that are preblended with matte <Pontobart>

scribus-commit scribus-commit at lists.scribus.net
Sat Apr 11 14:03:21 UTC 2020


Author: jghali
Date: Sat Apr 11 14:03:21 2020
New Revision: 23589

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23589
Log:
#16086: Unblend colors that are preblended with matte <Pontobart>

Modified:
    trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp

Modified: trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23589&path=/trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp	(original)
+++ trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp	Sat Apr 11 14:03:21 2020
@@ -53,6 +53,20 @@
 		// There are cases where both intersections are not empty but one of them is quite
 		// complicated with several subpaths, etc. We return the simpler one.
 		return (ret_a.elementCount() <= ret_b.elementCount()) ? ret_a : ret_b;
+	}
+
+	// Invert preblending matte values into the color values. Assuming that c and alpha are RGBA components
+	// between 0 and 255.
+	int unblendMatte(int c, int alpha, int matte)
+	{
+		if (alpha == 0)
+			return matte;
+		int ret = matte + ((c - matte) * 255) / alpha;
+		if (ret < 0)
+			return 0;
+		if (ret > 255)
+			return 255;
+		return ret;
 	}
 }
 
@@ -2525,18 +2539,36 @@
 	if ((maskWidth != width) || (maskHeight != height))
 		*image = image->scaled(maskWidth, maskHeight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
 	QImage res = image->convertToFormat(QImage::Format_ARGB32);
-	unsigned char cc, cm, cy, ck;
+
+	int matteRc, matteGc, matteBc;
+	const GfxColor *matteColor = maskColorMap->getMatteColor();
+	if (matteColor != nullptr)
+	{
+		GfxRGB matteRgb;
+		colorMap->getColorSpace()->getRGB(matteColor, &matteRgb);
+		matteRc = qRound(colToDbl(matteRgb.r) * 255);
+		matteGc = qRound(colToDbl(matteRgb.g) * 255);
+		matteBc = qRound(colToDbl(matteRgb.b) * 255);
+	}
+
+	unsigned char cr, cg, cb, ca;
 	int s = 0;
 	for (int yi=0; yi < res.height(); ++yi)
 	{
 		QRgb *t = (QRgb*)(res.scanLine( yi ));
 		for (int xi=0; xi < res.width(); ++xi)
 		{
-			cc = qRed(*t);
-			cm = qGreen(*t);
-			cy = qBlue(*t);
-			ck = mbuffer[s];
-			(*t) = qRgba(cc, cm, cy, ck);
+			cr = qRed(*t);
+			cg = qGreen(*t);
+			cb = qBlue(*t);
+			ca = mbuffer[s];
+			if (matteColor != nullptr)
+			{
+				cr = unblendMatte(cr, ca, matteRc);
+				cg = unblendMatte(cg, ca, matteGc);
+				cb = unblendMatte(cb, ca, matteBc);
+			}
+			(*t) = qRgba(cr, cg, cb, ca);
 			s++;
 			t++;
 		}




More information about the scribus-commit mailing list