Minor changes, unfinished palette selection

This commit is contained in:
Casey 2024-09-30 14:19:28 +03:00
parent a665f9498d
commit 33e3c1ad8c
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 21 additions and 12 deletions

View File

@ -202,8 +202,16 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}
// TODO: load palette
// TODO: load palette, maybe calculate it too? k-means?
const union color *palette = DEFAULT_PALETTE;
switch (args.palette_type) {
case PALETTE_DEFAULT: palette = DEFAULT_PALETTE; break;
case PALETTE_DEFAULT_GRAY: palette = DEFAULT_GRAY_PALETTE; break;
case PALETTE_AUTO: assert(0 && "Not implemented"); break;
case PALETTE_LIST: assert(0 && "Not implemented"); break;
case PALETTE_PATH: assert(0 && "Not implemented"); break;
default: assert(0 && "Unreachable");
}
// TODO: properly scale
struct image *scaled_image;
@ -226,8 +234,6 @@ int main(int argc, char **argv) {
// TODO: actually do stuff
const union color *palette = DEFAULT_PALETTE;
struct cc_char *characters = calloc(args.width * args.height, sizeof(struct cc_char));
struct image_pal *quantized_image = image_quantize(canvas, palette, 16);
@ -243,11 +249,14 @@ int main(int argc, char **argv) {
if (args.fast_mode) {
// use old 2x3
for (int y = 0; y < args.height; y++) {
for (int x = 0; x < args.width; x++) {
}
}
} else {
// use new 8x11 character matching
for (int y = 0; y < args.height; y++) {
for (int x = 0; x < args.width; x++) {
printf("DBG: %d:%d\n", x, y);
// Oh boy...
int min_diff = 0xffffff;
char closest_sym = 0x00, closest_color = 0xae;
@ -325,23 +334,23 @@ bool parse_cmdline(int argc, char **argv) {
if (c == '?') break;
switch (c) {
case 'h':
case 'h': // --help
show_help(argv[0], true, stdout);
exit(EXIT_SUCCESS);
break;
case 'f':
case 'f': // --fast
args.fast_mode = true;
if (args.cpi_version != CPI_VERSION_AUTO) {
fprintf(stderr, "Warning: text mode ignores version\n");
}
break;
case 'W':
case 'W': // --width
args.width = atoi(optarg);
break;
case 'H':
case 'H': // --height
args.height = atoi(optarg);
break;
case 'V':
case 'V': // --cpi_version
{
if (0 == strcmp(optarg, "auto") || 0 == strcmp(optarg, "-1")) {
args.cpi_version = CPI_VERSION_AUTO;
@ -356,7 +365,7 @@ bool parse_cmdline(int argc, char **argv) {
}
}
break;
case 'p':
case 'p': // --placement
if (0 == strcmp(optarg, "center")) {
args.placement = PLACEMENT_CENTER;
} else if (0 == strcmp(optarg, "cover")) {
@ -374,7 +383,7 @@ bool parse_cmdline(int argc, char **argv) {
return false;
}
break;
case 'P':
case 'P': // --palette
if (0 == strcmp(optarg, "default")) {
args.palette_type = PALETTE_DEFAULT;
} else if (0 == strcmp(optarg, "defaultgray")) {