]> granicus.if.org Git - graphviz/commitdiff
optimize in-place image transforms a bit
authorellson <devnull@localhost>
Fri, 7 Sep 2007 20:26:42 +0000 (20:26 +0000)
committerellson <devnull@localhost>
Fri, 7 Sep 2007 20:26:42 +0000 (20:26 +0000)
plugin/devil/gvdevice_devil.c
plugin/gdk_pixbuf/gvdevice_gdk_pixbuf.c

index e8707dd228b920f18eb003f1f17690cb1071a70a..48cc62fe746a344c643b84d53edd86d60d287645 100644 (file)
 static void
 Y_inv ( unsigned int width, unsigned int height, unsigned char *data)
 {
-        unsigned int x, y, rowsize, i;
-        unsigned char tmp, *data2;
+        unsigned int x, y, *a, *b, t;
 
-#define STRIDE 4
-
-        rowsize = width * STRIDE;
-        data2 = data + (height-1) * rowsize;
+       a = (unsigned int*)data;
+        b = a + (height-1) * width;
         for (y = 0; y < height/2; y++) {
                 for (x = 0; x < width; x++) {
-                        for (i = 0; i < STRIDE; i++) {
-                                tmp = *data;
-                                *data++ = *data2;
-                                *data2++ = tmp;
-                        }
+                       t = *a;
+                       *a++ = *b;
+                       *b++ = t;
                 }
-                data2 -= 2*rowsize;
+                b -= 2*width;
         }
 }
 
index 376d77c1c952d7264eb54c238ab53c10f74938c9..3027b178a4fbb69e13d68708c17ee74bde4fb156 100644 (file)
@@ -36,9 +36,9 @@ static void
 argb2rgba ( unsigned int width, unsigned int height, unsigned char *data)
 {
 /* define indexes to color bytes in each format */
-#define Ra 2
-#define Ga 1
 #define Ba 0
+#define Ga 1
+#define Ra 2
 #define Aa 3
 
 #define Rb 0
@@ -46,49 +46,14 @@ 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
-
+            /* swap red and blue */
+            unsigned char r = data[Ra];
+            data[Bb] = data[Ba];
+           data[Rb] = r;
             data += 4;
         }
     }