From 0cd9999e2c2c9b62105d1197e9443ebb2b744e24 Mon Sep 17 00:00:00 2001 From: mental Date: Wed, 29 Aug 2007 04:57:40 +0000 Subject: [PATCH] DNR bpp stuff so much --- src/libnr/nr-gradient.cpp | 68 ++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/src/libnr/nr-gradient.cpp b/src/libnr/nr-gradient.cpp index 9de84d707..fdeafa0ed 100644 --- a/src/libnr/nr-gradient.cpp +++ b/src/libnr/nr-gradient.cpp @@ -18,6 +18,7 @@ * Derived in part from public domain code by Lauris Kaplinski */ +#include #include #include #include @@ -68,8 +69,31 @@ static unsigned char const *color_at(NR::Coord r, } }; -template +template struct ModeTraits; + +template <> +struct ModeTraits { +static const unsigned bpp=4; +}; + +template <> +struct ModeTraits { +static const unsigned bpp=4; +}; + +template <> +struct ModeTraits { +static const unsigned bpp=3; +}; + +template <> +struct ModeTraits { +static const unsigned bpp=1; +}; + +template struct Compose { +static const unsigned bpp=ModeTraits::bpp; static void compose(NRPixBlock *pb, unsigned char *dest, NRPixBlock *spb, unsigned char const *src) { @@ -77,20 +101,19 @@ static void compose(NRPixBlock *pb, unsigned char *dest, } }; -template <> -struct Compose { +template +struct Compose { +static const unsigned bpp=ModeTraits::bpp; static void compose(NRPixBlock *pb, unsigned char *dest, NRPixBlock *spb, unsigned char const *src) { - dest[0] = src[0]; - dest[1] = src[1]; - dest[2] = src[2]; - dest[3] = src[3]; + std::memcpy(dest, src, bpp); } }; template <> struct Compose { +static const unsigned bpp=4; static void compose(NRPixBlock *pb, unsigned char *dest, NRPixBlock *spb, unsigned char const *src) { @@ -105,6 +128,7 @@ static void compose(NRPixBlock *pb, unsigned char *dest, template <> struct Compose { +static const unsigned bpp=4; static void compose(NRPixBlock *pb, unsigned char *dest, NRPixBlock *spb, unsigned char const *src) { @@ -117,6 +141,7 @@ static void compose(NRPixBlock *pb, unsigned char *dest, template <> struct Compose { +static const unsigned bpp=3; static void compose(NRPixBlock *pb, unsigned char *dest, NRPixBlock *spb, unsigned char const *src) { @@ -134,37 +159,37 @@ render_spread(NRGradientRenderer *gr, NRPixBlock *pb) case NR_PIXBLOCK_MODE_R8G8B8A8N: if (pb->empty) { typedef Compose compose; - Subtype::template render(gr, pb); + Subtype::template render(gr, pb); } else { typedef Compose compose; - Subtype::template render(gr, pb); + Subtype::template render(gr, pb); } break; case NR_PIXBLOCK_MODE_R8G8B8A8P: if (pb->empty) { typedef Compose compose; - Subtype::template render(gr, pb); + Subtype::template render(gr, pb); } else { typedef Compose compose; - Subtype::template render(gr, pb); + Subtype::template render(gr, pb); } break; case NR_PIXBLOCK_MODE_R8G8B8: if (pb->empty) { typedef Compose compose; - Subtype::template render(gr, pb); + Subtype::template render(gr, pb); } else { typedef Compose compose; - Subtype::template render(gr, pb); + Subtype::template render(gr, pb); } break; case NR_PIXBLOCK_MODE_A8: if (pb->empty) { typedef Compose compose; - Subtype::template render(gr, pb); + Subtype::template render(gr, pb); } else { typedef Compose compose; - Subtype::template render(gr, pb); + Subtype::template render(gr, pb); } break; } @@ -197,7 +222,7 @@ render(NRRenderer *r, NRPixBlock *pb, NRPixBlock *m) namespace { struct Linear { -template +template static void render(NRGradientRenderer *gr, NRPixBlock *pb) { NRLGradientRenderer *lgr = static_cast(gr); @@ -224,7 +249,7 @@ static void render(NRGradientRenderer *gr, NRPixBlock *pb) { for (x = 0; x < width; x++) { unsigned char const *s=spread::color_at(pos, lgr->vector); compose::compose(pb, d, &spb, s); - d += bpp; + d += compose::bpp; pos += lgr->dx; } } @@ -297,7 +322,7 @@ nr_lgradient_renderer_setup (NRLGradientRenderer *lgr, namespace { struct SymmetricRadial { -template +template static void render(NRGradientRenderer *gr, NRPixBlock *pb) { NRRGradientRenderer *rgr = static_cast(gr); @@ -320,7 +345,7 @@ static void render(NRGradientRenderer *gr, NRPixBlock *pb) NR::Coord const pos = sqrt(((gx*gx) + (gy*gy))); unsigned char const *s=spread::color_at(pos, rgr->vector); compose::compose(pb, d, &spb, s); - d += bpp; + d += compose::bpp; gx += dx; gy += dy; } @@ -331,7 +356,7 @@ static void render(NRGradientRenderer *gr, NRPixBlock *pb) }; struct Radial { -template +template static void render(NRGradientRenderer *gr, NRPixBlock *pb) { NRRGradientRenderer *rgr = static_cast(gr); @@ -373,8 +398,7 @@ static void render(NRGradientRenderer *gr, NRPixBlock *pb) } compose::compose(pb, d, &spb, s); - - d += bpp; + d += compose::bpp; gx += dx; gy += dy; -- 2.30.2