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
#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;
}
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;