Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.9 KiB

  1. #define STB_HERRINGBONE_WANG_TILE_IMPLEMENTATION
  2. #include "stb_herringbone_wang_tile.h"
  3. #define STB_IMAGE_WRITE_IMPLEMENTATION
  4. #include "stb_image_write.h"
  5. // e 12 1 1 1 1 1 1 4 4
  6. int main(int argc, char **argv)
  7. {
  8. stbhw_config c = { 0 };
  9. int w,h, num_colors,i;
  10. unsigned char *data;
  11. if (argc == 1) goto usage;
  12. if (argc < 3) goto error;
  13. switch (argv[2][0]) {
  14. case 'c':
  15. if (argc < 8 || argc > 10)
  16. goto error;
  17. num_colors = 4;
  18. c.is_corner = 1;
  19. break;
  20. case 'e':
  21. if (argc < 10 || argc > 12)
  22. goto error;
  23. num_colors = 6;
  24. c.is_corner = 0;
  25. break;
  26. default:
  27. goto error;
  28. }
  29. c.short_side_len = atoi(argv[3]);
  30. for (i=0; i < num_colors; ++i)
  31. c.num_color[i] = atoi(argv[4+i]);
  32. c.num_vary_x = 1;
  33. c.num_vary_y = 1;
  34. if (argc > 4+i)
  35. c.num_vary_x = atoi(argv[4+i]);
  36. if (argc > 5+i)
  37. c.num_vary_y = atoi(argv[5+i]);
  38. stbhw_get_template_size(&c, &w, &h);
  39. data = (unsigned char *) malloc(w*h*3);
  40. if (stbhw_make_template(&c, data, w, h, w*3))
  41. stbi_write_png(argv[1], w, h, 3, data, w*3);
  42. else
  43. fprintf(stderr, "Error: %s\n", stbhw_get_last_error());
  44. return 0;
  45. error:
  46. fputs("Invalid command-line arguments\n\n", stderr);
  47. usage:
  48. fputs("Usage (see source for corner & edge type definitions):\n\n", stderr);
  49. fputs("herringbone_generator {outfile} c {sidelen} {c0} {c1} {c2} {c3} [{vx} {vy}]\n"
  50. " {outfile} -- filename that template will be written to as PNG\n"
  51. " {sidelen} -- length of short side of rectangle in pixels\n"
  52. " {c0} -- number of colors for corner type 0\n"
  53. " {c1} -- number of colors for corner type 1\n"
  54. " {c2} -- number of colors for corner type 2\n"
  55. " {c3} -- number of colors for corner type 3\n"
  56. " {vx} -- number of color-duplicating variations horizontally in template\n"
  57. " {vy} -- number of color-duplicating variations vertically in template\n"
  58. "\n"
  59. , stderr);
  60. fputs("herringbone_generator {outfile} e {sidelen} {e0} {e1} {e2} {e3} {e4} {e5} [{vx} {vy}]\n"
  61. " {outfile} -- filename that template will be written to as PNG\n"
  62. " {sidelen} -- length of short side of rectangle in pixels\n"
  63. " {e0} -- number of colors for edge type 0\n"
  64. " {e1} -- number of colors for edge type 1\n"
  65. " {e2} -- number of colors for edge type 2\n"
  66. " {e3} -- number of colors for edge type 3\n"
  67. " {e4} -- number of colors for edge type 4\n"
  68. " {e5} -- number of colors for edge type 5\n"
  69. " {vx} -- number of color-duplicating variations horizontally in template\n"
  70. " {vy} -- number of color-duplicating variations vertically in template\n"
  71. , stderr);
  72. return 1;
  73. }