back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/image_converter/converter.c
diff options
context:
space:
mode:
authorscratko <m@scratko.xyz>2024-11-21 23:01:56 +0300
committerscratko <m@scratko.xyz>2024-11-21 23:01:56 +0300
commite9078b6980eaf22c1f6352930bd36d4a9e85a4b0 (patch)
treedea9e3659bd18dbd52dc3eedb55ac6acfcc14370 /image_converter/converter.c
parentca449b813cef6c8f7348ff51302f125587a90a53 (diff)
downloadpicture-puzzle-e9078b6980eaf22c1f6352930bd36d4a9e85a4b0.tar.gz
picture-puzzle-e9078b6980eaf22c1f6352930bd36d4a9e85a4b0.tar.bz2
picture-puzzle-e9078b6980eaf22c1f6352930bd36d4a9e85a4b0.zip
Including resources in the object file
Convert pictures to array data (image_converter/converter.c) Resources are located in image_converter/resources.o
Diffstat (limited to 'image_converter/converter.c')
-rw-r--r--image_converter/converter.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/image_converter/converter.c b/image_converter/converter.c
new file mode 100644
index 0000000..8db1bff
--- /dev/null
+++ b/image_converter/converter.c
@@ -0,0 +1,52 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+enum {
+ length = 9
+};
+
+static const char *parts[] = {
+ "00.png", "01.png", "02.png",
+ "10.png", "11.png", "12.png",
+ "20.png", "21.png", "22.png"
+};
+
+int main()
+{
+ int part_sizes[length];
+ int i, j, c;
+ char res_dir[] = "../resources/tucan/";
+ FILE * out = fopen("resources.cpp","wt");
+ if (out == NULL) {
+ printf("Can not open output\n");
+ return 1;
+ }
+ fprintf(out,"const unsigned char image_data[] = {\n");
+ for(i = 0; i < length; ++i) {
+ char *str_copy = (char*)malloc(sizeof(res_dir) + strlen("00.png"));
+ strcpy(str_copy, res_dir);
+ FILE * in = fopen(strcat(str_copy, parts[i]), "rb");
+ if (in == NULL) {
+ printf("Can not open input file\n");
+ return 1;
+ }
+ for(j = 0, c = fgetc(in); c != EOF; c = fgetc(in), ++j) {
+ if (j%16 == 0) fprintf(out," ");
+ fprintf(out,"0x%02X, ", c);
+ if (j%16 == 15) fputs("\n", out);
+ }
+ part_sizes[i] = j;
+ fclose(in);
+ free(str_copy);
+ }
+ fprintf(out,"0xFF };\n\n");
+ fprintf(out, "const int image_sizes[] = {\n");
+ for(int i = 0; i < length; ++i) {
+ if (i%16 == 0) fprintf(out," ");
+ fprintf(out,"%d, ", part_sizes[i]);
+ if (i%16 == 15) fputs("\n", out);
+ }
+ fprintf(out,"0xFF };\n\n");
+ fclose(out);
+}