r15128 by jghali - - start using color space classes in image loading code, did basic testing, more testing needed tho - necessary change for enable use of lcms2, especially remove use of cmsChageBufferFormat as such thing is not supported by lcms2. CMake stuff related to lcms2 is still to be done tho

scribus-commit scribus-commit at lists.scribus.net
Fri May 28 19:01:32 CEST 2010


Revision: 15128
Author: jghali
Date: 2010-05-28T16:51:41.020561Z
Commit message: - start using color space classes in image loading code, did basic testing, more testing needed tho
- necessary change for enable use of lcms2, especially remove use of cmsChageBufferFormat as such thing is not supported by lcms2. CMake stuff related to lcms2 is still to be done tho


Changeset: 
M  /trunk/Scribus/scribus/colormgmt/sccolorspace.h
M  /trunk/Scribus/scribus/scimgdataloader.h
M  /trunk/Scribus/scribus/scimgdataloader_jpeg.cpp
M  /trunk/Scribus/scribus/scimgdataloader_psd.cpp
M  /trunk/Scribus/scribus/scribusdoc.cpp
M  /trunk/Scribus/scribus/scimgdataloader_tiff.h
M  /trunk/Scribus/scribus/colormgmt/sccolorspacedata_laba.h
M  /trunk/Scribus/scribus/scimgdataloader_pict.cpp
M  /trunk/Scribus/scribus/colormgmt/sccolortransformdata.h
M  /trunk/Scribus/scribus/colormgmt/sccolortransform.cpp
M  /trunk/Scribus/scribus/colormgmt/sclcmscolortransformimpl.h
M  /trunk/Scribus/scribus/colormgmt/sccolormgmtenginefactory.cpp
M  /trunk/Scribus/scribus/scimgdataloader_pdf.cpp
M  /trunk/Scribus/scribus/colormgmt/sccolorspacedata_rgba.h
M  /trunk/Scribus/scribus/colormgmt/sccolorspacedata.h
M  /trunk/Scribus/scribus/scimgdataloader.cpp
M  /trunk/Scribus/scribus/colormgmt/sccolorspace.cpp
M  /trunk/Scribus/scribus/colormgmt/sclcmscolormgmtengineimpl.cpp
M  /trunk/Scribus/scribus/scimgdataloader_ps.cpp
M  /trunk/Scribus/scribus/scimgdataloader_tiff.cpp
M  /trunk/Scribus/scribus/scimgdataloader_psd.h
M  /trunk/Scribus/scribus/colormgmt/CMakeLists.txt
M  /trunk/Scribus/scribus/scimgdataloader_gimp.cpp
M  /trunk/Scribus/scribus/scimgdataloader_wpg.cpp
M  /trunk/Scribus/scribus/colormgmt/sclcmscolortransformimpl.cpp
M  /trunk/Scribus/scribus/colormgmt/sccolorspacedata_gray.h
M  /trunk/Scribus/scribus/colormgmt/sccolorspacedata_cmyk.h
M  /trunk/Scribus/scribus/colormgmt/sccolorspacedata_cmyka.h
M  /trunk/Scribus/scribus/colormgmt/sccolortransform.h
M  /trunk/Scribus/scribus/scimage.cpp
M  /trunk/Scribus/scribus/colormgmt/sccolorspacedata_rgb.h
M  /trunk/Scribus/scribus/scimgdataloader_qt.cpp

Diffs:
Index: scribus/scimgdataloader_ps.cpp
===================================================================
--- scribus/scimgdataloader_ps.cpp	(revision 15127)
+++ scribus/scimgdataloader_ps.cpp	(revision 15128)
@@ -546,6 +546,7 @@
 		else
 			m_imageInfoRecord.colorspace = ColorSpaceRGB;
 		m_imageInfoRecord.actualPageNumber = page;
+		m_pixelFormat = Format_BGRA_8;
 		return true;
 	}
 	if (found)
@@ -625,6 +626,7 @@
 				m_imageInfoRecord.colorspace = ColorSpaceRGB;
 				m_image.setDotsPerMeterX ((int) (xres / 0.0254));
 				m_image.setDotsPerMeterY ((int) (yres / 0.0254));
+				m_pixelFormat = Format_BGRA_8;
 			}
 		}
 		else
@@ -694,6 +696,7 @@
 				m_imageInfoRecord.type = ImageType7;
 				m_image.setDotsPerMeterX ((int) (xres / 0.0254));
 				m_image.setDotsPerMeterY ((int) (yres / 0.0254));
+				m_pixelFormat = Format_CMYK_8;
 			}
 			else
 			{
@@ -771,6 +774,7 @@
 			}
 			m_imageInfoRecord.colorspace = ColorSpaceCMYK;
 			m_imageInfoRecord.type = ImageType7;
+			m_pixelFormat = Format_CMYK_8;
 		}
 		else
 		{
@@ -795,6 +799,7 @@
 			}
 			m_imageInfoRecord.type = ImageType7;
 			m_imageInfoRecord.colorspace = ColorSpaceRGB;
+			m_pixelFormat = Format_BGRA_8;
 		}
 		
 		QFile::remove(tmpFile);
@@ -944,6 +949,7 @@
 					out[i] = qRgb(in[0], in[1], in[2]);
 				}
 			}
+			m_pixelFormat = Format_BGRA_8;
 		}
 		if ( cinfo.output_components == 4 )
 		{
@@ -980,6 +986,7 @@
 					}
 				}
 			}
+			m_pixelFormat = Format_CMYK_8;
 		}
 		if ( cinfo.output_components == 1 )
 		{
@@ -998,6 +1005,7 @@
 					d++;
 				}
 			}
+			m_pixelFormat = Format_BGRA_8;
 		}
 	}
 	(void) jpeg_finish_decompress(&cinfo);
@@ -1037,6 +1045,7 @@
 		tmpImg.setNumColors(256);
 		for (int i=0; i<256; i++)
 			tmpImg.setColor(i, qRgb(i,i,i));
