r22459 by jghali - avoid unnecessary conversions between QImage and QPixmap when creating thumbnails for PDF

scribus-commit scribus-commit at lists.scribus.net
Fri Mar 30 16:13:24 UTC 2018


Author: jghali
Date: Fri Mar 30 16:13:24 2018
New Revision: 22459

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22459
Log:
avoid unnecessary conversions between QImage and QPixmap when creating thumbnails for PDF

Modified:
    trunk/Scribus/scribus/pdflib.cpp
    trunk/Scribus/scribus/pdflib.h
    trunk/Scribus/scribus/pdflib_core.cpp
    trunk/Scribus/scribus/pdflib_core.h
    trunk/Scribus/scribus/plugins/scriptplugin/objpdffile.cpp
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribus.h

Modified: trunk/Scribus/scribus/pdflib.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22459&path=/trunk/Scribus/scribus/pdflib.cpp
==============================================================================
--- trunk/Scribus/scribus/pdflib.cpp	(original)
+++ trunk/Scribus/scribus/pdflib.cpp	Fri Mar 30 16:13:24 2018
@@ -14,7 +14,7 @@
 }
 
 bool PDFlib::doExport(const QString& fn, const QString& nam, int Components,
-			  const std::vector<int> & pageNs, const QMap<int,QPixmap> & thumbs)
+			  const std::vector<int> & pageNs, const QMap<int, QImage>& thumbs)
 {
 	return static_cast<PDFLibCore*>(m_impl)->doExport(fn, nam, Components, pageNs, thumbs);
 }

Modified: trunk/Scribus/scribus/pdflib.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22459&path=/trunk/Scribus/scribus/pdflib.h
==============================================================================
--- trunk/Scribus/scribus/pdflib.h	(original)
+++ trunk/Scribus/scribus/pdflib.h	Fri Mar 30 16:13:24 2018
@@ -11,9 +11,9 @@
 #include "scconfig.h"
 #include "scribusapi.h"
 
+#include <QImage>
 #include <QObject>
 #include <QMap>
-#include <QPixmap>
 #include <vector>
 
 class ScribusDoc;
