View Issue Details

IDProjectCategoryView StatusLast Update
0016086ScribusPDFpublic2020-04-11 14:03
ReporterPontobart Assigned Tojghali  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version1.5.6.svn 
Target VersionFixed in Version1.5.6.svn 
Summary0016086: Unblend colors that are preblended with matte
DescriptionThe following document is currently not imported correctly: https://bugs.ghostscript.com/attachment.cgi?id=12909 as preblended colors are not handled properly. The attached fix tries to improve this.
TagsNo tags attached.
PatchNo

Activities

Pontobart

2020-04-11 13:28

reporter  

unblend_matte.diff (2,137 bytes)
Index: scribus/plugins/import/pdf/slaoutput.cpp
===================================================================
--- scribus/plugins/import/pdf/slaoutput.cpp	(Revision 23587)
+++ scribus/plugins/import/pdf/slaoutput.cpp	(Arbeitskopie)
@@ -54,6 +54,20 @@
 		// 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;
+	}
 }
 
 LinkSubmitForm::LinkSubmitForm(Object *actionObj)
@@ -2506,7 +2520,19 @@
 	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)
 	{
@@ -2513,11 +2539,17 @@
 		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++;
 		}
unblend_matte.diff (2,137 bytes)

jghali

2020-04-11 14:03

administrator   ~0047511

Applied, thanks!

Issue History

Date Modified Username Field Change
2020-04-11 13:28 Pontobart New Issue
2020-04-11 13:28 Pontobart File Added: unblend_matte.diff
2020-04-11 14:03 jghali Assigned To => jghali
2020-04-11 14:03 jghali Status new => resolved
2020-04-11 14:03 jghali Resolution open => fixed
2020-04-11 14:03 jghali Fixed in Version => 1.5.6.svn
2020-04-11 14:03 jghali Note Added: 0047511