1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include <stdint.h>
#include <stdio.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
int main(int argc, char **argv) {
int img_w, img_h, img_col_chans;
uint8_t *img_data;
if (argc != 3) {
fprintf(stderr, "usage: %s image.png name\n", argv[0]);
return 1;
}
img_data = stbi_load(argv[1], &img_w, &img_h, &img_col_chans, 0);
if (img_data == NULL) {
fputs("error: failed to load image\n", stderr);
return 1;
}
if (img_col_chans != 1) {
fputs("error: image isn't grayscale\n", stderr);
stbi_image_free(img_data);
return 1;
}
if (img_h * img_w == 0) {
fputs("error: image size is 0\n", stderr);
stbi_image_free(img_data);
return 1;
}
printf("#include \"px.h\"\nconst PxSpr %s={%d,%d,(uint8_t[]){",
argv[2], img_w, img_h);
for (int i = 0; i < img_w * img_h; i++)
printf("%#x,", (unsigned)img_data[i]);
printf("}};\n");
stbi_image_free(img_data);
return 0;
}
|