Fix for "nsvg__scanlineSolid"

Updated fix for https://github.com/memononen/nanosvg/issues/37 (code now
using nsvg__div255).

Fix for "nsvg__scanlineSolid" #2

Updated fix for https://github.com/memononen/nanosvg/issues/37 (code now
using nsvg__div255).
This commit is contained in:
Christoph Neuhauser 2015-06-06 16:43:40 +02:00
parent 5966d6e77a
commit 8d51b88261

View File

@ -859,6 +859,11 @@ static unsigned int nsvg__applyOpacity(unsigned int c, float u)
return nsvg__RGBA(r,g,b,a); return nsvg__RGBA(r,g,b,a);
} }
inline int nsvg__div255(int x)
{
return ((x+1) * 257) >> 16;
}
static void nsvg__scanlineSolid(unsigned char* dst, int count, unsigned char* cover, int x, int y, static void nsvg__scanlineSolid(unsigned char* dst, int count, unsigned char* cover, int x, int y,
float tx, float ty, float scale, NSVGcachedPaint* cache) float tx, float ty, float scale, NSVGcachedPaint* cache)
{ {
@ -872,18 +877,18 @@ static void nsvg__scanlineSolid(unsigned char* dst, int count, unsigned char* co
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
int r,g,b; int r,g,b;
int a = ((int)cover[0] * ca) >> 8; int a = nsvg__div255((int)cover[0] * ca);
int ia = 255 - a; int ia = 255 - a;
// Premultiply // Premultiply
r = (cr * a) >> 8; r = nsvg__div255(cr * a);
g = (cg * a) >> 8; g = nsvg__div255(cg * a);
b = (cb * a) >> 8; b = nsvg__div255(cb * a);
// Blend over // Blend over
r += ((ia * (int)dst[0]) >> 8); r += nsvg__div255(ia * (int)dst[0]);
g += ((ia * (int)dst[1]) >> 8); g += nsvg__div255(ia * (int)dst[1]);
b += ((ia * (int)dst[2]) >> 8); b += nsvg__div255(ia * (int)dst[2]);
a += ((ia * (int)dst[3]) >> 8); a += nsvg__div255(ia * (int)dst[3]);
dst[0] = (unsigned char)r; dst[0] = (unsigned char)r;
dst[1] = (unsigned char)g; dst[1] = (unsigned char)g;
@ -914,19 +919,19 @@ static void nsvg__scanlineSolid(unsigned char* dst, int count, unsigned char* co
cb = (c >> 16) & 0xff; cb = (c >> 16) & 0xff;
ca = (c >> 24) & 0xff; ca = (c >> 24) & 0xff;
a = ((int)cover[0] * ca) >> 8; a = nsvg__div255((int)cover[0] * ca);
ia = 255 - a; ia = 255 - a;
// Premultiply // Premultiply
r = (cr * a) >> 8; r = nsvg__div255(cr * a);
g = (cg * a) >> 8; g = nsvg__div255(cg * a);
b = (cb * a) >> 8; b = nsvg__div255(cb * a);
// Blend over // Blend over
r += ((ia * (int)dst[0]) >> 8); r += nsvg__div255(ia * (int)dst[0]);
g += ((ia * (int)dst[1]) >> 8); g += nsvg__div255(ia * (int)dst[1]);
b += ((ia * (int)dst[2]) >> 8); b += nsvg__div255(ia * (int)dst[2]);
a += ((ia * (int)dst[3]) >> 8); a += nsvg__div255(ia * (int)dst[3]);
dst[0] = (unsigned char)r; dst[0] = (unsigned char)r;
dst[1] = (unsigned char)g; dst[1] = (unsigned char)g;
@ -961,19 +966,19 @@ static void nsvg__scanlineSolid(unsigned char* dst, int count, unsigned char* co
cb = (c >> 16) & 0xff; cb = (c >> 16) & 0xff;
ca = (c >> 24) & 0xff; ca = (c >> 24) & 0xff;
a = ((int)cover[0] * ca) >> 8; a = nsvg__div255((int)cover[0] * ca);
ia = 255 - a; ia = 255 - a;
// Premultiply // Premultiply
r = (cr * a) >> 8; r = nsvg__div255(cr * a);
g = (cg * a) >> 8; g = nsvg__div255(cg * a);
b = (cb * a) >> 8; b = nsvg__div255(cb * a);
// Blend over // Blend over
r += ((ia * (int)dst[0]) >> 8); r += nsvg__div255(ia * (int)dst[0]);
g += ((ia * (int)dst[1]) >> 8); g += nsvg__div255(ia * (int)dst[1]);
b += ((ia * (int)dst[2]) >> 8); b += nsvg__div255(ia * (int)dst[2]);
a += ((ia * (int)dst[3]) >> 8); a += nsvg__div255(ia * (int)dst[3]);
dst[0] = (unsigned char)r; dst[0] = (unsigned char)r;
dst[1] = (unsigned char)g; dst[1] = (unsigned char)g;