git ssb

1+

cel / pngspark



Commit b405534855170d670048928d59818e8c22f0375c

Get it working

Charles Lehner committed on 2/10/2015, 2:23:50 AM
Parent: 0b29f5c16c806103ae9326149404b382ab3b7cfd

Files changed

pngspark.cchanged
pngspark.hchanged
pngspark.cView
@@ -7,11 +7,11 @@
77 #include "pngspark.h"
88
99 static const size_t initial_size = 8;
1010
11-uint8_t parse_color(const char *color)
11 +uint32_t parse_color(const char *color)
1212 {
13- return !strcmp("black", color) ? 0x00 : 0x99;
13 + return !strcmp("black", color) ? 0xff000000 : 0xff999989;
1414 }
1515
1616 int pngspark_init(struct pngspark *ps, size_t height, const char *color)
1717 {
@@ -37,26 +37,20 @@
3737 ps->max_value = value;
3838 return 0;
3939 }
4040
41-int pngspark_draw(struct pngspark *ps, uint8_t *data, size_t width,
41 +int pngspark_draw(struct pngspark *ps, uint32_t *data, size_t width,
4242 size_t height)
4343 {
4444 double *values = ps->values;
45- uint8_t color = ps->color;
45 + uint32_t color = ps->color;
46 + double height_scale = (double)height / (double)ps->max_value;
4647 for (size_t x = 0; x < width; x++) {
47- size_t value = values[x] * height;
48- data[x] = value;
49- for (size_t y = 0; y < height; y++)
50- data[x * width + y] = 0x9f;
51- /*
52- printf("write value: %zu, i: %zu\n", value, 1 * width + x);
53- for (size_t y = value+1; y < height; y++)
54- data[y * width + x] = color;
55- */
56- (void)value;
57- (void)color;
58- (void)data;
48 + size_t value = values[x] * height_scale;
49 + for (size_t y = 0; y < value; y++)
50 + data[x + width * y] = 0;
51 + for (size_t y = value; y <= height; y++)
52 + data[x + width * y] = color;
5953 }
6054 return 0;
6155 }
6256
@@ -67,13 +61,14 @@
6761 }
6862
6963 int pngspark_write(struct pngspark *ps, FILE *file)
7064 {
71- LuImage *img = luImageCreate(ps->num_values, ps->max_value+1, 1, 8);
65 + LuImage *img = luImageCreate(ps->num_values, ps->max_value+1, 4, 8);
7266 if (!img) return 1;
7367 printf("size: %zu\n", img->dataSize);
7468
75- int ret = pngspark_draw(ps, img->data, ps->num_values, ps->max_value);
69 + int ret = pngspark_draw(ps, (uint32_t *)img->data, ps->num_values,
70 + ps->max_value);
7671 if (!ret)
7772 ret = luPngWrite(write_fd, file, img);
7873 luImageRelease(img);
7974 return ret;
pngspark.hView
@@ -7,9 +7,9 @@
77 size_t num_values;
88 size_t size;
99 size_t max_value;
1010 size_t height;
11- uint8_t color;
11 + uint32_t color;
1212 double *values;
1313 };
1414
1515 int pngspark_init(struct pngspark *, size_t, const char *);

Built with git-ssb-web