Only calculate difference between each pixel × each palette entry once
This commit is contained in:
parent
1eb767d0d2
commit
d765e88679
19
img2cpi.c
19
img2cpi.c
|
@ -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;
|
int w = img->w / 8, h = img->h / 11;
|
||||||
for (int y = 0; y < h; y++) {
|
for (int y = 0; y < h; y++) {
|
||||||
for (int x = 0; x < w; x++) {
|
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;
|
float min_diff = 0xffffff;
|
||||||
char closest_sym = 0x00, closest_color = 0xae;
|
char closest_sym = 0x00, closest_color = 0xae;
|
||||||
for (int sym = 0x01; sym <= 0xFF; sym++) {
|
for (int sym = 0x01; sym <= 0xFF; sym++) {
|
||||||
|
@ -587,17 +599,12 @@ void convert_8x11(const struct image_pal *img, struct cc_char *characters) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int color = 0x00; color <= 0xff; color++) {
|
for (int color = 0x00; color <= 0xff; color++) {
|
||||||
union color cell_bg = img->palette[color & 0xF],
|
|
||||||
cell_fg = img->palette[color >> 4];
|
|
||||||
float difference = 0;
|
float difference = 0;
|
||||||
for (int oy = 0; oy < 11; oy++) {
|
for (int oy = 0; oy < 11; oy++) {
|
||||||
unsigned char sym_line = font_atlas[sym][oy];
|
unsigned char sym_line = font_atlas[sym][oy];
|
||||||
for (int ox = 0; ox < 8; ox++) {
|
for (int ox = 0; ox < 8; ox++) {
|
||||||
bool lit = sym_line & (0x80 >> ox);
|
bool lit = sym_line & (0x80 >> ox);
|
||||||
union color pixel = img->palette[img->pixels[
|
difference += chunk_palette_diffs[ox][oy][lit ? color >> 4 : color & 0xF];
|
||||||
ox + (x + (y * 11 + oy) * w) * 8
|
|
||||||
]];
|
|
||||||
difference += get_color_difference(pixel, lit ? cell_fg : cell_bg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (difference <= min_diff) {
|
if (difference <= min_diff) {
|
||||||
|
|
Loading…
Reference in New Issue