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.

82 lines
2.4 KiB

  1. #include <stdio.h>
  2. #define STB_HBWANG_MAX_X 500
  3. #define STB_HBWANG_MAX_Y 500
  4. #define STB_HERRINGBONE_WANG_TILE_IMPLEMENTATION
  5. #include "stb_herringbone_wang_tile.h"
  6. #define STB_IMAGE_IMPLEMENTATION
  7. #include "stb_image.h"
  8. #define STB_IMAGE_WRITE_IMPLEMENTATION
  9. #include "stb_image_write.h"
  10. int main(int argc, char **argv)
  11. {
  12. if (argc < 5) {
  13. fprintf(stderr, "Usage: herringbone_map {inputfile} {output-width} {output-height} {outputfile}\n");
  14. return 1;
  15. } else {
  16. char *filename = argv[1];
  17. int out_w = atoi(argv[2]);
  18. int out_h = atoi(argv[3]);
  19. char *outfile = argv[4];
  20. unsigned char *pixels, *out_pixels;
  21. stbhw_tileset ts;
  22. int w,h;
  23. pixels = stbi_load(filename, &w, &h, 0, 3);
  24. if (pixels == 0) {
  25. fprintf(stderr, "Couldn't open input file '%s'\n", filename);
  26. exit(1);
  27. }
  28. if (!stbhw_build_tileset_from_image(&ts, pixels, w*3, w, h)) {
  29. fprintf(stderr, "Error: %s\n", stbhw_get_last_error());
  30. return 1;
  31. }
  32. free(pixels);
  33. #ifdef DEBUG_OUTPUT
  34. {
  35. int i,j,k;
  36. // add blue borders to top-left edges of the tiles
  37. int hstride = (ts.short_side_len*2)*3;
  38. int vstride = (ts.short_side_len )*3;
  39. for (i=0; i < ts.num_h_tiles; ++i) {
  40. unsigned char *pix = ts.h_tiles[i]->pixels;
  41. for (j=0; j < ts.short_side_len*2; ++j)
  42. for (k=0; k < 3; ++k)
  43. pix[j*3+k] = (pix[j*3+k]*0.5+100+k*75)/1.5;
  44. for (j=1; j < ts.short_side_len; ++j)
  45. for (k=0; k < 3; ++k)
  46. pix[j*hstride+k] = (pix[j*hstride+k]*0.5+100+k*75)/1.5;
  47. }
  48. for (i=0; i < ts.num_v_tiles; ++i) {
  49. unsigned char *pix = ts.v_tiles[i]->pixels;
  50. for (j=0; j < ts.short_side_len; ++j)
  51. for (k=0; k < 3; ++k)
  52. pix[j*3+k] = (pix[j*3+k]*0.5+100+k*75)/1.5;
  53. for (j=1; j < ts.short_side_len*2; ++j)
  54. for (k=0; k < 3; ++k)
  55. pix[j*vstride+k] = (pix[j*vstride+k]*0.5+100+k*75)/1.5;
  56. }
  57. }
  58. #endif
  59. out_pixels = malloc(out_w * out_h * 3);
  60. if (!stbhw_generate_image(&ts, NULL, out_pixels, out_w*3, out_w, out_h)) {
  61. fprintf(stderr, "Error: %s\n", stbhw_get_last_error());
  62. return 1;
  63. }
  64. stbi_write_png(argv[4], out_w, out_h, 3, out_pixels, out_w*3);
  65. free(out_pixels);
  66. stbhw_free_tileset(&ts);
  67. return 0;
  68. }
  69. }