[util] Minor
This commit is contained in:
parent
fbecde3d5c
commit
ff0f210519
|
@ -222,11 +222,12 @@ struct biimage_t
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
block_best (const biimage_t &bi, unsigned int *score, bool *inverse)
|
block_best (const biimage_t &bi, bool *inverse)
|
||||||
{
|
{
|
||||||
assert (bi.width <= CELL_W);
|
assert (bi.width <= CELL_W);
|
||||||
assert (bi.height <= CELL_H);
|
assert (bi.height <= CELL_H);
|
||||||
|
|
||||||
|
unsigned int score = (unsigned int) -1;
|
||||||
unsigned int row_sum[CELL_H] = {0};
|
unsigned int row_sum[CELL_H] = {0};
|
||||||
unsigned int col_sum[CELL_W] = {0};
|
unsigned int col_sum[CELL_W] = {0};
|
||||||
unsigned int row_sum_i[CELL_H] = {0};
|
unsigned int row_sum_i[CELL_H] = {0};
|
||||||
|
@ -262,14 +263,14 @@ block_best (const biimage_t &bi, unsigned int *score, bool *inverse)
|
||||||
const char *best_c = " ";
|
const char *best_c = " ";
|
||||||
|
|
||||||
/* Maybe empty is better! */
|
/* Maybe empty is better! */
|
||||||
if (total < *score) {
|
if (total < score) {
|
||||||
*score = total;
|
score = total;
|
||||||
*inverse = false;
|
*inverse = false;
|
||||||
best_c = " ";
|
best_c = " ";
|
||||||
}
|
}
|
||||||
/* Maybe full is better! */
|
/* Maybe full is better! */
|
||||||
if (total_i < *score) {
|
if (total_i < score) {
|
||||||
*score = total_i;
|
score = total_i;
|
||||||
*inverse = true;
|
*inverse = true;
|
||||||
best_c = " ";
|
best_c = " ";
|
||||||
}
|
}
|
||||||
|
@ -295,11 +296,11 @@ block_best (const biimage_t &bi, unsigned int *score, bool *inverse)
|
||||||
best_inv = true;
|
best_inv = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (best_s < *score) {
|
if (best_s < score) {
|
||||||
static const char *lower[7] = {"▁", "▂", "▃", "▄", "▅", "▆", "▇"};
|
static const char *lower[7] = {"▁", "▂", "▃", "▄", "▅", "▆", "▇"};
|
||||||
unsigned int which = lround (((best_i + 1) * 8) / bi.height);
|
unsigned int which = lround (((best_i + 1) * 8) / bi.height);
|
||||||
if (1 <= which && which <= 7) {
|
if (1 <= which && which <= 7) {
|
||||||
*score = best_s;
|
score = best_s;
|
||||||
*inverse = best_inv;
|
*inverse = best_inv;
|
||||||
best_c = lower[7 - which];
|
best_c = lower[7 - which];
|
||||||
}
|
}
|
||||||
|
@ -327,11 +328,11 @@ block_best (const biimage_t &bi, unsigned int *score, bool *inverse)
|
||||||
best_inv = false;
|
best_inv = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (best_s < *score) {
|
if (best_s < score) {
|
||||||
static const char *left [7] = {"▏", "▎", "▍", "▌", "▋", "▊", "▉"};
|
static const char *left [7] = {"▏", "▎", "▍", "▌", "▋", "▊", "▉"};
|
||||||
unsigned int which = lround (((best_i + 1) * 8) / bi.width);
|
unsigned int which = lround (((best_i + 1) * 8) / bi.width);
|
||||||
if (1 <= which && which <= 7) {
|
if (1 <= which && which <= 7) {
|
||||||
*score = best_s;
|
score = best_s;
|
||||||
*inverse = best_inv;
|
*inverse = best_inv;
|
||||||
best_c = left[which - 1];
|
best_c = left[which - 1];
|
||||||
}
|
}
|
||||||
|
@ -349,7 +350,7 @@ block_best (const biimage_t &bi, unsigned int *score, bool *inverse)
|
||||||
qs += quad_i[i][j];
|
qs += quad_i[i][j];
|
||||||
} else
|
} else
|
||||||
qs += quad[i][j];
|
qs += quad[i][j];
|
||||||
if (qs < *score) {
|
if (qs < score) {
|
||||||
const char *c = NULL;
|
const char *c = NULL;
|
||||||
bool inv = false;
|
bool inv = false;
|
||||||
switch (q) {
|
switch (q) {
|
||||||
|
@ -365,7 +366,7 @@ block_best (const biimage_t &bi, unsigned int *score, bool *inverse)
|
||||||
case 14: c = "▟"; inv = true; break;
|
case 14: c = "▟"; inv = true; break;
|
||||||
}
|
}
|
||||||
if (c) {
|
if (c) {
|
||||||
*score = qs;
|
score = qs;
|
||||||
*inverse = inv;
|
*inverse = inv;
|
||||||
best_c = c;
|
best_c = c;
|
||||||
}
|
}
|
||||||
|
@ -400,9 +401,8 @@ ansi_print_image_rgb24 (const uint32_t *data,
|
||||||
printf (" ");
|
printf (" ");
|
||||||
} else {
|
} else {
|
||||||
/* Figure out the closest character to the biimage */
|
/* Figure out the closest character to the biimage */
|
||||||
unsigned int score = (unsigned int) -1;
|
|
||||||
bool inverse = false;
|
bool inverse = false;
|
||||||
const char *c = block_best (bi, &score, &inverse);
|
const char *c = block_best (bi, &inverse);
|
||||||
if (inverse) {
|
if (inverse) {
|
||||||
if (last_bg != bi.fg || last_fg != bi.bg) {
|
if (last_bg != bi.fg || last_fg != bi.bg) {
|
||||||
printf ("\e[%d;%dm", 30 + bi.bg, 40 + bi.fg);
|
printf ("\e[%d;%dm", 30 + bi.bg, 40 + bi.fg);
|
||||||
|
|
Loading…
Reference in New Issue