git ssb

1+

cel / pngspark



Commit 16f492a7668162cda0aa59a56f6efbe644b19295

Parse colors

Charles Lehner committed on 2/10/2015, 3:48:49 AM
Parent: b405534855170d670048928d59818e8c22f0375c

Files changed

pngspark.cchanged
pngspark.cView
@@ -7,11 +7,15 @@
77 #include "pngspark.h"
88
99 static const size_t initial_size = 8;
1010
11-uint32_t parse_color(const char *color)
11 +uint32_t parse_color(const char *color_str)
1212 {
13- return !strcmp("black", color) ? 0xff000000 : 0xff999989;
13 + if (!color_str) return 0;
14 + if (color_str[0] == '#') color_str++;
15 + uint32_t color = strtol(color_str, NULL, 16);
16 + return 0xff000000 |
17 + ((color >> 16) | (color & 0x00ff00) | (color & 0xff) << 16);
1418 }
1519
1620 int pngspark_init(struct pngspark *ps, size_t height, const char *color)
1721 {
@@ -63,9 +67,8 @@
6367 int pngspark_write(struct pngspark *ps, FILE *file)
6468 {
6569 LuImage *img = luImageCreate(ps->num_values, ps->max_value+1, 4, 8);
6670 if (!img) return 1;
67- printf("size: %zu\n", img->dataSize);
6871
6972 int ret = pngspark_draw(ps, (uint32_t *)img->data, ps->num_values,
7073 ps->max_value);
7174 if (!ret)

Built with git-ssb-web