+
+static void encodeMonochromeImage(RGBA*data, int width, int height, RGBA*colors)
+{
+ int t;
+ int len = width*height;
+
+ U32* img = (U32*)data;
+ U32 color1 = img[0];
+ U32 color2 = 0;
+ for(t=1;t<len;t++) {
+ if(img[t] != color1) {
+ color2 = img[t];
+ break;
+ }
+ }
+ *(U32*)&colors[0] = color1;
+ *(U32*)&colors[1] = color2;
+ for(t=0;t<len;t++) {
+ if(img[t] == color1) {
+ img[t] = 0;
+ } else {
+ img[t] = 0xffffffff;
+ }
+ }
+}
+
+static void decodeMonochromeImage(RGBA*data, int width, int height, RGBA*colors)
+{
+ int t;
+ int len = width*height;
+
+ for(t=0;t<len;t++) {
+ U32 m = data[t].r;
+ data[t].r = (colors[0].r * (255-m) + colors[1].r * m) >> 8;
+ data[t].g = (colors[0].g * (255-m) + colors[1].g * m) >> 8;
+ data[t].b = (colors[0].b * (255-m) + colors[1].b * m) >> 8;
+ data[t].a = (colors[0].a * (255-m) + colors[1].a * m) >> 8;
+ }
+}
+