2021-09-02 00:21:10 -04:00
|
|
|
#include "common.h"
|
2016-08-24 21:56:07 -04:00
|
|
|
|
2021-09-02 00:21:10 -04:00
|
|
|
void usage() {
|
2021-09-02 18:37:36 -04:00
|
|
|
fputs("Usage: png_dimensions front.png front.dimensions\n", stderr);
|
2016-08-24 21:56:07 -04:00
|
|
|
}
|
|
|
|
|
2021-09-02 18:37:36 -04:00
|
|
|
uint8_t read_png_dimensions(const char *filename) {
|
2021-09-02 00:21:10 -04:00
|
|
|
uint32_t width_px = read_png_width_verbose(filename);
|
|
|
|
if (width_px != 40 && width_px != 48 && width_px != 56) {
|
2021-09-02 03:04:40 -04:00
|
|
|
error_exit("Not a valid width for \"%s\": %" PRIu32 " px\n", filename, width_px);
|
2017-12-28 01:25:25 -05:00
|
|
|
}
|
2021-09-02 00:21:10 -04:00
|
|
|
uint8_t width_tiles = (uint8_t)(width_px / 8);
|
|
|
|
return (width_tiles << 4) | width_tiles;
|
2016-08-24 21:56:07 -04:00
|
|
|
}
|
|
|
|
|
2021-09-02 00:21:10 -04:00
|
|
|
int main(int argc, char *argv[]) {
|
2016-08-24 21:56:07 -04:00
|
|
|
if (argc < 3) {
|
|
|
|
usage();
|
2021-09-02 00:21:10 -04:00
|
|
|
exit(1);
|
2016-08-24 21:56:07 -04:00
|
|
|
}
|
2021-09-02 01:21:15 -04:00
|
|
|
|
2021-09-02 18:37:36 -04:00
|
|
|
uint8_t output_byte = read_png_dimensions(argv[1]);
|
2021-09-02 00:21:10 -04:00
|
|
|
write_u8(argv[2], &output_byte, 1);
|
2016-08-24 21:56:07 -04:00
|
|
|
return 0;
|
|
|
|
}
|