Code

fix compositing for premultiplication and non-alpha cases
authormental <mental@users.sourceforge.net>
Thu, 30 Aug 2007 03:58:15 +0000 (03:58 +0000)
committermental <mental@users.sourceforge.net>
Thu, 30 Aug 2007 03:58:15 +0000 (03:58 +0000)
src/libnr/nr-gradient.cpp

index fdeafa0ed0ddf1977ba52cc215e15e1464694e9a..2d52767bf2c189e56bf73de5679bc92f9b366e7f 100644 (file)
@@ -101,13 +101,48 @@ static void compose(NRPixBlock *pb, unsigned char *dest,
 }
 };
 
-template <NR_PIXBLOCK_MODE mode>
-struct Compose<mode, true> {
-static const unsigned bpp=ModeTraits<mode>::bpp;
+template <>
+struct Compose<NR_PIXBLOCK_MODE_R8G8B8A8N, true> {
+static const unsigned bpp=4;
+static void compose(NRPixBlock *pb, unsigned char *dest,
+                    NRPixBlock *spb, unsigned char const *src)
+{
+    std::memcpy(dest, src, 4);
+}
+};
+
+template <>
+struct Compose<NR_PIXBLOCK_MODE_R8G8B8A8P, true> {
+static const unsigned bpp=4;
+static void compose(NRPixBlock *pb, unsigned char *dest,
+                    NRPixBlock *spb, unsigned char const *src)
+{
+    dest[0] = NR_PREMUL_111(src[0], src[3]);
+    dest[1] = NR_PREMUL_111(src[1], src[3]);
+    dest[2] = NR_PREMUL_111(src[2], src[3]);
+    dest[3] = src[3];
+}
+};
+
+template <>
+struct Compose<NR_PIXBLOCK_MODE_R8G8B8, true> {
+static const unsigned bpp=3;
+static void compose(NRPixBlock *pb, unsigned char *dest,
+                    NRPixBlock *spb, unsigned char const *src)
+{
+    dest[0] = NR_COMPOSEN11_1111(src[0], src[3], 255);
+    dest[1] = NR_COMPOSEN11_1111(src[1], src[3], 255);
+    dest[2] = NR_COMPOSEN11_1111(src[2], src[3], 255);
+}
+};
+
+template <>
+struct Compose<NR_PIXBLOCK_MODE_A8, true> {
+static const unsigned bpp=1;
 static void compose(NRPixBlock *pb, unsigned char *dest,
                     NRPixBlock *spb, unsigned char const *src)
 {
-    std::memcpy(dest, src, bpp);
+    dest[0] = src[3];
 }
 };