From: jaspervdg Date: Sat, 4 Apr 2009 13:26:17 +0000 (+0000) Subject: Some extra comments. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=794be8829d13bcb54402980a3e99773e176f566f;p=inkscape.git Some extra comments. --- diff --git a/src/display/nr-filter-displacement-map.cpp b/src/display/nr-filter-displacement-map.cpp index 29815abbb..321018fca 100644 --- a/src/display/nr-filter-displacement-map.cpp +++ b/src/display/nr-filter-displacement-map.cpp @@ -112,7 +112,7 @@ static void performDisplacement(NRPixBlock const* texture, NRPixBlock const* map int ymap = yout; pixel_t mapValue = pixelValue(map, xmap, ymap); - double xtex = xout + (Xneedsdemul ? + double xtex = xout + (Xneedsdemul ? // Although the value of the pixel corresponds to the MIDDLE of the pixel, no +0.5 is needed because we're interpolating pixels anyway (so to get the actual pixel locations 0.5 would have to be subtracted again). (mapValue[3]==0?0:(scalex * (mapValue[Xchannel] - mapValue[3]*0.5) / mapValue[3])) : (scalex * (mapValue[Xchannel] - 127.5))); double ytex = yout + (Yneedsdemul ? 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);