Skip to content

Commit

Permalink
Fixed rbg percentage parsing in nsvg__parseColorRGB
Browse files Browse the repository at this point in the history
  • Loading branch information
AuthorityFX committed Apr 7, 2022
1 parent ccdb199 commit c3ad36e
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 @@ -1228,8 +1228,9 @@ static unsigned int nsvg__parseColorRGB(const char* str)
unsigned int r=0, g=0, b=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);
float rf=0, gf=0, bf=0;
if (sscanf(str, "rgb(%f%%, %f%%, %f%%)", &rf, &gf, &bf) == 3) // decimal integer percentage
return NSVG_RGB(round(rf*2.55f), round(gf*2.55f), round(bf*2.55f)); // (255 / 100.0f)
return NSVG_RGB(128, 128, 128);
}

Expand Down

0 comments on commit c3ad36e

Please # to comment.