From 3e99af61d0e64767adc1a23c0b69a0c421006144 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Mon, 29 Jan 2024 13:37:28 +0100 Subject: [PATCH] True color detection now done by libscterm Also, if not supported, libscterm will automatically gracefully degrade to the standard 216-color palette. --- src/pixels.cpp | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/pixels.cpp b/src/pixels.cpp index 0a78381..a7b20e4 100644 --- a/src/pixels.cpp +++ b/src/pixels.cpp @@ -1,16 +1,9 @@ #include -#include #include #include #include "pixels.hpp" -// truecolor to palette color (216-color) -static inline int t2p(int val) { - return round(5 * val / 255.0); -} - static void write(std::ostream& os, FILE* in) { - bool has_truecolor = sc::term::has_truecolor(); struct pam info; pnm_readpaminit(in, &info, PAM_STRUCT_SIZE(tuple_type)); std::unique_ptr row1 {pnm_allocpamrow(&info), pm_freerow}; @@ -29,16 +22,8 @@ static void write(std::ostream& os, FILE* in) { } for (int x = 0; x < info.width; ++x) { if (info.depth == 3) { // assume RGB, 1 byte per sample - if (has_truecolor) { - os << sc::io::truecolorb(t1[x][0], t1[x][1], t1[x][2]); - } else { - os << sc::io::rgbb(t2p(t1[x][0]), t2p(t1[x][1]), t2p(t1[x][2])); - } - if (has_truecolor) { - os << sc::io::truecolorf(t2[x][0], t2[x][1], t2[x][2]); - } else { - os << sc::io::rgbf(t2p(t2[x][0]), t2p(t2[x][1]), t2p(t2[x][2])); - } + os << sc::io::truecolorb(t1[x][0], t1[x][1], t1[x][2]); + os << sc::io::truecolorf(t2[x][0], t2[x][1], t2[x][2]); os << u8"\u2584"; // unicode lower half block } }