]> granicus.if.org Git - graphviz/commitdiff
bug fix and minor optimization
authorellson <devnull@localhost>
Thu, 30 Aug 2007 13:00:16 +0000 (13:00 +0000)
committerellson <devnull@localhost>
Thu, 30 Aug 2007 13:00:16 +0000 (13:00 +0000)
plugin/gdk_pixbuf/gvdevice_gdk_pixbuf.c

index 6d75b2fb195c34735795031a3dd6eabf88994557..7782d1649d9327aa88374712e0129e2e34f63313 100644 (file)
@@ -39,9 +39,7 @@ typedef enum {
 static void
 argb2rgba ( unsigned int width, unsigned int height, unsigned char *data)
 {
-    unsigned int x, y;
-    unsigned char r, g, b, a;
-
+/* define indexes to color bytes in each format */
 #define Ra 2
 #define Ga 1
 #define Ba 0
@@ -52,17 +50,48 @@ argb2rgba ( unsigned int width, unsigned int height, unsigned char *data)
 #define Bb 2
 #define Ab 3
 
+/* only need to process those bytes whose index is different */
+#if (Ra != Rb)
+    unsigned char r;
+#endif
+#if (Ga != Gb)
+    unsigned char g;
+#endif
+#if (Ba != Bb)
+    unsigned char b;
+#endif
+#if (Aa != Ab)
+    unsigned char a;
+#endif
+    unsigned int x, y;
+
     for (y = 0; y < height; y++) {
         for (x = 0; x < width; x++) {
+#if (Ra != Rb)
             r = data[Ra];
+#endif
+#if (Ga != Gb)
             g = data[Ga];
+#endif
+#if (Ba != Bb)
             b = data[Ba];
+#endif
+#if (Aa != Ab)
             a = data[Aa];
+#endif
 
+#if (Ra != Rb)
             data[Rb] = r;
+#endif
+#if (Ga != Gb)
             data[Gb] = g;
+#endif
+#if (Ba != Bb)
             data[Bb] = b;
+#endif
+#if (Aa != Ab)
             data[Ab] = a;
+#endif
 
             data += 4;
         }
@@ -72,7 +101,6 @@ argb2rgba ( unsigned int width, unsigned int height, unsigned char *data)
 static gboolean
 writer ( const gchar *buf, gsize count, GError **error, gpointer data)
 {
-    error = NULL;
     if (count == fwrite(buf, 1, count, (FILE *)data))
         return TRUE;
     return FALSE;