herringbone_generator.c
This file
Path
tests/herringbone_generator.c
87 lines · 2.9 KiB · C
Last changed by
Not known.
History of this fileTake it
1#define STB_HERRINGBONE_WANG_TILE_IMPLEMENTATION2#include "stb_herringbone_wang_tile.h"34#define STB_IMAGE_WRITE_IMPLEMENTATION5#include "stb_image_write.h"67// e 12 1 1 1 1 1 1 4 489int main(int argc, char **argv)10{11 stbhw_config c = { 0 };12 int w,h, num_colors,i;13 unsigned char *data;1415 if (argc == 1) goto usage;16 if (argc < 3) goto error;1718 switch (argv[2][0]) {19 case 'c':20 if (argc < 8 || argc > 10)21 goto error;22 num_colors = 4;23 c.is_corner = 1;24 break;2526 case 'e':27 if (argc < 10 || argc > 12)28 goto error;29 num_colors = 6;30 c.is_corner = 0;31 break;3233 default:34 goto error;35 }3637 c.short_side_len = atoi(argv[3]);38 for (i=0; i < num_colors; ++i)39 c.num_color[i] = atoi(argv[4+i]);4041 c.num_vary_x = 1;42 c.num_vary_y = 1;4344 if (argc > 4+i)45 c.num_vary_x = atoi(argv[4+i]);46 if (argc > 5+i)47 c.num_vary_y = atoi(argv[5+i]);4849 stbhw_get_template_size(&c, &w, &h);5051 data = (unsigned char *) malloc(w*h*3);5253 if (stbhw_make_template(&c, data, w, h, w*3))54 stbi_write_png(argv[1], w, h, 3, data, w*3);55 else56 fprintf(stderr, "Error: %s\n", stbhw_get_last_error());57 return 0;5859 error:60 fputs("Invalid command-line arguments\n\n", stderr);61 usage:62 fputs("Usage (see source for corner & edge type definitions):\n\n", stderr);63 fputs("herringbone_generator {outfile} c {sidelen} {c0} {c1} {c2} {c3} [{vx} {vy}]\n"64 " {outfile} -- filename that template will be written to as PNG\n"65 " {sidelen} -- length of short side of rectangle in pixels\n"66 " {c0} -- number of colors for corner type 0\n"67 " {c1} -- number of colors for corner type 1\n"68 " {c2} -- number of colors for corner type 2\n"69 " {c3} -- number of colors for corner type 3\n"70 " {vx} -- number of color-duplicating variations horizontally in template\n"71 " {vy} -- number of color-duplicating variations vertically in template\n"72 "\n"73 , stderr);74 fputs("herringbone_generator {outfile} e {sidelen} {e0} {e1} {e2} {e3} {e4} {e5} [{vx} {vy}]\n"75 " {outfile} -- filename that template will be written to as PNG\n"76 " {sidelen} -- length of short side of rectangle in pixels\n"77 " {e0} -- number of colors for edge type 0\n"78 " {e1} -- number of colors for edge type 1\n"79 " {e2} -- number of colors for edge type 2\n"80 " {e3} -- number of colors for edge type 3\n"81 " {e4} -- number of colors for edge type 4\n"82 " {e5} -- number of colors for edge type 5\n"83 " {vx} -- number of color-duplicating variations horizontally in template\n"84 " {vy} -- number of color-duplicating variations vertically in template\n"85 , stderr);86 return 1;87}