summaryrefslogtreecommitdiffstats
path: root/src/sp-gradient.cpp
diff options
context:
space:
mode:
authorJasper van de Gronde <jasper.vandegronde@gmail.com>2009-04-04 13:26:17 +0000
committerjaspervdg <jaspervdg@users.sourceforge.net>2009-04-04 13:26:17 +0000
commita05cd9a724949f71f6a331aef920e193cff7231b (patch)
treee53d88e002cd18977dc51c52c70b34b82dd7d696 /src/sp-gradient.cpp
parentMinor French translation update. (diff)
downloadinkscape-a05cd9a724949f71f6a331aef920e193cff7231b.tar.gz
inkscape-a05cd9a724949f71f6a331aef920e193cff7231b.zip
Some extra comments.
(bzr r7622)
Diffstat (limited to '')
-rw-r--r--src/sp-gradient.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp
index 1d41e2042..84a0a9870 100644
--- a/src/sp-gradient.cpp
+++ b/src/sp-gradient.cpp
@@ -1095,18 +1095,18 @@ sp_gradient_ensure_colors(SPGradient *gr)
double remainder_for_end[4] = {0,0,0,0}; // Used at the end
switch(gr->spread) {
case SP_GRADIENT_SPREAD_PAD:
- remainder[0] = 0.5*gr->vector.stops[0].color.v.c[0];
+ remainder[0] = 0.5*gr->vector.stops[0].color.v.c[0]; // Half of the first cell uses the color of the first stop
remainder[1] = 0.5*gr->vector.stops[0].color.v.c[1];
remainder[2] = 0.5*gr->vector.stops[0].color.v.c[2];
remainder[3] = 0.5*gr->vector.stops[0].opacity;
- remainder_for_end[0] = 0.5*gr->vector.stops[gr->vector.stops.size() - 1].color.v.c[0];
+ remainder_for_end[0] = 0.5*gr->vector.stops[gr->vector.stops.size() - 1].color.v.c[0]; // Half of the first cell uses the color of the last stop
remainder_for_end[1] = 0.5*gr->vector.stops[gr->vector.stops.size() - 1].color.v.c[1];
remainder_for_end[2] = 0.5*gr->vector.stops[gr->vector.stops.size() - 1].color.v.c[2];
remainder_for_end[3] = 0.5*gr->vector.stops[gr->vector.stops.size() - 1].opacity;
break;
case SP_GRADIENT_SPREAD_REFLECT:
- break;
case SP_GRADIENT_SPREAD_REPEAT:
+ // These two are handled differently, see below.
break;
default:
g_error("Spread type not supported!");
@@ -1160,16 +1160,19 @@ sp_gradient_ensure_colors(SPGradient *gr)
double dt = ob+.5-o0;
f = 0.5*dt*df;
if (ob==0 && gr->spread==SP_GRADIENT_SPREAD_REFLECT) {
+ // The first half of the first cell is just a mirror image of the second half, so simply multiply it by 2.
gr->color[4 * ob + 0] = (unsigned char) floor(2*255*(remainder[0] + dt*(r0 + f*(r1-r0))) + .5);
gr->color[4 * ob + 1] = (unsigned char) floor(2*255*(remainder[1] + dt*(g0 + f*(g1-g0))) + .5);
gr->color[4 * ob + 2] = (unsigned char) floor(2*255*(remainder[2] + dt*(b0 + f*(b1-b0))) + .5);
gr->color[4 * ob + 3] = (unsigned char) floor(2*255*(remainder[3] + dt*(a0 + f*(a1-a0))) + .5);
} else if (ob==0 && gr->spread==SP_GRADIENT_SPREAD_REPEAT) {
+ // The first cell is the same as the last cell, so save whatever is in the second half here and deal with the rest later.
remainder_for_end[0] = remainder[0] + dt*(r0 + f*(r1-r0));
remainder_for_end[1] = remainder[1] + dt*(g0 + f*(g1-g0));
remainder_for_end[2] = remainder[2] + dt*(b0 + f*(b1-b0));
remainder_for_end[3] = remainder[3] + dt*(a0 + f*(a1-a0));
} else {
+ // The first half of the cell was already in remainder.
gr->color[4 * ob + 0] = (unsigned char) floor(255*(remainder[0] + dt*(r0 + f*(r1-r0))) + .5);
gr->color[4 * ob + 1] = (unsigned char) floor(255*(remainder[1] + dt*(g0 + f*(g1-g0))) + .5);
gr->color[4 * ob + 2] = (unsigned char) floor(255*(remainder[2] + dt*(b0 + f*(b1-b0))) + .5);
@@ -1197,12 +1200,14 @@ sp_gradient_ensure_colors(SPGradient *gr)
gr->color[4 * (NCOLORS-1) + 3] = (unsigned char) floor(255*(remainder[3]+remainder_for_end[3]) + .5);
break;
case SP_GRADIENT_SPREAD_REFLECT:
+ // The second half is the same as the first half, so multiply by 2.
gr->color[4 * (NCOLORS-1) + 0] = (unsigned char) floor(2*255*remainder[0] + .5);
gr->color[4 * (NCOLORS-1) + 1] = (unsigned char) floor(2*255*remainder[1] + .5);
gr->color[4 * (NCOLORS-1) + 2] = (unsigned char) floor(2*255*remainder[2] + .5);
gr->color[4 * (NCOLORS-1) + 3] = (unsigned char) floor(2*255*remainder[3] + .5);
break;
case SP_GRADIENT_SPREAD_REPEAT:
+ // The second half is the same as the second half of the first cell (which was saved in remainder_for_end).
gr->color[0] = gr->color[4 * (NCOLORS-1) + 0] = (unsigned char) floor(255*(remainder[0]+remainder_for_end[0]) + .5);
gr->color[1] = gr->color[4 * (NCOLORS-1) + 1] = (unsigned char) floor(255*(remainder[1]+remainder_for_end[1]) + .5);
gr->color[2] = gr->color[4 * (NCOLORS-1) + 2] = (unsigned char) floor(255*(remainder[2]+remainder_for_end[2]) + .5);