r19737 by fschmid - Fixed Bug #12878: Only bottom layer of Gimp image is imported

scribus-commit scribus-commit at lists.scribus.net
Tue Jan 6 19:26:36 UTC 2015


Author: fschmid
Date: Tue Jan  6 19:26:36 2015
New Revision: 19737

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=19737
Log:
Fixed Bug #12878: Only bottom layer of Gimp image is imported
Additional fix: Enable access to the layers.

Modified:
    trunk/Scribus/scribus/scimage.cpp
    trunk/Scribus/scribus/scimgdataloader_gmagick.cpp
    trunk/Scribus/scribus/scimgdataloader_gmagick.h

Modified: trunk/Scribus/scribus/scimage.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19737&path=/trunk/Scribus/scribus/scimage.cpp
==============================================================================
--- trunk/Scribus/scribus/scimage.cpp (original)
+++ trunk/Scribus/scribus/scimage.cpp Tue Jan  6 19:26:36 2015
@@ -2288,7 +2288,10 @@
 	else if (fmtImg.contains(ext))
 		pDataLoader.reset( new ScImgDataLoader_QT() );
 	else
+	{
 		pDataLoader.reset( new ScImgDataLoader_GMagick() );
+		pDataLoader->setRequest(imgInfo.isRequest, imgInfo.RequestProps);
+	}
 #else
 	else
 		pDataLoader.reset( new ScImgDataLoader_QT() );

Modified: trunk/Scribus/scribus/scimgdataloader_gmagick.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19737&path=/trunk/Scribus/scribus/scimgdataloader_gmagick.cpp
==============================================================================
--- trunk/Scribus/scribus/scimgdataloader_gmagick.cpp (original)
+++ trunk/Scribus/scribus/scimgdataloader_gmagick.cpp Tue Jan  6 19:26:36 2015
@@ -125,16 +125,20 @@
 		return false;
 	}
 
+	QRgb *s = (QRgb*)(output->scanLine(0));
 	int i;
-	for (i = 0; i < width*height; i++) {
-		*buffer++ = ScaleQuantumToChar(GetBlueSample(pixels[i]));
-		*buffer++ = ScaleQuantumToChar(GetGreenSample(pixels[i]));
-		*buffer++ = ScaleQuantumToChar(GetRedSample(pixels[i]));
-		if (hasAlpha) {
-			*buffer++ = 255 - ScaleQuantumToChar(GetRGBAlphaSample(pixels[i]));
-		} else {
-			*buffer++ = 255;
-		}
+	for (i = 0; i < width*height; i++)
+	{
+		unsigned char b = ScaleQuantumToChar(GetBlueSample(pixels[i]));
+		unsigned char g = ScaleQuantumToChar(GetGreenSample(pixels[i]));
+		unsigned char r = ScaleQuantumToChar(GetRedSample(pixels[i]));
+		unsigned char a;
+		if (hasAlpha)
+			a = 255 - ScaleQuantumToChar(GetRGBAlphaSample(pixels[i]));
+		else
+			a = 255;
+		*s = qRgba(r, g, b, a);
+		s++;
 	}
 	return true;
 }
