src/pixmap.cc
branchpyrit
changeset 95 ca7d4c665531
parent 92 9af5c039b678
child 103 3b3257a410fe
--- a/src/pixmap.cc	Thu May 08 09:21:25 2008 +0200
+++ b/src/pixmap.cc	Sat May 10 14:29:37 2008 +0200
@@ -47,13 +47,22 @@
 #else
 	__m128 cmax = _mm_set_ps1(255.0);
 	__m64 m;
-	for (unsigned char *cd = cdata; cd < cdata + w*h*3; cd += 4, fd += 4)
-	{
-		m = _mm_cvtps_pi16(_mm_mul_ps(cmax,
-			_mm_min_ps(mOne, _mm_load_ps(fd))));
-		for (int i = 0; i < 4; i++)
-			cd[i] = ((unsigned char *)&m)[i<<1];
-	}
+	if (!refdata)
+		for (unsigned char *cd = cdata; cd < cdata + w*h*3; cd += 4, fd += 4)
+		{
+			m = _mm_cvtps_pi16(_mm_mul_ps(cmax,
+				_mm_min_ps(mOne, _mm_load_ps(fd))));
+			for (int i = 0; i < 4; i++)
+				cd[i] = ((unsigned char *)&m)[i<<1];
+		}
+	else // must use _mm_loadu_ instead of _mm_load_ as we do not know the alignment
+		for (unsigned char *cd = cdata; cd < cdata + w*h*3; cd += 4, fd += 4)
+		{
+			m = _mm_cvtps_pi16(_mm_mul_ps(cmax,
+				_mm_min_ps(mOne, _mm_loadu_ps(fd))));
+			for (int i = 0; i < 4; i++)
+				cd[i] = ((unsigned char *)&m)[i<<1];
+		}
 #endif
 
 	return cdata;
@@ -62,6 +71,7 @@
 int Pixmap::writePNG(const char *fname) const
 {
 #ifndef HAVE_PNG
+	dbgmsg(0, "W %s not written: PNG support is disabled\n", fname);
 	return -3;
 #else
 	int y;