1
0
Fork 0

Only calculate difference between each pixel × each palette entry once

This commit is contained in:
Vftdan 2024-10-02 19:11:57 +02:00
parent 1eb767d0d2
commit d765e88679
1 changed files with 13 additions and 6 deletions

View File

@ -580,6 +580,18 @@ void convert_8x11(const struct image_pal *img, struct cc_char *characters) {
int w = img->w / 8, h = img->h / 11;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
float chunk_palette_diffs[8][11][0x10] = {{{(float) 0xffffff}}};
for (int ox = 0; ox < 8; ox++) {
for (int oy = 0; oy < 11; oy++) {
union color pixel = img->palette[img->pixels[
ox + (x + (y * 11 + oy) * w) * 8
]];
for (int color = 0x0; color < 0x10 && color < img->palette_size; color++) {
chunk_palette_diffs[ox][oy][color] = get_color_difference(pixel, img->palette[color]);
}
}
}
float min_diff = 0xffffff;
char closest_sym = 0x00, closest_color = 0xae;
for (int sym = 0x01; sym <= 0xFF; sym++) {
@ -587,17 +599,12 @@ void convert_8x11(const struct image_pal *img, struct cc_char *characters) {
continue;
}
for (int color = 0x00; color <= 0xff; color++) {
union color cell_bg = img->palette[color & 0xF],
cell_fg = img->palette[color >> 4];
float difference = 0;
for (int oy = 0; oy < 11; oy++) {
unsigned char sym_line = font_atlas[sym][oy];
for (int ox = 0; ox < 8; ox++) {
bool lit = sym_line & (0x80 >> ox);
union color pixel = img->palette[img->pixels[
ox + (x + (y * 11 + oy) * w) * 8
]];
difference += get_color_difference(pixel, lit ? cell_fg : cell_bg);
difference += chunk_palette_diffs[ox][oy][lit ? color >> 4 : color & 0xF];
}
}
if (difference <= min_diff) {