From: mental Date: Thu, 30 Aug 2007 03:58:15 +0000 (+0000) Subject: fix compositing for premultiplication and non-alpha cases X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7cdcd76996e5e33b0ce8bea84fa8dc68024ebdfb;p=inkscape.git fix compositing for premultiplication and non-alpha cases --- diff --git a/src/libnr/nr-gradient.cpp b/src/libnr/nr-gradient.cpp index fdeafa0ed..2d52767bf 100644 --- a/src/libnr/nr-gradient.cpp +++ b/src/libnr/nr-gradient.cpp @@ -101,13 +101,48 @@ static void compose(NRPixBlock *pb, unsigned char *dest, } }; -template -struct Compose { -static const unsigned bpp=ModeTraits::bpp; +template <> +struct Compose { +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 { +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 { +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 { +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]; } };