summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 24d8e4e)
raw | patch | inline | side by side (parent: 24d8e4e)
author | mental <mental@users.sourceforge.net> | |
Wed, 29 Aug 2007 04:57:40 +0000 (04:57 +0000) | ||
committer | mental <mental@users.sourceforge.net> | |
Wed, 29 Aug 2007 04:57:40 +0000 (04:57 +0000) |
src/libnr/nr-gradient.cpp | patch | blob | history |
index 9de84d707a1819b17936ab901de6697c0cb09bc2..fdeafa0ed0ddf1977ba52cc215e15e1464694e9a 100644 (file)
* Derived in part from public domain code by Lauris Kaplinski
*/
+#include <cstring>
#include <libnr/nr-pixops.h>
#include <libnr/nr-pixblock-pixel.h>
#include <libnr/nr-blit.h>
}
};
-template <NR_PIXBLOCK_MODE mode, bool empty=false>
+template <NR_PIXBLOCK_MODE mode> struct ModeTraits;
+
+template <>
+struct ModeTraits<NR_PIXBLOCK_MODE_R8G8B8A8N> {
+static const unsigned bpp=4;
+};
+
+template <>
+struct ModeTraits<NR_PIXBLOCK_MODE_R8G8B8A8P> {
+static const unsigned bpp=4;
+};
+
+template <>
+struct ModeTraits<NR_PIXBLOCK_MODE_R8G8B8> {
+static const unsigned bpp=3;
+};
+
+template <>
+struct ModeTraits<NR_PIXBLOCK_MODE_A8> {
+static const unsigned bpp=1;
+};
+
+template <NR_PIXBLOCK_MODE mode, bool empty>
struct Compose {
+static const unsigned bpp=ModeTraits<mode>::bpp;
static void compose(NRPixBlock *pb, unsigned char *dest,
NRPixBlock *spb, unsigned char const *src)
{
}
};
-template <>
-struct Compose<NR_PIXBLOCK_MODE_R8G8B8A8N, true> {
+template <NR_PIXBLOCK_MODE mode>
+struct Compose<mode, true> {
+static const unsigned bpp=ModeTraits<mode>::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<NR_PIXBLOCK_MODE_R8G8B8A8N, false> {
+static const unsigned bpp=4;
static void compose(NRPixBlock *pb, unsigned char *dest,
NRPixBlock *spb, unsigned char const *src)
{
template <>
struct Compose<NR_PIXBLOCK_MODE_R8G8B8A8P, false> {
+static const unsigned bpp=4;
static void compose(NRPixBlock *pb, unsigned char *dest,
NRPixBlock *spb, unsigned char const *src)
{
template <>
struct Compose<NR_PIXBLOCK_MODE_R8G8B8, false> {
+static const unsigned bpp=3;
static void compose(NRPixBlock *pb, unsigned char *dest,
NRPixBlock *spb, unsigned char const *src)
{
case NR_PIXBLOCK_MODE_R8G8B8A8N:
if (pb->empty) {
typedef Compose<NR_PIXBLOCK_MODE_R8G8B8A8N, true> compose;
- Subtype::template render<compose, spread, 4>(gr, pb);
+ Subtype::template render<compose, spread>(gr, pb);
} else {
typedef Compose<NR_PIXBLOCK_MODE_R8G8B8A8N, false> compose;
- Subtype::template render<compose, spread, 4>(gr, pb);
+ Subtype::template render<compose, spread>(gr, pb);
}
break;
case NR_PIXBLOCK_MODE_R8G8B8A8P:
if (pb->empty) {
typedef Compose<NR_PIXBLOCK_MODE_R8G8B8A8P, true> compose;
- Subtype::template render<compose, spread, 4>(gr, pb);
+ Subtype::template render<compose, spread>(gr, pb);
} else {
typedef Compose<NR_PIXBLOCK_MODE_R8G8B8A8P, false> compose;
- Subtype::template render<compose, spread, 4>(gr, pb);
+ Subtype::template render<compose, spread>(gr, pb);
}
break;
case NR_PIXBLOCK_MODE_R8G8B8:
if (pb->empty) {
typedef Compose<NR_PIXBLOCK_MODE_R8G8B8, true> compose;
- Subtype::template render<compose, spread, 3>(gr, pb);
+ Subtype::template render<compose, spread>(gr, pb);
} else {
typedef Compose<NR_PIXBLOCK_MODE_R8G8B8, false> compose;
- Subtype::template render<compose, spread, 3>(gr, pb);
+ Subtype::template render<compose, spread>(gr, pb);
}
break;
case NR_PIXBLOCK_MODE_A8:
if (pb->empty) {
typedef Compose<NR_PIXBLOCK_MODE_A8, true> compose;
- Subtype::template render<compose, spread, 1>(gr, pb);
+ Subtype::template render<compose, spread>(gr, pb);
} else {
typedef Compose<NR_PIXBLOCK_MODE_A8, false> compose;
- Subtype::template render<compose, spread, 1>(gr, pb);
+ Subtype::template render<compose, spread>(gr, pb);
}
break;
}
namespace {
struct Linear {
-template <typename compose, typename spread, unsigned bpp>
+template <typename compose, typename spread>
static void render(NRGradientRenderer *gr, NRPixBlock *pb) {
NRLGradientRenderer *lgr = static_cast<NRLGradientRenderer *>(gr);
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;
}
}
namespace {
struct SymmetricRadial {
-template <typename compose, typename spread, unsigned bpp>
+template <typename compose, typename spread>
static void render(NRGradientRenderer *gr, NRPixBlock *pb)
{
NRRGradientRenderer *rgr = static_cast<NRRGradientRenderer *>(gr);
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;
}
};
struct Radial {
-template <typename compose, typename spread, unsigned bpp>
+template <typename compose, typename spread>
static void render(NRGradientRenderer *gr, NRPixBlock *pb)
{
NRRGradientRenderer *rgr = static_cast<NRRGradientRenderer *>(gr);
}
compose::compose(pb, d, &spb, s);
-
- d += bpp;
+ d += compose::bpp;
gx += dx;
gy += dy;