diff options
| author | MenTaLguY <mental@rydia.net> | 2007-08-21 03:46:10 +0000 |
|---|---|---|
| committer | mental <mental@users.sourceforge.net> | 2007-08-21 03:46:10 +0000 |
| commit | 9c5094f6e6e72f42d8a9558384b24b43fcffb28b (patch) | |
| tree | ffed18df74884dd52c580c3002acfb79da89a1b8 /src | |
| parent | factor out gradient index calculation (diff) | |
| download | inkscape-9c5094f6e6e72f42d8a9558384b24b43fcffb28b.tar.gz inkscape-9c5094f6e6e72f42d8a9558384b24b43fcffb28b.zip | |
experimental: add some noise to the gradient function
(bzr r3564)
Diffstat (limited to 'src')
| -rw-r--r-- | src/libnr/nr-gradient.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libnr/nr-gradient.cpp b/src/libnr/nr-gradient.cpp index d4ce764c1..cd771e7de 100644 --- a/src/libnr/nr-gradient.cpp +++ b/src/libnr/nr-gradient.cpp @@ -20,6 +20,8 @@ #include <libnr/nr-pixblock-pixel.h> #include <libnr/nr-blit.h> #include <libnr/nr-gradient.h> +#include <glib/gtypes.h> +#include <stdio.h> /* Common */ @@ -28,6 +30,15 @@ #define NRG_MASK (NR_GRADIENT_VECTOR_LENGTH - 1) #define NRG_2MASK ((long long) ((NR_GRADIENT_VECTOR_LENGTH << 1) - 1)) +static guint32 msr_state=0xfefefefe; + +inline guint32 msr_next() { + guint32 lsb = msr_state & 1; + guint32 msb = ( lsb << 31 ) ^ ( ( msr_state & 2) << 30 ); + msr_state = ( msr_state >> 1 ) | msb; + return lsb; +} + inline unsigned char const *index_to_pointer(int idx, unsigned char const *vector) { @@ -37,18 +48,21 @@ inline unsigned char const *index_to_pointer(int idx, inline unsigned char const *r_to_pointer_pad(NR::Coord r, unsigned char const *vector) { + r += msr_next(); return index_to_pointer((int)CLAMP(r, 0, (double)(NR_GRADIENT_VECTOR_LENGTH - 1)), vector); } inline unsigned char const *r_to_pointer_repeat(NR::Coord r, unsigned char const *vector) { + r += msr_next(); return index_to_pointer((int)((long long)r & NRG_MASK), vector); } inline unsigned char const *r_to_pointer_reflect(NR::Coord r, unsigned char const *vector) { + r += msr_next(); int idx = (int) ((long long)r & NRG_2MASK); if (idx > NRG_MASK) idx = NRG_2MASK - idx; return index_to_pointer(idx, vector); |
