Skip to content

Commit

Permalink
Merge pull request #205 from AuthorityFX/master
Browse files Browse the repository at this point in the history
Fixed rbg percentage parsing in nsvg__parseColorRGB
  • Loading branch information
memononen authored Apr 7, 2022
2 parents ccdb199 + a5486fa commit 214cf85
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/nanosvg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 214cf85

Please # to comment.