@@ -142,13 +146,19 @@
 
 bool ScImgDataLoader_GMagick::loadPicture(const QString& fn, int /*page*/, int res, bool thumbnail)
 {
+	if (!QFile::exists(fn))
+		return false;
+	bool valid = m_imageInfoRecord.isRequest;
+	QMap<int, ImageLoadRequest> req = m_imageInfoRecord.RequestProps;
+	initialize();
+	m_imageInfoRecord.RequestProps = req;
+	m_imageInfoRecord.isRequest = valid;
+	m_imageInfoRecord.type = ImageTypeOther;
+	m_imageInfoRecord.exifDataValid = false;
+	m_imageInfoRecord.layerInfo.clear();
+	m_imageInfoRecord.PDSpathData.clear();
 	initGraphicsMagick();
-	qDebug() << "Loading image" << fn << "Tumbnail:" << thumbnail;
-
-	if (!QFile::exists(fn))
-		return false;
-
-	initialize();
+//	qDebug() << "Loading image" << fn << "Tumbnail:" << thumbnail;
 
 	ExceptionInfo exception;
 	GetExceptionInfo(&exception);
@@ -158,33 +168,142 @@
 	Image *image = ReadImage(image_info, &exception);
 	if (exception.severity != UndefinedException)
 		CatchException(&exception);
-	if (!image) {
+	if (!image)
+	{
 		qCritical() << "Failed to read image" << fn;
 		return false;
 	}
-	image = FlattenImages(image, &exception);
-//	qDebug() << "has matte(alpha):" << image->matte;
 	int width = image->columns;
 	int height = image->rows;
-
 	double xres = image->x_resolution;
 	double yres = image->y_resolution;
 
-	if (image->colorspace == CMYKColorspace) {
+	if (thumbnail)
+		image = FlattenImages(image, &exception);
+	else
+	{
+		struct PSDLayer layer;
+		layerCount = 0;
+		Image *flatten_image = CloneImage(image, 0, 0, true, &exception);
+		Image *next;
+		if ((flatten_image != (Image *) NULL) && (image->next != (Image *) NULL))
+		{
+			bool visible = true;
+			double opacity = 1.0;
+			QString compositeOp = "norm";
+			QString layerName = QString("layer%1").arg(layerCount+1);
+			if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount)))
+				opacity = m_imageInfoRecord.RequestProps[layerCount].opacity / 255.0;
+			if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount)))
+				visible = m_imageInfoRecord.RequestProps[layerCount].visible;
+			if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount)))
+				compositeOp = m_imageInfoRecord.RequestProps[layerCount].blend;
+			layer.layerName = layerName;
+			layer.channelType.clear();
+			layer.channelLen.clear();
+			layer.opacity = opacity;
+			layer.blend = "norm";
+			layer.maskYpos = 0;
+			layer.maskXpos = 0;
+			layer.maskHeight = 0;
+			layer.maskWidth = 0;
+			layer.flags = visible ? 0 : 2;
+			QImage imt;
+			if (image->colorspace == CMYKColorspace)
+			{
+				RawImage r2_image;
+				readCMYK(flatten_image, &r2_image, width, height);
+				imt = r2_image.convertToQImage(true);
+			}
+			else
+			{
+				m_useRawImage = false;
+				imt = QImage(width, height, QImage::Format_ARGB32);
+				readRGB(flatten_image, &imt, width, height);
+			}
+			double sx = imt.width() / 40.0;
+			double sy = imt.height() / 40.0;
+			layer.thumb = sy < sx ?  imt.scaled(qRound(imt.width() / sx), qRound(imt.height() / sx), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) :
+				  imt.scaled(qRound(imt.width() / sy), qRound(imt.height() / sy), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+			m_imageInfoRecord.layerInfo.append(layer);
+			layerCount++;
+			if (!visible)
+			{
+				(void)CompositeImage(flatten_image, ClearCompositeOp, flatten_image, flatten_image->page.x, flatten_image->page.y);
+			}
+			for (next = image->next; next != (Image*)NULL; next = next->next)
+			{
+				visible = true;
+				opacity = 1.0;
+				compositeOp = "norm";
+				layerName = QString("layer%1").arg(layerCount+1);
+				if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount)))
+					opacity = m_imageInfoRecord.RequestProps[layerCount].opacity / 255.0;
+				if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount)))
+					visible = m_imageInfoRecord.RequestProps[layerCount].visible;
+				if ((m_imageInfoRecord.isRequest) && (m_imageInfoRecord.RequestProps.contains(layerCount)))
+					compositeOp = m_imageInfoRecord.RequestProps[layerCount].blend;
+				layer.layerName = layerName;
+				layer.channelType.clear();
+				layer.channelLen.clear();
+				layer.opacity = opacity;
+				layer.blend = "norm";
+				layer.maskYpos = 0;
+				layer.maskXpos = 0;
+				layer.maskHeight = 0;
+				layer.maskWidth = 0;
+				layer.flags = visible ? 0 : 2;
+				if (image->colorspace == CMYKColorspace)
+				{
+					RawImage r2_image;
+					readCMYK(next, &r2_image, width, height);
+					imt = r2_image.convertToQImage(true);
+				}
+				else
+				{
+					m_useRawImage = false;
+					imt = QImage(width, height, QImage::Format_ARGB32);
+					readRGB(next, &imt, width, height);
+				}
+				double sx = imt.width() / 40.0;
+				double sy = imt.height() / 40.0;
+				layer.thumb = sy < sx ?  imt.scaled(qRound(imt.width() / sx), qRound(imt.height() / sx), Qt::IgnoreAspectRatio, Qt::SmoothTransformation) :
+					  imt.scaled(qRound(imt.width() / sy), qRound(imt.height() / sy), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+				m_imageInfoRecord.layerInfo.append(layer);
+				layerCount++;
+				if (visible)
+					(void)CompositeImage(flatten_image, next->compose, next, next->page.x, next->page.y);
+			}
+			image = CloneImage(flatten_image, 0, 0, true, &exception);
+		}
+	}
+//	qDebug() << "has matte(alpha):" << image->matte;
+
+	if (image->colorspace == CMYKColorspace)
+	{
 		qDebug() << "CMYK image";
 		m_useRawImage = true;
-		if (!readCMYK(image, &r_image, width, height)) return false;
+		if (!readCMYK(image, &r_image, width, height))
+			return false;
 		m_imageInfoRecord.colorspace = ColorSpaceCMYK;
 		m_pixelFormat = (r_image.channels() == 5) ? Format_CMYKA_8 : Format_CMYK_8;
-	} else {
+	}
+	else
+	{
 		m_useRawImage = false;
 		m_image = QImage(width, height, QImage::Format_ARGB32);
-		if (!readRGB(image, &m_image, width, height)) return false;
+		if (!readRGB(image, &m_image, width, height))
+			return false;
 		m_imageInfoRecord.colorspace = ColorSpaceRGB;
 		m_pixelFormat = Format_BGRA_8;
 	}
+	m_imageInfoRecord.exifDataValid = false;
+	if (thumbnail)
+	{
+		m_imageInfoRecord.exifDataValid = true;
+		m_imageInfoRecord.exifInfo.thumbnail = m_image;
+	}
 	m_imageInfoRecord.type = ImageTypeOther;
-	m_imageInfoRecord.exifDataValid = false;
 	m_imageInfoRecord.xres = qMax(72, qRound(xres));
 	m_imageInfoRecord.yres = qMax(72, qRound(yres));
 	m_imageInfoRecord.BBoxX = 0;
@@ -258,4 +377,3 @@
 	m_embeddedProfile.resize(length);
 	memcpy(dest, src, length);
 }
-

Modified: trunk/Scribus/scribus/scimgdataloader_gmagick.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19737&path=/trunk/Scribus/scribus/scimgdataloader_gmagick.h
==============================================================================
--- trunk/Scribus/scribus/scimgdataloader_gmagick.h (original)
+++ trunk/Scribus/scribus/scimgdataloader_gmagick.h Tue Jan  6 19:26:36 2015
@@ -15,6 +15,7 @@
 protected:
 	void initSupportedFormatList();
 	bool m_useRawImage;
+	int layerCount;
 private:
 	static bool gm_initialized;
 	bool readCMYK(Image *input, RawImage *output, int width, int height);




More information about the scribus-commit mailing list