@@ -52,7 +52,7 @@
 	 * \param thumbs A mapping of input (document) page numbers to pre-rendered thumbnails.
 	 */
 	bool doExport(const QString& fn, const QString& nam, int Components,
-				  const std::vector<int> & pageNs, const QMap<int,QPixmap> & thumbs);
+				  const std::vector<int> & pageNs, const QMap<int, QImage>& thumbs);
 
 	/**
 	 * Return an error message in case export has failed.

Modified: trunk/Scribus/scribus/pdflib_core.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22459&path=/trunk/Scribus/scribus/pdflib_core.cpp
==============================================================================
--- trunk/Scribus/scribus/pdflib_core.cpp	(original)
+++ trunk/Scribus/scribus/pdflib_core.cpp	Fri Mar 30 16:13:24 2018
@@ -47,7 +47,6 @@
 #include <QImage>
 #include <QList>
 #include <QPainterPath>
-#include <QPixmap>
 #include <QRect>
 #include <QRegExp>
 #include <QScopedPointer>
@@ -594,9 +593,9 @@
 }
 
 bool PDFLibCore::doExport(const QString& fn, const QString& nam, int Components,
-					  const std::vector<int> & pageNs, const QMap<int,QPixmap> & thumbs)
-{
-	QPixmap pm;
+					  const std::vector<int> & pageNs, const QMap<int, QImage> & thumbs)
+{
+	QImage thumb;
 	bool ret = false, error = false;
 	int  pc_exportpages=0;
 	int  pc_exportmasterpages=0;
@@ -650,11 +649,11 @@
 		for (uint a = 0; a < pageNs.size() && !abortExport; ++a)
 		{
 			if (doc.pdfOptions().Thumbnails)
-				pm = thumbs[pageNs[a]];
+				thumb = thumbs[pageNs[a]];
 			qApp->processEvents();
 			if (abortExport) break;
 
-			PDF_Begin_Page(doc.DocPages.at(pageNs[a]-1), pm);
+			PDF_Begin_Page(doc.DocPages.at(pageNs[a]-1), thumb);
 			qApp->processEvents();
 			if (abortExport) break;
 
@@ -3326,7 +3325,7 @@
 
 
 
-void PDFLibCore::PDF_Begin_Page(const ScPage* pag, QPixmap pm)
+void PDFLibCore::PDF_Begin_Page(const ScPage* pag, const QImage& thumb)
 {
 	ActPageP = pag;
 	Content = "";
@@ -3334,7 +3333,7 @@
 	pageData.radioButtonList.clear();
 	if (Options.Thumbnails)
 	{
-		ScImage img(pm.toImage());
+		ScImage img(thumb);
 		bool compDataAvail = false;
 		QByteArray array = img.ImageToArray();
 		if (Options.Compress)

Modified: trunk/Scribus/scribus/pdflib_core.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22459&path=/trunk/Scribus/scribus/pdflib_core.h
==============================================================================
--- trunk/Scribus/scribus/pdflib_core.h	(original)
+++ trunk/Scribus/scribus/pdflib_core.h	Fri Mar 30 16:13:24 2018
@@ -67,7 +67,7 @@
 	explicit PDFLibCore(ScribusDoc & docu);
 	~PDFLibCore();
 	bool doExport(const QString& fn, const QString& nam, int Components,
-				  const std::vector<int> & pageNs, const QMap<int,QPixmap> & thumbs);
+				  const std::vector<int> & pageNs, const QMap<int, QImage> & thumbs);
 
 	const QString& errorMessage(void) const;
 	bool  exportAborted(void) const;
@@ -117,7 +117,7 @@
 	void PDF_Begin_Colors();
 	void PDF_Begin_Layers();
 	
-	void PDF_Begin_Page(const ScPage* pag, QPixmap pm);
+	void PDF_Begin_Page(const ScPage* pag, const QImage& thumb);
 	void PDF_End_Page();
 	bool PDF_TemplatePage(const ScPage* pag, bool clip = false);
 	bool PDF_ProcessPage(const ScPage* pag, uint PNr, bool clip = false);

Modified: trunk/Scribus/scribus/plugins/scriptplugin/objpdffile.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22459&path=/trunk/Scribus/scribus/plugins/scriptplugin/objpdffile.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/objpdffile.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/objpdffile.cpp	Fri Mar 30 16:13:24 2018
@@ -15,8 +15,8 @@
 #include "ui/bookmarkpalette.h"
 
 #include <QFileInfo>
+#include <QImage>
 #include <QList>
-#include <QPixmap>
 #include <vector>
 
 // these functions are located at utils.cpp
@@ -1480,13 +1480,13 @@
 			pdfOptions.UseProfiles2 = false;
 		}
 	}
-	QMap<int,QPixmap> thumbs;
+	QMap<int, QImage> thumbs;
 	for (uint ap = 0; ap < pageNs.size(); ++ap)
 	{
-		QPixmap pm(10,10);
+		QImage thumb(10, 10, QImage::Format_ARGB32_Premultiplied );
 		if (pdfOptions.Thumbnails)
-			pm = QPixmap::fromImage(ScCore->primaryMainWindow()->view->PageToPixmap(pageNs[ap]-1, 100));
-		thumbs.insert(pageNs[ap], pm);
+			thumb = ScCore->primaryMainWindow()->view->PageToPixmap(pageNs[ap]-1, 100);
+		thumbs.insert(pageNs[ap], thumb);
 	}
 	ReOrderText(ScCore->primaryMainWindow()->doc, ScCore->primaryMainWindow()->view);
 

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22459&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp	(original)
+++ trunk/Scribus/scribus/scribus.cpp	Fri Mar 30 16:13:24 2018
@@ -7135,7 +7135,7 @@
 }
 
 bool ScribusMainWindow::getPDFDriver(const QString &filename, const QString &name, int components, const std::vector<int> & pageNumbers,
-									 const QMap<int,QPixmap> & thumbs, QString& error, bool* cancelled)
+									 const QMap<int, QImage>& thumbs, QString& error, bool* cancelled)
 {
 	ScCore->fileWatcher->forceScan();
 	ScCore->fileWatcher->stop();
@@ -7225,7 +7225,7 @@
 	QString pageString(dia.getPagesString());
 	std::vector<int> pageNs;
 	uint pageNumbersSize;
-	QMap<int,QPixmap> allThumbs, thumbs;
+	QMap<int, QImage> allThumbs, thumbs;
 	int components = dia.colorSpaceComponents();
 	QString nam(dia.cmsDescriptor());
 	QString fileName = doc->pdfOptions().fileName;
@@ -7249,14 +7249,14 @@
 	pageNumbersSize = pageNs.size();
 	for (uint i = 0; i < pageNumbersSize; ++i)
 	{
-		QPixmap pm(10, 10);
+		QImage thumb(10, 10, QImage::Format_ARGB32_Premultiplied);
 		if (doc->pdfOptions().Thumbnails)
 		{
 			// No need to load full res images for drawing small thumbnail
 			PageToPixmapFlags flags = Pixmap_DontReloadImages;
-			pm = QPixmap::fromImage(view->PageToPixmap(pageNs[i] - 1, 100, flags));
-		}
-		allThumbs.insert(pageNs[i], pm);
+			thumb = view->PageToPixmap(pageNs[i] - 1, 100, flags);
+		}
+		allThumbs.insert(pageNs[i], thumb);
 	}
 	if (cmsCorr)
 	{
@@ -7279,10 +7279,10 @@
 			pageNs2.clear();
 			pageNs2.push_back(pageNs[aa]);
 			pageNumbersSize = pageNs2.size();
-			QPixmap pm(10,10);
+			QImage thumb(10, 10, QImage::Format_ARGB32_Premultiplied);
 			if (doc->pdfOptions().Thumbnails)
-				pm = allThumbs[pageNs[aa]];
-			thumbs.insert(1, pm);
+				thumb = allThumbs[pageNs[aa]];
+			thumbs.insert(1, thumb);
 			QString realName = QDir::toNativeSeparators(path+"/"+name+ tr("-Page%1").arg(pageNs[aa], 3, 10, QChar('0'))+"."+ext);
 			if (!getPDFDriver(realName, nam, components, pageNs2, thumbs, errorMsg, &cancelled))
 			{

Modified: trunk/Scribus/scribus/scribus.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22459&path=/trunk/Scribus/scribus/scribus.h
==============================================================================
--- trunk/Scribus/scribus/scribus.h	(original)
+++ trunk/Scribus/scribus/scribus.h	Fri Mar 30 16:13:24 2018
@@ -33,11 +33,11 @@
 
 #include <QActionGroup>
 #include <QClipboard>
+#include <QImage>
 #include <QKeyEvent>
 #include <QMainWindow>
 #include <QMap>
 #include <QMultiHash>
-#include <QPixmap>
 #include <QPointer>
 #include <QPushButton>
 #include <QProcess>
@@ -159,7 +159,7 @@
 	void applyNewMaster(QString name);
 	void updateRecent(QString fn);
 	void doPasteRecent(QString data);
-	bool getPDFDriver(const QString & filename, const QString & name, int components, const std::vector<int> & pageNumbers, const QMap<int,QPixmap> & thumbs, QString& error, bool* cancelled = NULL);
+	bool getPDFDriver(const QString & filename, const QString & name, int components, const std::vector<int> & pageNumbers, const QMap<int, QImage> & thumbs, QString& error, bool* cancelled = NULL);
 	bool DoSaveAsEps(QString fn, QString& error);
 	QString CFileDialog(QString workingDirectory = ".", QString dialogCaption = "", QString fileFilter = "", QString defNa = "",
 						int optionFlags = fdExistingFiles, bool *useCompression = 0, bool *useFonts = 0, bool *useProfiles = 0);




More information about the scribus-commit mailing list