[ansi-print] Precision

This commit is contained in:
Behdad Esfahbod 2022-06-22 16:39:36 -06:00
parent c695a09154
commit 0d59d7952c
1 changed files with 3 additions and 3 deletions

View File

@ -196,11 +196,11 @@ struct biimage_t
color_t bgc = color_t::from_ansi (bg); color_t bgc = color_t::from_ansi (bg);
color_t fgc = color_t::from_ansi (fg); color_t fgc = color_t::from_ansi (fg);
color_diff_t diff = fgc.diff (bgc); color_diff_t diff = fgc.diff (bgc);
int dd = sqrt (diff.dot (diff)); double dd = sqrt (diff.dot (diff));
for (unsigned int y = 0; y < height; y++) for (unsigned int y = 0; y < height; y++)
for (unsigned int x = 0; x < width; x++) { for (unsigned int x = 0; x < width; x++) {
int d = sqrt (diff.dot (image (x, y).diff (bgc))); double d = sqrt (diff.dot (image (x, y).diff (bgc)));
(*this)(x, y) = d < 0 ? 0 : d > dd ? 255 : lround (d * 255. / dd); (*this)(x, y) = d <= 0 ? 0 : d >= dd ? 255 : lround (d / dd * 255.);
} }
} }