diff --git a/img2cpi.c b/img2cpi.c index c50c23b..4b0623a 100644 --- a/img2cpi.c +++ b/img2cpi.c @@ -36,8 +36,12 @@ const extern GlyphBitmap font_atlas[256]; const extern struct palette DEFAULT_PALETTE, DEFAULT_GRAY_PALETTE; struct arguments { - bool fast_mode; int width, height; + enum character_mode { + CHARACTER_BLOCK, + CHARACTER_CHAR_PRECISE, + CHARACTER_CHAR_FAST, + } character_mode; enum cpi_version { CPI_VERSION_AUTO, CPI_VERSION_RAW, @@ -64,9 +68,9 @@ struct arguments { char *input_path; char *output_path; } args = { - .fast_mode = false, .width = 4 * 8 - 1, // 4x3 blocks screen .height = 3 * 6 - 2, + .character_mode = CHARACTER_CHAR_PRECISE, .cpi_version = CPI_VERSION_AUTO, .placement = PLACEMENT_FULL, .input_path = NULL, @@ -140,7 +144,14 @@ static const struct optiondocs { struct optiondocs_choice { char *value; char *doc; } *choices; } optiondocs[] = { { 'h', "help", 0, "Show help", 0 }, - { 'f', "fast", 0, "Use fast (old) method for picking characters and colors", 0 }, + { 'f', "fast", 0, "Use fast (old) method for picking characters and colors\n" + " DEPRECATED: use `--mode block` instead\n", 0 }, + { 'm', "mode", "mode", "Set conversion mode", + (struct optiondocs_choice[]) { + { "block", "Use fast (old) method for picking characters and colors" }, + { "char-precise", "Select among all characters with maximum precision" }, + { "char-fast", "Select among all characters with reduced precision" }, + { 0, 0 } } }, { 'W', "width", "width", "Width in characters", 0 }, { 'h', "height", "height", "Height in characters", 0 }, { 'P', "palette", "palette", "Use specific palette.\n" @@ -184,7 +195,7 @@ int main(int argc, char **argv) { } struct image *canvas; - if (args.fast_mode) { + if (args.character_mode == CHARACTER_BLOCK) { canvas = image_new(args.width * 2, args.height * 3); } else { canvas = image_new(args.width * 8, args.height * 11); @@ -237,7 +248,7 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } - if (args.fast_mode) { + if (args.character_mode == CHARACTER_BLOCK) { convert_2x3(quantized_image, characters); } else { convert_8x11(quantized_image, characters); @@ -269,6 +280,7 @@ bool parse_cmdline(int argc, char **argv) { static struct option options[] = { { "help", no_argument, 0, 'h' }, { "fast", no_argument, 0, 'f' }, + { "mode", required_argument, 0, 'm' }, { "width", required_argument, 0, 'W' }, { "height", required_argument, 0, 'H' }, { "cpi_version", required_argument, 0, 'V' }, @@ -279,7 +291,7 @@ bool parse_cmdline(int argc, char **argv) { while (true) { int option_index = 0; - int c = getopt_long(argc, argv, "hfW:H:V:p:P:", options, &option_index); + int c = getopt_long(argc, argv, "hfm:W:H:V:p:P:", options, &option_index); if (c == -1) break; if (c == 0) c = options[option_index].val; if (c == '?') break; @@ -290,11 +302,23 @@ bool parse_cmdline(int argc, char **argv) { exit(EXIT_SUCCESS); break; case 'f': // --fast - args.fast_mode = true; + args.character_mode = CHARACTER_BLOCK; + fprintf(stderr, "Warning: `--fast` is deprecated, use `--mode block` instead\n"); if (args.cpi_version != CPI_VERSION_AUTO) { fprintf(stderr, "Warning: text mode ignores version\n"); } break; + case 'm': // --mode + { + if (0 == strcmp(optarg, "block") || 0 == strcmp(optarg, "fast") || 0 == strcmp(optarg, "2x3")) { + args.character_mode = CHARACTER_BLOCK; + } else if (0 == strcmp(optarg, "char") || 0 == strcmp(optarg, "char-precise") || 0 == strcmp(optarg, "8x11") || 0 == strcmp(optarg, "6x9")) { + args.character_mode = CHARACTER_CHAR_PRECISE; + } else if (0 == strcmp(optarg, "char-fast") || 0 == strcmp(optarg, "8x11-fast") || 0 == strcmp(optarg, "6x9-fast")) { + args.character_mode = CHARACTER_CHAR_FAST; + } + } + break; case 'W': // --width args.width = atoi(optarg); break;