r23513 by jghali - Simplify ScImgDataLoader_KRA::loadPicture() thanks to previous commit

scribus-commit scribus-commit at lists.scribus.net
Wed Mar 18 22:25:47 UTC 2020


Author: jghali
Date: Wed Mar 18 22:25:47 2020
New Revision: 23513

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23513
Log:
Simplify ScImgDataLoader_KRA::loadPicture() thanks to previous commit

Modified:
    trunk/Scribus/scribus/imagedataloaders/scimgdataloader_kra.cpp

Modified: trunk/Scribus/scribus/imagedataloaders/scimgdataloader_kra.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23513&path=/trunk/Scribus/scribus/imagedataloaders/scimgdataloader_kra.cpp
==============================================================================
--- trunk/Scribus/scribus/imagedataloaders/scimgdataloader_kra.cpp	(original)
+++ trunk/Scribus/scribus/imagedataloaders/scimgdataloader_kra.cpp	Wed Mar 18 22:25:47 2020
@@ -8,6 +8,8 @@
 #include <QFileInfo>
 #include <QByteArray>
 #include <QList>
+#include <QScopedPointer>
+
 #include "scimgdataloader_kra.h"
 #include "util_formats.h"
 
@@ -41,65 +43,25 @@
 	m_imageInfoRecord.exifDataValid = false;
 	m_imageInfoRecord.layerInfo.clear();
 	m_imageInfoRecord.PDSpathData.clear();
-	ScZipHandler *uz = new ScZipHandler();
 
+	QScopedPointer<ScZipHandler> uz(new ScZipHandler());
 	if (!uz->open(fn))
-	{
-		delete uz;
 		return false;
-	}
 
 	// if thumbnail is set to true, this function is loading the thumbnail image into the preview area
 	// if thumbnail is set to false, this function is loading the main image
 
 	if (thumbnail)
 	{
-		if (uz->contains("preview.png"))
-		{
-			QByteArray im;
+		if (!uz->contains("preview.png"))
+			return false;
 
-			if (uz->read("preview.png", im))
-			{
-				m_image = QImage::fromData(im);
+		QByteArray im;
+		if (!uz->read("preview.png", im))
+			return false;
 
-				if (uz->contains("maindoc.xml"))
-				{
-					QByteArray f;
-					if (uz->read("maindoc.xml", f))
-					{
-						QDomDocument designMapDom;
-						if (designMapDom.setContent(f))
-						{
-							QDomElement docElem = designMapDom.documentElement().firstChildElement("IMAGE");
-							m_imageInfoRecord.exifInfo.height = docElem.attribute("height", "0").toInt();
-							m_imageInfoRecord.exifInfo.width = docElem.attribute("width", "0").toInt();
+		m_image = QImage::fromData(im);
 
-							// sanitize values for x-res and y-res. some older versions of Krita had resolutions like "76,0000023"
-							QString xResClean = docElem.attribute("x-res", "72").replace(",", ".");
-							QString yResClean = docElem.attribute("y-res", "72").replace(",", ".");
-
-							// strip out all decimal stuff since we cannot have that.
-							xResClean = xResClean.split(".").at(0);
-							yResClean = yResClean.split(".").at(0);
-
-							m_imageInfoRecord.xres = xResClean.toInt();
-							m_imageInfoRecord.yres = yResClean.toInt();
-						}
-					}
-				}
-				m_imageInfoRecord.exifDataValid = true;
-				m_imageInfoRecord.exifInfo.thumbnail = m_image;
-			}
-			else
-			{
-
-				delete uz;
-				return false;
-			}
-		}
-	}
-	else
-	{
 		if (uz->contains("maindoc.xml"))
 		{
 			QByteArray f;
@@ -112,8 +74,6 @@
 					m_imageInfoRecord.exifInfo.height = docElem.attribute("height", "0").toInt();
 					m_imageInfoRecord.exifInfo.width = docElem.attribute("width", "0").toInt();
 
-
-
 					// sanitize values for x-res and y-res. some older versions of Krita had resolutions like "76,0000023"
 					QString xResClean = docElem.attribute("x-res", "72").replace(",", ".");
 					QString yResClean = docElem.attribute("y-res", "72").replace(",", ".");
@@ -122,46 +82,68 @@
 					xResClean = xResClean.split(".").at(0);
 					yResClean = yResClean.split(".").at(0);
 
-
 					m_imageInfoRecord.xres = xResClean.toInt();
 					m_imageInfoRecord.yres = yResClean.toInt();
-
-
-					m_image = QImage(m_imageInfoRecord.exifInfo.width, m_imageInfoRecord.exifInfo.height, QImage::Format_ARGB32_Premultiplied);
-					if (m_image.isNull())
-					{
-						uz->close();
-						delete uz;
-						return false;
-					}
-
-					// load the mergedimage.png into the painter
-					if (uz->contains("mergedimage.png"))
-					{
-						QByteArray im;
-
-						if (uz->read("mergedimage.png", im))
-						{
-							m_image.fill( qRgba(0, 0, 0, 0) );
-							m_image = QImage::fromData(im);
-						}
-					}
-
-					m_image = m_image.convertToFormat(QImage::Format_ARGB32);
-					m_imageInfoRecord.valid = true;
-					m_image.setDotsPerMeterX((int) (m_imageInfoRecord.xres / 0.0254));
-					m_image.setDotsPerMeterY((int) (m_imageInfoRecord.yres / 0.0254));
-					m_imageInfoRecord.BBoxX = 0;
-					m_imageInfoRecord.BBoxH = m_image.height();
-					m_imageInfoRecord.colorspace = ColorSpaceRGB;
-					m_pixelFormat = Format_BGRA_8;
 				}
 			}
 		}
