Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/memononen/nanosvg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikko Mononen <memononen@gmail.com>2022-04-08 00:57:43 +0300
committerGitHub <noreply@github.com>2022-04-08 00:57:43 +0300
commit214cf85efcdc67524335ad0e2a2d5982246b6a72 (patch)
treedf1b7ad89a22a044f0c3e3ba6ffebe99d1374916
parentccdb1995134d340a93fb20e3a3d323ccb3838dd0 (diff)
parenta5486fa30d4a6d1864c01838cd896d6da6fd0652 (diff)
Merge pull request #205 from AuthorityFX/master
Fixed rbg percentage parsing in nsvg__parseColorRGB
-rw-r--r--src/nanosvg.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/nanosvg.h b/src/nanosvg.h
index f5058b1..5077f27 100644
--- a/src/nanosvg.h
+++ b/src/nanosvg.h
@@ -1226,10 +1226,11 @@ static unsigned int nsvg__parseColorHex(const char* str)
static unsigned int nsvg__parseColorRGB(const char* str)
{
unsigned int r=0, g=0, b=0;
+ float rf=0, gf=0, bf=0;
if (sscanf(str, "rgb(%u, %u, %u)", &r, &g, &b) == 3) // decimal integers
return NSVG_RGB(r, g, b);
- if (sscanf(str, "rgb(%u%%, %u%%, %u%%)", &r, &g, &b) == 3) // decimal integer percentage
- return NSVG_RGB(r*255/100, g*255/100, b*255/100);
+ if (sscanf(str, "rgb(%f%%, %f%%, %f%%)", &rf, &gf, &bf) == 3) // decimal integer percentage
+ return NSVG_RGB(roundf(rf*2.55f), roundf(gf*2.55f), roundf(bf*2.55f)); // (255 / 100.0f)
return NSVG_RGB(128, 128, 128);
}