r18546 by fschmid - Added the missing drawMaskedImage function.

scribus-commit scribus-commit at lists.scribus.net
Sat Oct 12 10:35:58 UTC 2013


Author: fschmid
Date: Sat Oct 12 10:35:58 2013
New Revision: 18546

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=18546
Log:
Added the missing drawMaskedImage function.

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

Modified: trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18546&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 Oct 12 10:35:58 2013
@@ -2587,6 +2587,141 @@
 	delete[] mbuffer;
 }
 
+void SlaOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,  int width, int height, GfxImageColorMap *colorMap, GBool interpolate, Stream *maskStr, int maskWidth, int maskHeight, GBool maskInvert, GBool maskInterpolate)
+{
+	ImageStream * imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
+	imgStr->reset();
+	unsigned int *dest = 0;
+	unsigned char * buffer = new unsigned char[width * height * 4];
+	QImage * image = 0;
+	for (int y = 0; y < height; y++)
+	{
+		dest = (unsigned int *)(buffer + y * 4 * width);
+		Guchar * pix = imgStr->getLine();
+		colorMap->getRGBLine(pix, dest, width);
+	}
+	image = new QImage(buffer, width, height, QImage::Format_RGB32);
+	if (image == NULL || image->isNull())
+	{
+		delete imgStr;
+		delete[] buffer;
+		delete image;
+		return;
+	}
+	ImageStream *mskStr = new ImageStream(maskStr, maskWidth, 1, 1);
+	mskStr->reset();
+	Guchar *mdest = 0;
+	int invert_bit = maskInvert ? 1 : 0;
+	unsigned char * mbuffer = new unsigned char[maskWidth * maskHeight];
+	for (int y = 0; y < maskHeight; y++)
+	{
+		mdest = (Guchar *)(mbuffer + y * maskWidth);
+		Guchar * pix = mskStr->getLine();
+		for (int x = 0; x < maskWidth; x++)
+		{
+			if (pix[x] ^ invert_bit)
+				*mdest++ = 0;
+			else
+				*mdest++ = 255;
+		}
+	}
+	if ((maskWidth != width) || (maskHeight != height))
+	{
+		delete imgStr;
+		delete[] buffer;
+		delete image;
+		delete mskStr;
+		delete[] mbuffer;
+		return;
+	}
+	QImage res = image->convertToFormat(QImage::Format_ARGB32);
+	unsigned char cc, cm, cy, ck;
+	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);
+			s++;
+			t++;
+		}
+	}
+	double *ctm;
+	ctm = state->getCTM();
+	double xCoor = m_doc->currentPage()->xOffset();
+	double yCoor = m_doc->currentPage()->yOffset();
+	QRectF crect = QRectF(0, 0, width, height);
+	m_ctm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, ctm[2] + ctm[4], ctm[3] + ctm[5]);
+	QLineF cline = QLineF(0, 0, width, 0);
+	QLineF tline = m_ctm.map(cline);
+	QRectF trect = m_ctm.mapRect(crect);
+	double sx = m_ctm.m11();
+	double sy = m_ctm.m22();
+	QTransform mm = QTransform(ctm[0] / width, ctm[1] / width, -ctm[2] / height, -ctm[3] / height, 0, 0);
+	if ((mm.type() == QTransform::TxShear) || (mm.type() == QTransform::TxRotate))
+	{
+		mm.reset();
+		mm.rotate(-tline.angle());
+	}
+	else
+	{
+		mm.reset();
+		if (sx < 0)
+			mm.scale(-1, 1);
+		if (sy < 0)
+			mm.scale(1, -1);
+	}
+	res = res.transformed(mm);
+	int z = m_doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified, xCoor + trect.x(), yCoor + trect.y(), trect.width(), trect.height(), 0, CommonStrings::None, CommonStrings::None, true);
+	PageItem* ite = m_doc->Items->at(z);
+	ite->SetRectFrame();
+	m_doc->setRedrawBounding(ite);
+	ite->Clip = FlattenPath(ite->PoLine, ite->Segments);
+	ite->setTextFlowMode(PageItem::TextFlowDisabled);
+	ite->setFillShade(100);
+	ite->setLineShade(100);
+	ite->setFillEvenOdd(false);
+	ite->setFillTransparency(1.0 - state->getFillOpacity());
+	ite->setFillBlendmode(getBlendMode(state));
+	m_doc->AdjustItemSize(ite);
+	QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_pdf_XXXXXX.png");
+	tempFile->setAutoRemove(false);
+	if (tempFile->open())
+	{
+		QString fileName = getLongPathName(tempFile->fileName());
+		if (!fileName.isEmpty())
+		{
+			tempFile->close();
+			ite->isInlineImage = true;
+			ite->isTempFile = true;
+			res.save(fileName, "PNG");
+			m_doc->loadPict(fileName, ite);
+		//	ite->setImageScalingMode(false, false);
+			m_Elements->append(ite);
+			if (m_groupStack.count() != 0)
+			{
+				m_groupStack.top().Items.append(ite);
+				applyMask(ite);
+			}
+		}
+		else
+			m_doc->Items->removeAll(ite);
+	}
+	else
+		m_doc->Items->removeAll(ite);
+	delete tempFile;
+	delete imgStr;
+	delete[] buffer;
+	delete image;
+	delete mskStr;
+	delete[] mbuffer;
+}
+
 void SlaOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, GBool interpolate, int *maskColors, GBool inlineImg)
 {
 	ImageStream * imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
@@ -3867,13 +4002,14 @@
 			PLineJoin = Qt::BevelJoin;
 			break;
 	}
+	double lw = state->getLineWidth();
 	double *dashPattern;
 	int dashLength;
 	state->getLineDash(&dashPattern, &dashLength, &DashOffset);
 	QVector<double> pattern(dashLength);
 	for (int i = 0; i < dashLength; ++i)
 	{
-		pattern[i] = dashPattern[i];
+		pattern[i] = dashPattern[i] / lw;
 	}
 	DashValues = pattern;
 }

Modified: trunk/Scribus/scribus/plugins/import/pdf/slaoutput.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18546&path=/trunk/Scribus/scribus/plugins/import/pdf/slaoutput.h
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/slaoutput.h (original)
+++ trunk/Scribus/scribus/plugins/import/pdf/slaoutput.h Sat Oct 12 10:35:58 2013
@@ -227,7 +227,7 @@
 				   GBool interpolate,
 				   Stream *maskStr,
 				   int maskWidth, int maskHeight,
-				   GBool maskInvert, GBool maskInterpolate) { qDebug() << "Draw Masked Image"; }
+				   GBool maskInvert, GBool maskInterpolate); // { qDebug() << "Draw Masked Image"; }
 
 	//----- transparency groups and soft masks
 	virtual void beginTransparencyGroup(GfxState *state, double *bbox, GfxColorSpace * /*blendingColorSpace*/, GBool /*isolated*/, GBool /*knockout*/, GBool /*forSoftMask*/);




More information about the scribus-commit mailing list