+		m_pixelFormat = Format_GRAY_8;
 	}
 	if (!tmpImg.isNull())
 	{
@@ -1061,6 +1070,7 @@
 					out[i] = qRgb(in[0], in[1], in[2]);
 				}
 			}
+			m_pixelFormat = Format_BGRA_8;
 		}
 		if ( cinfo.output_components == 4 )
 		{
@@ -1097,6 +1107,7 @@
 					}
 				}
 			}
+			m_pixelFormat = Format_CMYK_8;
 		}
 		if ( cinfo.output_components == 1 )
 		{
@@ -1237,9 +1248,15 @@
 					}
 				}
 				if (psMode == 4)
+				{
 					m_imageInfoRecord.colorspace = ColorSpaceCMYK;
+					m_pixelFormat = Format_CMYK_8;
+				}
 				else
+				{
 					m_imageInfoRecord.colorspace = ColorSpaceRGB;
+					m_pixelFormat = Format_BGRA_8;
+				}
 				m_imageInfoRecord.type  = ImageType7;
 				m_imageInfoRecord.BBoxX = 0;
 				m_imageInfoRecord.BBoxH = m_image.height();
@@ -1486,6 +1503,7 @@
 	m_imageInfoRecord.type = ImageType7;
 	m_image.setDotsPerMeterX ((int) (xres / 0.0254));
 	m_image.setDotsPerMeterY ((int) (yres / 0.0254));
+	m_pixelFormat = Format_CMYK_8;
 }
 
 void ScImgDataLoader_PS::loadDCS1(QString fn, int gsRes)
@@ -1586,6 +1604,7 @@
 	m_imageInfoRecord.type = ImageType7;
 	m_image.setDotsPerMeterX ((int) (xres / 0.0254));
 	m_image.setDotsPerMeterY ((int) (yres / 0.0254));
+	m_pixelFormat = Format_CMYK_8;
 }
 
 void ScImgDataLoader_PS::blendImages(QImage &source, ScColor col)
Index: scribus/scimgdataloader_wpg.cpp
===================================================================
--- scribus/scimgdataloader_wpg.cpp	(revision 15127)
+++ scribus/scimgdataloader_wpg.cpp	(revision 15128)
@@ -343,5 +343,6 @@
 	m_imageInfoRecord.BBoxX = 0;
 	m_imageInfoRecord.colorspace = ColorSpaceRGB;
 	m_imageInfoRecord.BBoxH = m_image.height();
+	m_pixelFormat = Format_BGRA_8;
 	return true;
 }
Index: scribus/scimgdataloader.h
===================================================================
--- scribus/scimgdataloader.h	(revision 15127)
+++ scribus/scimgdataloader.h	(revision 15128)
@@ -12,6 +12,7 @@
 #include <QImage>
 #include <QStringList>
 
+#include "colormgmt/sccolormgmtstructs.h"
 #include "scimagestructs.h"
 #include "rawimage.h"
 
@@ -22,10 +23,11 @@
 
 	QStringList m_supportedFormats;
 
-	QImage m_image;
+	QImage          m_image;
 	ImageInfoRecord m_imageInfoRecord;
-	QByteArray m_embeddedProfile;
-	int m_profileComponents;
+	QByteArray      m_embeddedProfile;
+	int             m_profileComponents;
+	eColorFormat    m_pixelFormat;
 
 	typedef enum {
 		noMsg = 0,
@@ -48,14 +50,16 @@
 	const QStringList& supportedFormats(void) const { return m_supportedFormats; }
 	bool  supportFormat(const QString& fmt);
 
-	QImage& image(void) { return m_image; }
-	RawImage r_image;
-	QByteArray& embeddedProfile(void) { return m_embeddedProfile; }
+	RawImage    r_image;
+
+	QImage&          image(void) { return m_image; }
+	QByteArray&      embeddedProfile(void) { return m_embeddedProfile; }
 	ImageInfoRecord& imageInfoRecord(void) { return m_imageInfoRecord; }
-	void setRequest(bool valid, QMap<int, ImageLoadRequest> req);
+	eColorFormat     pixelFormat(void) { return m_pixelFormat; }
+	void             setRequest(bool valid, QMap<int, ImageLoadRequest> req);
 
-	bool  issuedErrorMsg(void) const { return (m_msgType == errorMsg); }
-	bool  issuedWarningMsg(void) const { return (m_msgType == warningMsg); }
+	bool  issuedErrorMsg(void)      const { return (m_msgType == errorMsg); }
+	bool  issuedWarningMsg(void)    const { return (m_msgType == warningMsg); }
 	const QString& getMessage(void) const { return m_message; }
 
 	virtual void initialize(void);
Index: scribus/scimgdataloader.cpp
===================================================================
--- scribus/scimgdataloader.cpp	(revision 15127)
+++ scribus/scimgdataloader.cpp	(revision 15128)
@@ -19,6 +19,7 @@
 	m_imageInfoRecord.init();
 	m_embeddedProfile.resize(0);
 	m_profileComponents = 0;
+	m_pixelFormat = Format_Undefined;
 }
 
 void ScImgDataLoader::setRequest(bool valid, QMap<int, ImageLoadRequest> req)
Index: scribus/scribusdoc.cpp
===================================================================
--- scribus/scribusdoc.cpp	(revision 15127)
+++ scribus/scribusdoc.cpp	(revision 15128)
@@ -729,14 +729,14 @@
 										DocDisplayProf, Format_RGB_16,
 										IntentColors, dcmsFlags);
 	// TODO : check input profiles used for images
-	stdProofImg = colorEngine.createProofingTransform(DocInputImageRGBProf, Format_RGBA_8,
-	                  DocDisplayProf, Format_RGBA_8, DocPrinterProf,
+	stdProofImg = colorEngine.createProofingTransform(DocInputImageRGBProf, Format_BGRA_8,
+	                  DocDisplayProf, Format_BGRA_8, DocPrinterProf,
 	                  IntentImages, Intent_Relative_Colorimetric, dcmsFlagsGC);
 	stdProofImgCMYK = colorEngine.createProofingTransform(DocInputImageCMYKProf, Format_CMYK_8,
-	                  DocDisplayProf, Format_RGBA_8, DocPrinterProf,
+	                  DocDisplayProf, Format_BGRA_8, DocPrinterProf,
 	                  IntentImages, Intent_Relative_Colorimetric, dcmsFlagsGC);
-	stdTransImg = colorEngine.createTransform(DocInputRGBProf, Format_RGBA_8,
-	                  DocDisplayProf, Format_RGBA_8, 
+	stdTransImg = colorEngine.createTransform(DocInputRGBProf, Format_BGRA_8,
+	                  DocDisplayProf, Format_BGRA_8, 
 					  IntentImages, dcmsFlags);
 	stdTransRGB = colorEngine.createTransform(DocInputCMYKProf, Format_CMYK_16,
 					  DocInputRGBProf, Format_RGB_16,
Index: scribus/scimgdataloader_pict.cpp
===================================================================
--- scribus/scimgdataloader_pict.cpp	(revision 15127)
+++ scribus/scimgdataloader_pict.cpp	(revision 15128)
@@ -141,6 +141,7 @@
 		m_imageInfoRecord.BBoxX = 0;
 		m_imageInfoRecord.colorspace = ColorSpaceRGB;
 		m_imageInfoRecord.BBoxH = m_image.height();
+		m_pixelFormat = Format_BGRA_8;
 		f.close();
 		return true;
 	}
Index: scribus/scimgdataloader_pdf.cpp
===================================================================
--- scribus/scimgdataloader_pdf.cpp	(revision 15127)
+++ scribus/scimgdataloader_pdf.cpp	(revision 15128)
@@ -108,6 +108,7 @@
 		m_imageInfoRecord.colorspace = ColorSpaceRGB;
 		m_image.setDotsPerMeterX ((int) (xres / 0.0254));
 		m_image.setDotsPerMeterY ((int) (yres / 0.0254));
+		m_pixelFormat = Format_BGRA_8;
 		return true;
 	}
 	return false;
Index: scribus/scimgdataloader_tiff.h
===================================================================
--- scribus/scimgdataloader_tiff.h	(revision 15127)
+++ scribus/scimgdataloader_tiff.h	(revision 15128)
@@ -49,6 +49,8 @@
 	virtual bool preloadAlphaChannel(const QString& fn, int page, int res, bool& hasAlpha);
 	virtual void loadEmbeddedProfile(const QString& fn, int page = 0);
 	virtual bool loadPicture(const QString& fn, int page, int res, bool thumbnail);
+
+	virtual bool useRawImage() { return true; }
 };
 
 #endif
Index: scribus/scimgdataloader_tiff.cpp
===================================================================
--- scribus/scimgdataloader_tiff.cpp	(revision 15127)
+++ scribus/scimgdataloader_tiff.cpp	(revision 15128)
@@ -209,6 +209,7 @@
 			if (bitspersample == 1)
 				bilevel = true;
 			isCMYK = false;
+			m_pixelFormat = Format_RGBA_8;
 		}
 		else
 		{
@@ -285,6 +286,7 @@
 				}
 			}
 			isCMYK = true;
+			m_pixelFormat = Format_CMYK_8;
 		}
 	}
 	else
@@ -293,6 +295,7 @@
 			return false;
 		if (bitspersample == 1)
 			bilevel = true;
+		m_pixelFormat = Format_RGBA_8;
 	}
 	return true;
 }
@@ -715,9 +718,15 @@
 					if (!m_imageInfoRecord.exifInfo.thumbnail.isNull())
 					{
 						if (isCMYK)
+						{
 							r_image.create(m_imageInfoRecord.exifInfo.thumbnail.width(), m_imageInfoRecord.exifInfo.thumbnail.height(), 5);
+							m_pixelFormat = Format_CMYKA_8;;
+						}
 						else
+						{
 							r_image.create(m_imageInfoRecord.exifInfo.thumbnail.width(), m_imageInfoRecord.exifInfo.thumbnail.height(), 4);
+							m_pixelFormat = (m_imageInfoRecord.colorspace == ColorSpaceCMYK) ? Format_CMYK_8 : Format_RGBA_8;
+						}
 						r_image.fill(0);
 						QRgb *s;
 						uchar *d;
Index: scribus/scimgdataloader_gimp.cpp
===================================================================
--- scribus/scimgdataloader_gimp.cpp	(revision 15127)
+++ scribus/scimgdataloader_gimp.cpp	(revision 15128)
@@ -109,6 +109,7 @@
 		m_imageInfoRecord.BBoxX = 0;
 		m_imageInfoRecord.colorspace = ColorSpaceRGB;
 		m_imageInfoRecord.BBoxH = m_image.height();
+		m_pixelFormat = Format_BGRA_8;
 		return true;
 	}
 	return true;
Index: scribus/scimgdataloader_qt.cpp
===================================================================
--- scribus/scimgdataloader_qt.cpp	(revision 15127)
+++ scribus/scimgdataloader_qt.cpp	(revision 15128)
@@ -55,6 +55,7 @@
 		m_imageInfoRecord.lowResType = resInf;
 		m_imageInfoRecord.BBoxX = 0;
 		m_imageInfoRecord.BBoxH = m_image.height();
+		m_pixelFormat = Format_BGRA_8;
 		return true;
 	}
 	return false; //TODO: I think this should be false!
Index: scribus/scimgdataloader_psd.cpp
===================================================================
--- scribus/scimgdataloader_psd.cpp	(revision 15127)
+++ scribus/scimgdataloader_psd.cpp	(revision 15128)
@@ -172,11 +172,8 @@
 			m_imageInfoRecord.profileName = prof.productDescription();
 			m_imageInfoRecord.isEmbedded = true;
 		}
+		isCMYK = (header.color_mode == CM_CMYK);
 		if (header.color_mode == CM_CMYK)
-			isCMYK = true;
-		else
-			isCMYK = false;
-		if (header.color_mode == CM_CMYK)
 			m_imageInfoRecord.colorspace = ColorSpaceCMYK;
 		else if (header.color_mode == CM_RGB)
 			m_imageInfoRecord.colorspace = ColorSpaceRGB;
@@ -192,9 +189,15 @@
 			if (!m_imageInfoRecord.exifInfo.thumbnail.isNull())
 			{
 				if (isCMYK)
+				{
 					r_image.create(m_imageInfoRecord.exifInfo.thumbnail.width(), m_imageInfoRecord.exifInfo.thumbnail.height(), 5);
+					m_pixelFormat = Format_CMYKA_8;
+				}
 				else
+				{
 					r_image.create(m_imageInfoRecord.exifInfo.thumbnail.width(), m_imageInfoRecord.exifInfo.thumbnail.height(), 4);
+					m_pixelFormat = Format_RGBA_8;
+				}
 				QRgb *s;
 				unsigned char cc, cm, cy, ck;
 				uchar *d;
@@ -249,11 +252,13 @@
 	{
 		if (!r_image.create(header.width, header.height, 5))
 			return false;
+		m_pixelFormat = Format_CMYKA_8;
 	}
 	else
 	{
 		if (!r_image.create(header.width, header.height, 4))
 			return false;
+		m_pixelFormat = Format_RGBA_8;
 	}
 	r_image.fill(0);
 	maxChannels = header.channel_count;
Index: scribus/scimage.cpp
===================================================================
--- scribus/scimage.cpp	(revision 15127)
+++ scribus/scimage.cpp	(revision 15128)
@@ -2204,31 +2204,22 @@
 	if (cmSettings.useColorManagement() && inputProf && screenProf && printerProf)
 	{
 		ScColorMgmtEngine engine(cmSettings.doc() ? cmSettings.doc()->colorEngine : ScCore->defaultEngine);
-		bool  isPsdTiff = (extensionIndicatesPSD(ext) || extensionIndicatesTIFF(ext));
-		eColorFormat inputProfFormat  = Format_BGRA_8;
+		eColorFormat inputProfFormat  = pDataLoader->pixelFormat();
 		eColorFormat outputProfFormat = Format_YMCK_8;
-		eColorSpaceType inputProfColorSpace = inputProf.colorSpace();
-		if ( inputProfColorSpace == ColorSpace_Rgb )
-			inputProfFormat = isPsdTiff ? Format_RGBA_8 : Format_BGRA_8; // Later make tiff and psd loader use Format_BGRA_8
-		else if (( inputProfColorSpace == ColorSpace_Cmyk ) && (isPsdTiff || pDataLoader->useRawImage()))
-		{
-			if (pDataLoader->r_image.channels() == 5)
-				inputProfFormat = Format_CMYKA_8;
-			else
-				inputProfFormat = Format_CMYK_8;
-		}
-		else if ( inputProfColorSpace == ColorSpace_Cmyk )
-			inputProfFormat = Format_YMCK_8;
-		else if ( inputProfColorSpace == ColorSpace_Gray )
-			inputProfFormat = Format_GRAY_8;
+		eColorSpaceType inputProfColorSpace  = inputProf.colorSpace();
 		eColorSpaceType outputProfColorSpace = printerProf.colorSpace();
+		if ( inputProfColorSpace == ColorSpace_Gray)
+			inputProfFormat  = Format_GRAY_8; // Grayscale is still a bit tricky
 		if ( outputProfColorSpace == ColorSpace_Rgb )
 			outputProfFormat = Format_BGRA_8;
 		else if ( outputProfColorSpace == ColorSpace_Cmyk )
 			outputProfFormat = Format_YMCK_8;
+		ScColorSpace inputCSpace  = engine.createColorSpace(inputProf, inputProfFormat);
+		ScColorSpace screenCSpace = engine.createColorSpace(screenProf, Format_BGRA_8);
+		ScColorSpace outputCSpace;
 		if (cmSettings.useColorManagement() && cmSettings.doSoftProofing())
 		{
-			cmsProofFlags |= Ctf_Softproofing;;
+			cmsProofFlags |= Ctf_Softproofing;
 			if (cmSettings.doGamutCheck())
 			{
 				cmsProofFlags |= Ctf_GamutCheck;
@@ -2240,7 +2231,7 @@
 		{
 		case CMYKData: // CMYK
 //			if ((!isCMYK && (outputProfColorSpace == icSigCmykData)) || (isCMYK && (outputProfColorSpace == icSigRgbData)) )
-				xform = engine.createTransform(inputProf, inputProfFormat, printerProf, outputProfFormat, cmSettings.imageRenderingIntent(), cmsFlags);
+				xform = inputCSpace.createTransform(printerProf, outputProfFormat, cmSettings.imageRenderingIntent(), cmsFlags);
 			if (outputProfColorSpace != ColorSpace_Cmyk )
 				*realCMYK = isCMYK = false;
 			break;
@@ -2250,22 +2241,22 @@
 			{
 				if ((imgInfo.profileName == cmSettings.defaultImageRGBProfile()) || (imgInfo.profileName == cmSettings.defaultImageCMYKProfile()))
 				{
-					if (isCMYK)
+					if (isCMYK && (inputProfFormat == Format_CMYK_8))
 						xform = cmSettings.cmykImageProofingTransform();
-					else
+					else if (inputProfFormat == Format_BGRA_8)
 						xform = cmSettings.rgbImageProofingTransform();
-					xform.changeBufferFormat(inputProfFormat, Format_BGRA_8);
 				}
-				else
-					xform = engine.createProofingTransform(inputProf, inputProfFormat,
-				                     screenProf, Format_BGRA_8, printerProf,
+				if (!xform)
+				{
+					xform = inputCSpace.createProofingTransform(screenCSpace, printerProf,
 				                     cmSettings.intent(), Intent_Relative_Colorimetric, cmsFlags | cmsProofFlags);
+				}
 			}
 			else if (cmSettings.softProofingAllowed() || isCMYK)
-				xform = engine.createTransform(inputProf, inputProfFormat, screenProf, Format_BGRA_8, cmSettings.intent(), cmsFlags);
+				xform = inputCSpace.createTransform(screenCSpace, cmSettings.intent(), cmsFlags);
 			else
 			{
-				if (extensionIndicatesPSD(ext) || extensionIndicatesTIFF(ext) || pDataLoader->useRawImage())
+				if (pDataLoader->useRawImage())
 				{
 					QImage::operator=(pDataLoader->r_image.convertToQImage(false));
 					profileName = imgInfo.profileName;
@@ -2278,10 +2269,11 @@
 				}
 			}
 			outputProfColorSpace = ColorSpace_Rgb;
+			outputCSpace = screenCSpace;
 			break;
 		case RawData: // no Conversion just raw Data
 			xform = 0;
-			if (extensionIndicatesPSD(ext) || extensionIndicatesTIFF(ext) || pDataLoader->useRawImage())
+			if (pDataLoader->useRawImage())
 			{
 				QImage::operator=(pDataLoader->r_image.convertToQImage(true, true));
 				profileName = imgInfo.profileName;
@@ -2300,15 +2292,16 @@
 				outputProfFormat = Format_BGRA_8;
 			else if ( outputProfColorSpace == ColorSpace_Cmyk )
 				outputProfFormat = Format_YMCK_8;
-			xform = engine.createTransform(inputProf, inputProfFormat, outputProfile, outputProfFormat, cmSettings.imageRenderingIntent(), cmsFlags);
+			xform = inputCSpace.createTransform(outputProfile, outputProfFormat, cmSettings.imageRenderingIntent(), cmsFlags);
 			isCMYK = (outputProfColorSpace == ColorSpace_Cmyk);
 			if (realCMYK)
 				*realCMYK = isCMYK;
+			outputCSpace = engine.createColorSpace(outputProfile, outputProfFormat);
 			break;
 		}
-		if (xform)
+		if (xform && outputCSpace)
 		{
-			if (extensionIndicatesPSD(ext) || extensionIndicatesTIFF(ext) || pDataLoader->useRawImage())
+			if (pDataLoader->useRawImage())
 			{
 				QImage::operator=(QImage(pDataLoader->r_image.width(), pDataLoader->r_image.height(), QImage::Format_ARGB32));
 				profileName = imgInfo.profileName;
@@ -2323,8 +2316,7 @@
 			for (int i = 0; i < height(); i++)
 			{
 				uchar* ptr = scanLine(i);
-				if (extensionIndicatesPSD(ext) || extensionIndicatesTIFF(ext) || pDataLoader->useRawImage())
-					ptr2 = pDataLoader->r_image.scanLine(i);
+				ptr2 = pDataLoader->useRawImage() ? pDataLoader->r_image.scanLine(i) : NULL;
 				if ( inputProfFormat == Format_GRAY_8 && (outputProfColorSpace != ColorSpace_Cmyk) )
 				{
 					unsigned char* ucs = ptr2 ? (ptr2 + 1) : (ptr + 1);
@@ -2352,30 +2344,12 @@
 				}
 				else
 				{
-					if (extensionIndicatesPSD(ext) || extensionIndicatesTIFF(ext) || pDataLoader->useRawImage()) //TODO: Unsure about this one
-					{
-						xform.apply(ptr2, ptr, width());
-					}
-					else
-						xform.apply(ptr, ptr, width());
+					inputCSpace.convert(outputCSpace, (eRenderIntent) 0, 0, ptr2 ? ptr2 : ptr, ptr, width(), &xform);
 				}
-				// if transforming from CMYK to RGB, flatten the alpha channel
-				// which will still contain the black channel
-				if (!(extensionIndicatesPSD(ext) || extensionIndicatesTIFF(ext) || pDataLoader->useRawImage()))
+				if (pDataLoader->useRawImage())
 				{
-					QRgb alphaFF = qRgba(0,0,0,255);
-					QRgb *p;
-					if (isCMYK && outputProfColorSpace != ColorSpace_Cmyk && !bilevel)
-					{
-						p = (QRgb *) ptr;
-						for (int j = 0; j < width(); j++, p++)
-							*p |= alphaFF;
-					}
-				}
-				else
-				{
 					// This might fix Bug #6328, please test.
-					if (outputProfColorSpace != ColorSpace_Cmyk && bilevel)
+					/*if (outputProfColorSpace != ColorSpace_Cmyk && bilevel)
 					{
 						QRgb alphaFF;
 						QRgb *p;
@@ -2386,38 +2360,26 @@
 							*p |= alphaFF;
 							ptr2 += 4;
 						}
-					}
-					if (outputProfColorSpace != ColorSpace_Cmyk && !bilevel)
+					}*/
+					// FIXME not valid if input or output colorspace are not 8bit / channels
+					if (inputCSpace.hasAlphaChannel() && outputCSpace.hasAlphaChannel())
 					{
-						if (pDataLoader->r_image.channels() == 5)
+						uint inputAlphaI  = inputCSpace.alphaIndex();
+						uint outputAlphaI = outputCSpace.alphaIndex();
+						uint inputBytes   = inputCSpace.bytesPerChannel()  * inputCSpace.numChannels();
+						uint outputBytes  = outputCSpace.bytesPerChannel() * outputCSpace.numChannels();
+						uchar* in  = ptr2 + inputAlphaI  * inputCSpace.bytesPerChannel();
+						uchar* out = ptr  + outputAlphaI * outputCSpace.bytesPerChannel();
+						for (int j = 0; j < width(); ++j)
 						{
-							QRgb *p = (QRgb *) ptr;
-							for (int j = 0; j < width(); j++, p++)
-							{
-								*p = qRgba(qRed(*p), qGreen(*p), qBlue(*p), ptr2[4]);
-								ptr2 += 5;
-							}
+							*out = *in;
+							in  += inputBytes;
+							out += outputBytes;
 						}
-						else
-						{
-							QRgb *p = (QRgb *) ptr;
-							for (int j = 0; j < width(); j++, p++)
-							{
-								if (isCMYK)
-									*p = qRgba(qRed(*p), qGreen(*p), qBlue(*p), 255);
-								else
-									*p = qRgba(qRed(*p), qGreen(*p), qBlue(*p), ptr2[3]);
-								ptr2 += 4;
-							}
-						}
 					}
 				}
 			}
 		}
-		if (isCMYK)
-			cmSettings.cmykImageProofingTransform().changeBufferFormat(Format_CMYK_8, Format_RGBA_8);
-		else
-			cmSettings.rgbImageProofingTransform().changeBufferFormat(Format_RGBA_8, Format_RGBA_8);
 	}
 	else
 	{
Index: scribus/scimgdataloader_jpeg.cpp
===================================================================
--- scribus/scimgdataloader_jpeg.cpp	(revision 15127)
+++ scribus/scimgdataloader_jpeg.cpp	(revision 15128)
@@ -341,6 +341,7 @@
 				}
 				else
 					m_image = m_imageInfoRecord.exifInfo.thumbnail.copy();
+				m_pixelFormat = Format_BGRA_8;
 			}
 			m_imageInfoRecord.valid = (m_imageInfoRecord.PDSpathData.size())>0?true:false; // The only interest is vectormask
 			arrayPhot.clear();
@@ -388,6 +389,7 @@
 					out[i] = qRgb(in[0], in[1], in[2]);
 				}
 			}
+			m_pixelFormat = Format_BGRA_8;
 		}
 		if ( cinfo.output_components == 4 )
 		{
@@ -447,6 +449,7 @@
 					}
 				}
 			}
+			m_pixelFormat = Format_YMCK_8;
 			isCMYK = true;
 		}
 		else
@@ -468,6 +471,7 @@
 					d++;
 				}
 			}
+			m_pixelFormat = Format_GRAY_8;;
 		}
 	}
 	(void) jpeg_finish_decompress(&cinfo);
Index: scribus/colormgmt/sccolortransformdata.h
===================================================================
--- scribus/colormgmt/sccolortransformdata.h	(revision 15127)
+++ scribus/colormgmt/sccolortransformdata.h	(revision 15128)
@@ -27,8 +27,6 @@
 
 	virtual bool apply(void* input, void* output, uint numElem) = 0;
 	virtual bool apply(QByteArray& input, QByteArray& output, uint numElem) = 0;
-
-	virtual void changeBufferFormat(eColorFormat input, eColorFormat output) = 0;
 };
 
 #endif
Index: scribus/colormgmt/sccolortransform.cpp
===================================================================
--- scribus/colormgmt/sccolortransform.cpp	(revision 15127)
+++ scribus/colormgmt/sccolortransform.cpp	(revision 15128)
@@ -29,11 +29,6 @@
 	return m_data->apply(input, output, numElem);
 }
 
-void ScColorTransform::changeBufferFormat(eColorFormat input, eColorFormat output)
-{
-	return m_data->changeBufferFormat(input, output);
-}
-
 bool ScColorTransform::operator==(const ScColorTransform& other) const
 {
 	return m_data == other.m_data;
Index: scribus/colormgmt/sccolorspacedata_gray.h
===================================================================
--- scribus/colormgmt/sccolorspacedata_gray.h	(revision 15127)
+++ scribus/colormgmt/sccolorspacedata_gray.h	(revision 15128)
@@ -13,6 +13,7 @@
 public:
 	ScColorSpaceDataTempl_Gray(ScColorProfile& profile);
 
+	virtual uint alphaIndex(void) const { return 0; }
 	virtual void flattenAlpha(void* dataIn, uint numElems) const {};
 };
 
Index: scribus/colormgmt/sccolorspacedata_cmyk.h
===================================================================
--- scribus/colormgmt/sccolorspacedata_cmyk.h	(revision 15127)
+++ scribus/colormgmt/sccolorspacedata_cmyk.h	(revision 15128)
@@ -19,6 +19,7 @@
 public:
 	ScColorSpaceDataTempl_CMYK(ScColorProfile& profile);
 
+	virtual uint alphaIndex(void) const { return 0; }
 	virtual void flattenAlpha(void* dataIn, uint numElems) const {};
 };
 
Index: scribus/colormgmt/sclcmscolortransformimpl.h
===================================================================
--- scribus/colormgmt/sclcmscolortransformimpl.h	(revision 15127)
+++ scribus/colormgmt/sclcmscolortransformimpl.h	(revision 15128)
@@ -25,8 +25,6 @@
 	virtual bool apply(void* input, void* output, uint numElem);
 	virtual bool apply(QByteArray& input, QByteArray& output, uint numElem);
 
-	virtual void changeBufferFormat(eColorFormat input, eColorFormat output);
-
 protected:
 	cmsHTRANSFORM m_transformHandle;
 
Index: scribus/colormgmt/sccolormgmtenginefactory.cpp
===================================================================
--- scribus/colormgmt/sccolormgmtenginefactory.cpp	(revision 15127)
+++ scribus/colormgmt/sccolormgmtenginefactory.cpp	(revision 15128)
@@ -5,8 +5,14 @@
 for which a new license (GPL+exception) is in place.
 */
 
+#include "scconfig.h"
 #include "sccolormgmtenginefactory.h"
+
+#ifdef HAVE_LCMS2
+#include "sclcms2colormgmtengineimpl.h"
+#else
 #include "sclcmscolormgmtengineimpl.h"
+#endif
 
 ScColorMgmtEngineFactory colorMgmtEngineFactory;
 
@@ -18,6 +24,11 @@
 
 ScColorMgmtEngine ScColorMgmtEngineFactory::createDefaultEngine()
 {
+#ifdef HAVE_LCMS2
+	ScColorMgmtEngine lcms2Engine(new ScLcms2ColorMgmtEngineImpl());
+	return lcms2Engine;
+#else
 	ScColorMgmtEngine lcmsEngine(new ScLcmsColorMgmtEngineImpl());
 	return lcmsEngine;
+#endif
 }
\ No newline at end of file
Index: scribus/colormgmt/sccolorspacedata.h
===================================================================
--- scribus/colormgmt/sccolorspacedata.h	(revision 15127)
+++ scribus/colormgmt/sccolorspacedata.h	(revision 15128)
@@ -33,6 +33,9 @@
 	virtual ScColorMgmtEngine& engine() { return m_profile.engine(); }
 	virtual const ScColorMgmtEngine& engine() const { return m_profile.engine(); }
 
+	// Index of alpha data
+	virtual uint  alphaIndex(void) const = 0;
+
 	// Restore full opacity of alpha channel
 	virtual void flattenAlpha(void* dataIn, uint numElems) const = 0;
 
Index: scribus/colormgmt/sccolorspace.cpp
===================================================================
--- scribus/colormgmt/sccolorspace.cpp	(revision 15127)
+++ scribus/colormgmt/sccolorspace.cpp	(revision 15128)
@@ -61,6 +61,13 @@
 	return false;
 }
 
+uint  ScColorSpace::alphaIndex(void) const
+{
+	if (m_data)
+		return m_data->alphaIndex();
+	return 0;
+}
+
 void ScColorSpace::flattenAlpha(void* dataIn, uint numElems)
 {
 	if (m_data)
Index: scribus/colormgmt/CMakeLists.txt
===================================================================
--- scribus/colormgmt/CMakeLists.txt	(revision 15127)
+++ scribus/colormgmt/CMakeLists.txt	(revision 15128)
@@ -4,6 +4,20 @@
 ${LCMS_INCLUDE_DIR}
 )
 
+IF(HAVE_LCMS2)
+	SET(SCRIBUS_LCMS_IMPL_SOURCES
+		sclcms2colormgmtengineimpl.cpp
+		sclcms2colorprofileimpl.cpp
+		sclcms2colortransformimpl.cpp
+	)
+ELSE(HAVE_LCMS2)
+	SET(SCRIBUS_LCMS_IMPL_SOURCES
+		sclcmscolormgmtengineimpl.cpp
+		sclcmscolorprofileimpl.cpp
+		sclcmscolortransformimpl.cpp
+	)
+ENDIF(HAVE_LCMS2)
+
 SET(SCRIBUS_COLORMGMT_LIB_SOURCES
 	sccolormgmtengine.cpp
 	sccolormgmtenginedata.cpp
@@ -20,7 +34,9 @@
 	sclcmscolormgmtengineimpl.cpp
 	sclcmscolorprofileimpl.cpp
 	sclcmscolortransformimpl.cpp
+	${SCRIBUS_LCMS_IMPL_SOURCES}
 )
+
 SET(SCRIBUS_COLORMGMT_LIB "scribus_colormgmt_lib")
 ADD_LIBRARY(${SCRIBUS_COLORMGMT_LIB} STATIC ${SCRIBUS_COLORMGMT_LIB_SOURCES})
 # This is a convenience library that for linkage purposes is part of Scribus's
Index: scribus/colormgmt/sccolorspacedata_laba.h
===================================================================
--- scribus/colormgmt/sccolorspacedata_laba.h	(revision 15127)
+++ scribus/colormgmt/sccolorspacedata_laba.h	(revision 15128)
@@ -19,6 +19,7 @@
 public:
 	ScColorSpaceDataTempl_LabA(ScColorProfile& profile);
 
+	virtual uint alphaIndex(void) const { return m_AIndex; }
 	virtual void flattenAlpha(void* dataIn, uint numElems) const;
 };
 
Index: scribus/colormgmt/sclcmscolortransformimpl.cpp
===================================================================
--- scribus/colormgmt/sclcmscolortransformimpl.cpp	(revision 15127)
+++ scribus/colormgmt/sclcmscolortransformimpl.cpp	(revision 15128)
@@ -44,16 +44,6 @@
 	return false;
 }
 
-void ScLcmsColorTransformImpl::changeBufferFormat(eColorFormat input, eColorFormat output)
-{
-	if (m_transformHandle)
-	{
-		DWORD lcmsInput  = ScLcmsColorMgmtEngineImpl::translateFormatToLcmsFormat(input);
-		DWORD lcmsOutput = ScLcmsColorMgmtEngineImpl::translateFormatToLcmsFormat(output);
-		cmsChangeBuffersFormat(m_transformHandle, lcmsInput, lcmsOutput);
-	}
-}
-
 void ScLcmsColorTransformImpl::deleteTransform(void)
 {
 	if (m_transformHandle)
Index: scribus/colormgmt/sccolorspacedata_cmyka.h
===================================================================
--- scribus/colormgmt/sccolorspacedata_cmyka.h	(revision 15127)
+++ scribus/colormgmt/sccolorspacedata_cmyka.h	(revision 15128)
@@ -20,6 +20,7 @@
 public:
 	ScColorSpaceDataTempl_CMYKA(ScColorProfile& profile);
 
+	virtual uint alphaIndex(void) const { return m_aIndex; }
 	virtual void flattenAlpha(void* dataIn, uint numElems) const;
 };
 
Index: scribus/colormgmt/sccolortransform.h
===================================================================
--- scribus/colormgmt/sccolortransform.h	(revision 15127)
+++ scribus/colormgmt/sccolortransform.h	(revision 15128)
@@ -32,9 +32,6 @@
 	bool apply(void* input, void* output, uint numElem);
 	bool apply(QByteArray& input, QByteArray& output, uint numElem);
 
-	// FIXME get rif of this API as soon as possible (cf scimage)
-	void changeBufferFormat(eColorFormat input, eColorFormat output);
-
 	bool operator==(const ScColorTransform& other) const;
 
 protected:
Index: scribus/colormgmt/sccolorspacedata_rgb.h
===================================================================
--- scribus/colormgmt/sccolorspacedata_rgb.h	(revision 15127)
+++ scribus/colormgmt/sccolorspacedata_rgb.h	(revision 15128)
@@ -18,6 +18,7 @@
 public:
 	ScColorSpaceDataTempl_RGB(ScColorProfile& profile);
 
+	virtual uint alphaIndex(void) const { return 0; }
 	virtual void flattenAlpha(void* dataIn, uint numElems) const {};
 };
 
Index: scribus/colormgmt/sccolorspacedata_rgba.h
===================================================================
--- scribus/colormgmt/sccolorspacedata_rgba.h	(revision 15127)
+++ scribus/colormgmt/sccolorspacedata_rgba.h	(revision 15128)
@@ -19,6 +19,7 @@
 public:
 	ScColorSpaceDataTempl_RGBA(ScColorProfile& profile);
 
+	virtual uint alphaIndex(void) const { return m_aIndex; }
 	virtual void flattenAlpha(void* dataIn, uint numElems) const;
 };
 
Index: scribus/colormgmt/sclcmscolormgmtengineimpl.cpp
===================================================================
--- scribus/colormgmt/sclcmscolormgmtengineimpl.cpp	(revision 15127)
+++ scribus/colormgmt/sclcmscolormgmtengineimpl.cpp	(revision 15128)
@@ -553,27 +553,27 @@
 eColorSpaceType ScLcmsColorMgmtEngineImpl::translateLcmsColorSpaceType(icColorSpaceSignature signature)
 {
 	eColorSpaceType colorSpaceType = ColorSpace_Unknown;
-    if (signature == icSigXYZData)
-		colorSpaceType = ColorSpace_XYZ;
-    if (signature == icSigLabData)
-		colorSpaceType = ColorSpace_Lab;
-    if (signature == icSigLuvData)
-		colorSpaceType = ColorSpace_Luv;
-    if (signature == icSigYCbCrData)
-		colorSpaceType = ColorSpace_YCbCr;
-    if (signature == icSigYxyData)
-		colorSpaceType = ColorSpace_Yxy;
-    if (signature == icSigRgbData)
-		colorSpaceType = ColorSpace_Rgb;
-    if (signature == icSigGrayData)
-		colorSpaceType = ColorSpace_Gray;
-    if (signature == icSigHsvData)
-		colorSpaceType = ColorSpace_Hsv;
-    if (signature == icSigHlsData)
-		colorSpaceType = ColorSpace_Hls;
-    if (signature == icSigCmykData)
-		colorSpaceType = ColorSpace_Cmyk;
-    if (signature == icSigCmyData)
+    if (signature == icSigXYZData)
+		colorSpaceType = ColorSpace_XYZ;
+    if (signature == icSigLabData)
+		colorSpaceType = ColorSpace_Lab;
+    if (signature == icSigLuvData)
+		colorSpaceType = ColorSpace_Luv;
+    if (signature == icSigYCbCrData)
+		colorSpaceType = ColorSpace_YCbCr;
+    if (signature == icSigYxyData)
+		colorSpaceType = ColorSpace_Yxy;
+    if (signature == icSigRgbData)
+		colorSpaceType = ColorSpace_Rgb;
+    if (signature == icSigGrayData)
+		colorSpaceType = ColorSpace_Gray;
+    if (signature == icSigHsvData)
+		colorSpaceType = ColorSpace_Hsv;
+    if (signature == icSigHlsData)
+		colorSpaceType = ColorSpace_Hls;
+    if (signature == icSigCmykData)
+		colorSpaceType = ColorSpace_Cmyk;
+    if (signature == icSigCmyData)
 		colorSpaceType = ColorSpace_Cmy;
 	return colorSpaceType;
 }
@@ -581,19 +581,19 @@
 eProfileClass ScLcmsColorMgmtEngineImpl::translateLcmsProfileClass(icProfileClassSignature signature)
 {
 	eProfileClass profileClass = Class_Unknown;
-	if (signature == icSigInputClass)
-		profileClass = Class_Input;
-    if (signature == icSigDisplayClass)
-		profileClass = Class_Display;
-    if (signature == icSigOutputClass)
-		profileClass = Class_Output;
-    if (signature == icSigLinkClass)
-		profileClass = Class_Link;
-    if (signature == icSigAbstractClass)
-		profileClass = Class_Abstract;
-    if (signature == icSigColorSpaceClass)
-		profileClass = Class_ColorSpace;
-    if (signature == icSigNamedColorClass)
+	if (signature == icSigInputClass)
+		profileClass = Class_Input;
+    if (signature == icSigDisplayClass)
+		profileClass = Class_Display;
+    if (signature == icSigOutputClass)
+		profileClass = Class_Output;
+    if (signature == icSigLinkClass)
+		profileClass = Class_Link;
+    if (signature == icSigAbstractClass)
+		profileClass = Class_Abstract;
+    if (signature == icSigColorSpaceClass)
+		profileClass = Class_ColorSpace;
+    if (signature == icSigNamedColorClass)
 		profileClass = Class_NamedColor;
 	return profileClass;
 }
Index: scribus/colormgmt/sccolorspace.h
===================================================================
--- scribus/colormgmt/sccolorspace.h	(revision 15127)
+++ scribus/colormgmt/sccolorspace.h	(revision 15128)
@@ -34,7 +34,9 @@
 
 	uint  numChannels(void)     const;
 	uint  bytesPerChannel(void) const;
+
 	bool  hasAlphaChannel(void) const;
+	uint  alphaIndex(void)      const;
 
 	// Restore full opacity of alpha channel
 	void flattenAlpha(void* dataIn, uint numElems);
Index: scribus/scimgdataloader_psd.h
===================================================================
--- scribus/scimgdataloader_psd.h	(revision 15127)
+++ scribus/scimgdataloader_psd.h	(revision 15128)
@@ -35,6 +35,8 @@
 	virtual void loadEmbeddedProfile(const QString& fn, int page = 0);
 	virtual bool loadPicture(const QString& fn, int page, int res, bool thumbnail);
 
+	virtual bool useRawImage() { return true; }
+
 protected:
 
 	QList<unsigned int> colorTable;




More information about the scribus-commit mailing list