+		m_imageInfoRecord.exifInfo.thumbnail = m_image;
+		m_imageInfoRecord.exifDataValid = true;
+		return true;
 	}
+
+	if (!uz->contains("maindoc.xml"))
+		return false;
+
+	QByteArray f;
+	if (!uz->read("maindoc.xml", f))
+		return false;
+
+	QDomDocument designMapDom;
+	if (!designMapDom.setContent(f))
+		return false;
+
+	QDomElement docElem = designMapDom.documentElement().firstChildElement("IMAGE");
+	m_imageInfoRecord.exifInfo.height = docElem.attribute("height", "0").toInt();
+	m_imageInfoRecord.exifInfo.width = docElem.attribute("width", "0").toInt();
+
+	// sanitize values for x-res and y-res. some older versions of Krita had resolutions like "76,0000023"
+	QString xResClean = docElem.attribute("x-res", "72").replace(",", ".");
+	QString yResClean = docElem.attribute("y-res", "72").replace(",", ".");
+
+	// strip out all decimal stuff since we cannot have that.
+	xResClean = xResClean.split(".").at(0);
+	yResClean = yResClean.split(".").at(0);
+
+	m_imageInfoRecord.xres = xResClean.toInt();
+	m_imageInfoRecord.yres = yResClean.toInt();
+
+	m_image = QImage(m_imageInfoRecord.exifInfo.width, m_imageInfoRecord.exifInfo.height, QImage::Format_ARGB32_Premultiplied);
+	if (m_image.isNull())
+		return false;
+
+	// load the mergedimage.png into the painter
+	if (!uz->contains("mergedimage.png"))
+		return false;
+
+	QByteArray im;
+	if (!uz->read("mergedimage.png", im))
+		return false;
+	
+	m_image.fill( qRgba(0, 0, 0, 0) );
+	m_image = QImage::fromData(im);
+
+	m_image = m_image.convertToFormat(QImage::Format_ARGB32);
+	m_imageInfoRecord.valid = true;
+	m_image.setDotsPerMeterX((int) (m_imageInfoRecord.xres / 0.0254));
+	m_image.setDotsPerMeterY((int) (m_imageInfoRecord.yres / 0.0254));
+	m_imageInfoRecord.BBoxX = 0;
+	m_imageInfoRecord.BBoxH = m_image.height();
+	m_imageInfoRecord.colorspace = ColorSpaceRGB;
+	m_pixelFormat = Format_BGRA_8;
+
 	uz->close();
-	delete uz;
-	return true; //TODO: I think this should be false!
+	return true;
 }
 
 bool ScImgDataLoader_KRA::preloadAlphaChannel(const QString& fn, int /*page*/, int res, bool& hasAlpha)




More information about the scribus-commit mailing list