Commit b405534855170d670048928d59818e8c22f0375c
Get it working
Charles Lehner committed on 2/10/2015, 2:23:50 AMParent: 0b29f5c16c806103ae9326149404b382ab3b7cfd
Files changed
pngspark.c | changed |
pngspark.h | changed |
pngspark.c | ||
---|---|---|
@@ -7,11 +7,11 @@ | ||
7 | 7 … | |
8 | 8 … | |
9 | 9 … | static const size_t initial_size = 8; |
10 | 10 … | |
11 | -uint8_t parse_color(const char *color) | |
11 … | +uint32_t parse_color(const char *color) | |
12 | 12 … | { |
13 | - return !strcmp("black", color) ? 0x00 : 0x99; | |
13 … | + return !strcmp("black", color) ? 0xff000000 : 0xff999989; | |
14 | 14 … | } |
15 | 15 … | |
16 | 16 … | int pngspark_init(struct pngspark *ps, size_t height, const char *color) |
17 | 17 … | { |
@@ -37,26 +37,20 @@ | ||
37 | 37 … | ps->max_value = value; |
38 | 38 … | return 0; |
39 | 39 … | } |
40 | 40 … | |
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, | |
42 | 42 … | size_t height) |
43 | 43 … | { |
44 | 44 … | 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; | |
46 | 47 … | 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; | |
59 | 53 … | } |
60 | 54 … | return 0; |
61 | 55 … | } |
62 | 56 … | |
@@ -67,13 +61,14 @@ | ||
67 | 61 … | } |
68 | 62 … | |
69 | 63 … | int pngspark_write(struct pngspark *ps, FILE *file) |
70 | 64 … | { |
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); | |
72 | 66 … | if (!img) return 1; |
73 | 67 … | printf("size: %zu\n", img->dataSize); |
74 | 68 … | |
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); | |
76 | 71 … | if (!ret) |
77 | 72 … | ret = luPngWrite(write_fd, file, img); |
78 | 73 … | luImageRelease(img); |
79 | 74 … | return ret; |
Built with git-ssb-web