forked from hkc/cc-stuff
1
0
Fork 0

Add --mode argument

Deprecates --fast
This commit is contained in:
Vftdan 2024-10-03 22:01:34 +02:00
parent 135c3642b0
commit bedc6d9166
1 changed files with 31 additions and 7 deletions

View File

@ -36,8 +36,12 @@ const extern GlyphBitmap font_atlas[256];
const extern struct palette DEFAULT_PALETTE, DEFAULT_GRAY_PALETTE; const extern struct palette DEFAULT_PALETTE, DEFAULT_GRAY_PALETTE;
struct arguments { struct arguments {
bool fast_mode;
int width, height; int width, height;
enum character_mode {
CHARACTER_BLOCK,
CHARACTER_CHAR_PRECISE,
CHARACTER_CHAR_FAST,
} character_mode;
enum cpi_version { enum cpi_version {
CPI_VERSION_AUTO, CPI_VERSION_AUTO,
CPI_VERSION_RAW, CPI_VERSION_RAW,
@ -64,9 +68,9 @@ struct arguments {
char *input_path; char *input_path;
char *output_path; char *output_path;
} args = { } args = {
.fast_mode = false,
.width = 4 * 8 - 1, // 4x3 blocks screen .width = 4 * 8 - 1, // 4x3 blocks screen
.height = 3 * 6 - 2, .height = 3 * 6 - 2,
.character_mode = CHARACTER_CHAR_PRECISE,
.cpi_version = CPI_VERSION_AUTO, .cpi_version = CPI_VERSION_AUTO,
.placement = PLACEMENT_FULL, .placement = PLACEMENT_FULL,
.input_path = NULL, .input_path = NULL,
@ -140,7 +144,14 @@ static const struct optiondocs {
struct optiondocs_choice { char *value; char *doc; } *choices; struct optiondocs_choice { char *value; char *doc; } *choices;
} optiondocs[] = { } optiondocs[] = {
{ 'h', "help", 0, "Show help", 0 }, { '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 }, { 'W', "width", "width", "Width in characters", 0 },
{ 'h', "height", "height", "Height in characters", 0 }, { 'h', "height", "height", "Height in characters", 0 },
{ 'P', "palette", "palette", "Use specific palette.\n" { 'P', "palette", "palette", "Use specific palette.\n"
@ -184,7 +195,7 @@ int main(int argc, char **argv) {
} }
struct image *canvas; struct image *canvas;
if (args.fast_mode) { if (args.character_mode == CHARACTER_BLOCK) {
canvas = image_new(args.width * 2, args.height * 3); canvas = image_new(args.width * 2, args.height * 3);
} else { } else {
canvas = image_new(args.width * 8, args.height * 11); canvas = image_new(args.width * 8, args.height * 11);
@ -237,7 +248,7 @@ int main(int argc, char **argv) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (args.fast_mode) { if (args.character_mode == CHARACTER_BLOCK) {
convert_2x3(quantized_image, characters); convert_2x3(quantized_image, characters);
} else { } else {
convert_8x11(quantized_image, characters); convert_8x11(quantized_image, characters);
@ -269,6 +280,7 @@ bool parse_cmdline(int argc, char **argv) {
static struct option options[] = { static struct option options[] = {
{ "help", no_argument, 0, 'h' }, { "help", no_argument, 0, 'h' },
{ "fast", no_argument, 0, 'f' }, { "fast", no_argument, 0, 'f' },
{ "mode", required_argument, 0, 'm' },
{ "width", required_argument, 0, 'W' }, { "width", required_argument, 0, 'W' },
{ "height", required_argument, 0, 'H' }, { "height", required_argument, 0, 'H' },
{ "cpi_version", required_argument, 0, 'V' }, { "cpi_version", required_argument, 0, 'V' },
@ -279,7 +291,7 @@ bool parse_cmdline(int argc, char **argv) {
while (true) { while (true) {
int option_index = 0; 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 == -1) break;
if (c == 0) c = options[option_index].val; if (c == 0) c = options[option_index].val;
if (c == '?') break; if (c == '?') break;
@ -290,11 +302,23 @@ bool parse_cmdline(int argc, char **argv) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
case 'f': // --fast 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) { if (args.cpi_version != CPI_VERSION_AUTO) {
fprintf(stderr, "Warning: text mode ignores version\n"); fprintf(stderr, "Warning: text mode ignores version\n");
} }
break; 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 case 'W': // --width
args.width = atoi(optarg); args.width = atoi(optarg);
break; break;