commit 625e510453e3d88f8bdd7a29d4cdceb4dadf973a
parent 727f26820edf6bcfd668fb5150e12c2223c3e0b7
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 24 Mar 2020 18:01:15 +0100
Print the color map in the terminal
Diffstat:
| M | src/htpp.c | | | 63 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- |
1 file changed, 56 insertions(+), 7 deletions(-)
diff --git a/src/htpp.c b/src/htpp.c
@@ -717,6 +717,31 @@ compute_XYZ_normalization_factor(const struct img* img)
return Ymax;
}
+static uint8_t
+rgb_to_c256(const uint8_t rgb[3])
+{
+ uint8_t c256 = 0;
+ ASSERT(rgb);
+
+ if(rgb[0] == rgb[1] && rgb[1] == rgb[2]) {
+ int c = rgb[0];
+ if(c < 4) {
+ c256 = 16; /* Grey 0 */
+ } else if(c >= 243) {
+ c256 = 231; /* Grey 100 */
+ } else {
+ c256 = (uint8_t)(232 + (c-8+5) / 10);
+ }
+ } else {
+ int r, g, b;
+ r = rgb[0] < 48 ? 0 : (rgb[0] < 95 ? 1 : 1 + (rgb[0] - 95 + 20) / 40);
+ g = rgb[1] < 48 ? 0 : (rgb[1] < 95 ? 1 : 1 + (rgb[1] - 95 + 20) / 40);
+ b = rgb[2] < 48 ? 0 : (rgb[2] < 95 ? 1 : 1 + (rgb[2] - 95 + 20) / 40);
+ c256 = (uint8_t)(36*r + 6*g + b + 16);
+ }
+ return c256;
+}
+
static res_T
pp_map(struct img* img, const struct args* args)
{
@@ -736,7 +761,6 @@ pp_map(struct img* img, const struct args* args)
range[0] = MMAX(img->ranges[args->map.pixcpnt][0], args->map.range[0]);
range[1] = MMIN(img->ranges[args->map.pixcpnt][1], args->map.range[1]);
ransz = range[1] - range[0];
- ASSERT(ransz > 0);
omp_set_num_threads(args->nthreads);
#pragma omp parallel for
@@ -745,13 +769,38 @@ pp_map(struct img* img, const struct args* args)
const size_t x = (size_t)i % img->width;
double* row = (double*)(img->pixels + img->pitch*y);
double* pixel = row + x*PIXCPNTS_COUNT__;
- const double val = CLAMP((pixel[args->map.pixcpnt] - range[0])/ransz, 0, 1);
- double color[3] = {0,0,0};
+ if(ransz == 0) {
+ pixel[PIXCPNT_R] = 0;
+ pixel[PIXCPNT_G] = 0;
+ pixel[PIXCPNT_B] = 0;
+ } else {
+ const double val = CLAMP((pixel[args->map.pixcpnt] - range[0])/ransz, 0, 1);
+ double color[3] = {0,0,0};
+
+ SCMAP(fetch_color(scmap, val, SCMAP_FILTER_LINEAR, color));
+ pixel[PIXCPNT_R] = color[0];
+ pixel[PIXCPNT_G] = color[1];
+ pixel[PIXCPNT_B] = color[2];
+ }
+ }
- SCMAP(fetch_color(scmap, val, SCMAP_FILTER_LINEAR, color));
- pixel[PIXCPNT_R] = color[0];
- pixel[PIXCPNT_G] = color[1];
- pixel[PIXCPNT_B] = color[2];
+ if(args->verbose) {
+ size_t nchars = 64;
+ fprintf(stderr, "%g [", range[0]);
+ FOR_EACH(i, 0, nchars) {
+ const double u = (double)i / (double)(nchars-1);
+ double color[3] = {0,0,0};
+ uint8_t rgb[3];
+ uint8_t c256;
+ SCMAP(fetch_color(scmap, u, SCMAP_FILTER_LINEAR, color));
+
+ rgb[0] = (uint8_t)(CLAMP(color[0], 0, 1) * 255. + 0.5/*round*/);
+ rgb[1] = (uint8_t)(CLAMP(color[1], 0, 1) * 255. + 0.5/*round*/);
+ rgb[2] = (uint8_t)(CLAMP(color[2], 0, 1) * 255. + 0.5/*round*/);
+ c256 = rgb_to_c256(rgb);
+ fprintf(stderr, "\x1b[48;5;%dm ", c256);
+ }
+ fprintf(stderr, "\x1b[0m] %g\n", range[1]);
}
exit: