r13986 by herm - Added error checking.

scribus-commit scribus-commit at lists.scribus.net
Mon Sep 14 03:00:16 CEST 2009


Revision: 13986
Author: herm
Date: 2009-09-14T00:59:18.718526Z
Commit message: Added error checking.


Changeset: 
M  /trunk/Scribus/scribus/scimgdataloader_gmagick.cpp

Diffs:
Index: scribus/scimgdataloader_gmagick.cpp
===================================================================
--- scribus/scimgdataloader_gmagick.cpp	(revision 13985)
+++ scribus/scimgdataloader_gmagick.cpp	(revision 13986)
@@ -37,8 +37,24 @@
 	bool hasAlpha = input->matte();
 	if (!output->create(width, height, hasAlpha ? 5 : 4)) return false;
 	const PixelPacket *pixels = input->getConstPixels(0, 0, width, height);
-	const IndexPacket *alpha  = input->getConstIndexes();
+	if (!pixels) {
+	   qCritical() << QObject::tr("Could not get pixel data!");
+	   return false;
+    }
+
+    const IndexPacket *alpha;
+    if (hasAlpha) {
+        alpha = input->getConstIndexes();
+        if (!alpha) {
+            qCritical() << QObject::tr("Could not get alpha channel data!");
+            return false;
+        }
+    }
 	unsigned char *buffer = output->bits();
+	if (!buffer) {
+	   qCritical() << QObject::tr("Could not allocate output buffer!");
+	   return false;
+    }
 
 	int i;
 	for (i = 0; i < width*height; i++) {
@@ -64,8 +80,16 @@
 	
 	bool hasAlpha = input->matte();
 	const PixelPacket *pixels = input->getConstPixels(0, 0, width, height);
+    if (!pixels) {
+	   qCritical() << QObject::tr("Could not get pixel data!");
+	   return false;
+    }
 	unsigned char *buffer = output->bits();
-
+	if (!buffer) {
+	   qCritical() << QObject::tr("Could not allocate output buffer!");
+	   return false;
+    }
+    
 	int i;
 	for (i = 0; i < width*height; i++) {
 		*buffer++ = ScaleQuantumToChar(GetBlueSample(pixels[i]));
@@ -187,11 +211,6 @@
 		double yres = image.yResolution();
 		int resInf = m_imageInfoRecord.lowResType;
 		
-		/*NOTE: 
-			- The BGRO bit ordering was found by try'n'error
-			- Always use "O" for the alpha channel! "A" is inverted!
-			- image.write() is broken for cmyk images!
-		*/
 		if (image.colorSpace() == CMYKColorspace) {
 			qDebug() << "CMYK image";
 			m_useRawImage = true;




More information about the scribus-commit mailing list