- // RGB order is reversed, and we need to premultiply
- // all channels by alpha value for use with ::AlphaBlend.
- const unsigned char a = *alpha++;
- *dst++ = (unsigned char)((src[2] * a + 127) / 255);
- *dst++ = (unsigned char)((src[1] * a + 127) / 255);
- *dst++ = (unsigned char)((src[0] * a + 127) / 255);
- *dst++ = a;
- src += 3;
+ case PixelFormat_PreMultiplied:
+ // Pre-multiply pixel values so that the DIB could be used
+ // with ::AlphaBlend().
+ for ( x = 0; x < w; x++ )
+ {
+ const unsigned char a = *alpha++;
+ *dst++ = (unsigned char)((src[2] * a + 127) / 255);
+ *dst++ = (unsigned char)((src[1] * a + 127) / 255);
+ *dst++ = (unsigned char)((src[0] * a + 127) / 255);
+ *dst++ = a;
+ src += 3;
+ }
+ break;
+
+ case PixelFormat_NotPreMultiplied:
+ // Just copy pixel data without changing it.
+ for ( x = 0; x < w; x++ )
+ {
+ *dst++ = src[2];
+ *dst++ = src[1];
+ *dst++ = src[0];
+
+ *dst++ = *alpha++;
+ src += 3;
+ }
+ break;