[cairo-commit] cairo/test read-png.c,1.4,1.5

Carl Worth commit at pdx.freedesktop.org
Tue May 10 12:42:34 PDT 2005


Committed by: cworth

Update of /cvs/cairo/cairo/test
In directory gabe:/tmp/cvs-serv21965/test

Modified Files:
	read-png.c 
Log Message:

        * src/cairo-wideint.h: Don't guess and make our own definitions
        for uint8_t, etc. Just error out if we can't find a suitable
        header file.

        * src/cairo-png.c: (unpremultiply_data), (premultiply_data):
        * test/read-png.c: (premultiply_data): Fix to use fixed-size type
        so that this code works when sizeof(unsigned long) != 32. Thanks
        to Manish Singh.


Index: read-png.c
===================================================================
RCS file: /cvs/cairo/cairo/test/read-png.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- read-png.c	27 Apr 2005 20:33:25 -0000	1.4
+++ read-png.c	10 May 2005 19:42:32 -0000	1.5
@@ -25,6 +25,20 @@
  * Author: Carl D. Worth <cworth at isi.edu>
  */
 
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if   HAVE_STDINT_H
+# include <stdint.h>
+#elif HAVE_INTTYPES_H
+# include <inttypes.h>
+#elif HAVE_SYS_INT_TYPES_H
+# include <sys/int_types.h>
+#else
+#error Cannot find definitions for fixed-width integral types (uint8_t, uint32_t, etc.)
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <png.h>
@@ -40,18 +54,18 @@
     int i;
 
     for (i = 0; i < row_info->rowbytes; i += 4) {
-	unsigned char  *base = &data[i];
-	unsigned char  blue = base[0];
-	unsigned char  green = base[1];
-	unsigned char  red = base[2];
-	unsigned char  alpha = base[3];
-	unsigned long	p;
+	uint8_t *base = &data[i];
+	uint8_t  blue = base[0];
+	uint8_t  green = base[1];
+	uint8_t  red = base[2];
+	uint8_t  alpha = base[3];
+	uint32_t p;
 
 	red = ((unsigned) red * (unsigned) alpha + 127) / 255;
 	green = ((unsigned) green * (unsigned) alpha + 127) / 255;
 	blue = ((unsigned) blue * (unsigned) alpha + 127) / 255;
 	p = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);
-	memcpy (base, &p, sizeof (unsigned long));
+	memcpy (base, &p, sizeof (uint32_t));
     }
 }
 




More information about the cairo-commit mailing list