3 #define STB_HBWANG_MAX_X 500
4 #define STB_HBWANG_MAX_Y 500
6 #define STB_HERRINGBONE_WANG_TILE_IMPLEMENTATION
7 #include "stb_herringbone_wang_tile.h"
9 #define STB_IMAGE_IMPLEMENTATION
10 #include "stb_image.h"
12 #define STB_IMAGE_WRITE_IMPLEMENTATION
13 #include "stb_image_write.h"
15 int main(int argc
, char **argv
)
18 fprintf(stderr
, "Usage: herringbone_map {inputfile} {output-width} {output-height} {outputfile}\n");
21 char *filename
= argv
[1];
22 int out_w
= atoi(argv
[2]);
23 int out_h
= atoi(argv
[3]);
24 char *outfile
= argv
[4];
26 unsigned char *pixels
, *out_pixels
;
30 pixels
= stbi_load(filename
, &w
, &h
, 0, 3);
32 fprintf(stderr
, "Couldn't open input file '%s'\n", filename
);
36 if (!stbhw_build_tileset_from_image(&ts
, pixels
, w
*3, w
, h
)) {
37 fprintf(stderr
, "Error: %s\n", stbhw_get_last_error());
46 // add blue borders to top-left edges of the tiles
47 int hstride
= (ts
.short_side_len
*2)*3;
48 int vstride
= (ts
.short_side_len
)*3;
49 for (i
=0; i
< ts
.num_h_tiles
; ++i
) {
50 unsigned char *pix
= ts
.h_tiles
[i
]->pixels
;
51 for (j
=0; j
< ts
.short_side_len
*2; ++j
)
53 pix
[j
*3+k
] = (pix
[j
*3+k
]*0.5+100+k
*75)/1.5;
54 for (j
=1; j
< ts
.short_side_len
; ++j
)
56 pix
[j
*hstride
+k
] = (pix
[j
*hstride
+k
]*0.5+100+k
*75)/1.5;
58 for (i
=0; i
< ts
.num_v_tiles
; ++i
) {
59 unsigned char *pix
= ts
.v_tiles
[i
]->pixels
;
60 for (j
=0; j
< ts
.short_side_len
; ++j
)
62 pix
[j
*3+k
] = (pix
[j
*3+k
]*0.5+100+k
*75)/1.5;
63 for (j
=1; j
< ts
.short_side_len
*2; ++j
)
65 pix
[j
*vstride
+k
] = (pix
[j
*vstride
+k
]*0.5+100+k
*75)/1.5;
70 out_pixels
= malloc(out_w
* out_h
* 3);
72 if (!stbhw_generate_image(&ts
, NULL
, out_pixels
, out_w
*3, out_w
, out_h
)) {
73 fprintf(stderr
, "Error: %s\n", stbhw_get_last_error());
77 stbi_write_png(argv
[4], out_w
, out_h
, 3, out_pixels
, out_w
*3);
80 stbhw_free_tileset(&ts
);