htpp

htrdr-image post-processing
git clone git://git.meso-star.fr/htpp.git
Log | Files | Refs | README | LICENSE

commit 0b034b2f05bb9cb25fbb717f4feb907c8544c0d0
parent 7691f195a7ff3404147593fd9e906c7fa6e76700
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 26 Mar 2020 17:39:01 +0100

Update the comportment of the range mapping option

Diffstat:
Mdoc/htpp.1.txt | 14++++++++------
Msrc/htpp.c | 107+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
2 files changed, 69 insertions(+), 52 deletions(-)

diff --git a/doc/htpp.1.txt b/doc/htpp.1.txt @@ -66,10 +66,10 @@ Finally, the resulting pixel components are clamped to [0, 1] and encoded on The mapping of a pixel component onto a color ramp is controlled by the *-m* option. The pixel component to post-process is defined by the _pixcpnt_ -mapping option. *htpp* first defines the range of the component onto the whole -image, eventually clamped to the _range_ mapping option. The component is then -normalized according to this range and then mapped to a built-in color ramp -whose name is defined by the _palette_ mapping option. +mapping option. *htpp* normalized this component according to its range onto +the whole image or with respect to the _range_ mapping option if it is +defined. The resuling value is then mapped to a built-in color ramp whose name +is defined by the _palette_ mapping option. OPTIONS ------- @@ -109,8 +109,10 @@ OPTIONS is the first one, i.e. *pixcpnt*=0. **range**=__min__,__max__;; - Range to clamp the values of the pixel component. By default the range is - infinite. + Range of the values to map. A degenerated range (i.e. __min__ >= __max__) + means that this range is automatically computed from the boundaries of the + selected pixel component over the whole image. By default the range is + degenerated. *-o* _output_:: File where the PPM image is written. If not defined, write _output_ to diff --git a/src/htpp.c b/src/htpp.c @@ -84,7 +84,7 @@ struct args { }, { \ &scmap_palette_inferno, /* Map palette */ \ 0, /* Map channel */ \ - {-DBL_MAX,DBL_MAX}, /* Range */ \ + {DBL_MAX,-DBL_MAX}, /* Range */ \ }, \ 0, /* Verbosity level */ \ 0, /* Force overwrite? */ \ @@ -118,18 +118,21 @@ print_help(const char* cmd) "image. If no image name is defined, read the image data from\n" "standard input\n", cmd); + printf("\n"); printf( " -f overwrite the OUTPUT file if it already exists.\n"); printf( " -h display this help and exit.\n"); printf( -" -i <image-option>[:<image-option> ... ]\n" -" handle the input as an image whose first, third,\n" -" and fifth pixel component store the pixel color in\n" -" the CIE 1931 XYZ color space\n"); +" -i <sub-option>[:<sub-option> ... ]\n" +" post process the colors of the submitted image. The\n" +" first, third, and fifth pixel component are assumed\n" +" to store a color encoded in the CIE 1931 XYZ color\n" +" space ('man htpp' for the list of sub-options).\n"); printf( -" -m <map-option>[:<map-option> ... ]\n" -" map a specific pixel component to a color.\n"); +" -m <sub-option>[:<sub-option> ... ]\n" +" map a specific pixel component to a color.\n" +" ('man htpp' for the list of sub-options).\n"); printf( " -o <output> write PPM image to <output>. If not defined, write\n" " results to standard output.\n"); @@ -302,11 +305,6 @@ parse_map_option(struct args* args, const char* str) size_t len; res = cstr_to_list_double(val, ',', args->map.range, &len, 2); if(res != RES_OK) goto error; - if(len != 2 || args->map.range[0] >= args->map.range[1]) { - fprintf(stderr, "Invalid map range `%s'.\n", val); - res = RES_BAD_ARG; - goto error; - } } else { fprintf(stderr, "Invalid map option `%s'.\n", key); res = RES_BAD_ARG; @@ -742,6 +740,46 @@ rgb_to_c256(const uint8_t rgb[3]) return c256; } +static void +print_color_map(const struct scmap* scmap, const double range[2]) +{ + const double ransz = range[1] - range[0]; + const int map_length = 65; + const int map_quarter = map_length / 4; + const int label_length = map_length / 4; + int i; + ASSERT(range && range[0] < range[1]); + + FOR_EACH(i, 0, map_length) { + const double u = (double)i / (double)(map_length-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); + if(i == 0 * map_quarter + || i == 1 * map_quarter + || i == 2 * map_quarter + || i == 3 * map_quarter + || i == 4 * map_quarter) { + fprintf(stderr, "\x1b[0m|"); + } else { + fprintf(stderr, "\x1b[48;5;%dm ", c256); + } + } + fprintf(stderr, "\n"); + fprintf(stderr, "%-*.5g", label_length, range[0]); + fprintf(stderr, "%-*.5g", label_length, 0.25 * ransz + range[0]); + fprintf(stderr, "%-*.5g", label_length, 0.50 * ransz + range[0]); + fprintf(stderr, "%-*.5g", label_length, 0.75 * ransz + range[0]); + fprintf(stderr, "%-*.5g", label_length, range[1]); + fprintf(stderr, "\n"); +} + static res_T pp_map(struct img* img, const struct args* args) { @@ -758,8 +796,16 @@ pp_map(struct img* img, const struct args* args) res_to_cstr(res)); goto error; } - 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]); + + if(args->map.range[0] < args->map.range[1]) { + /* The range is fixed */ + range[0] = args->map.range[0]; + range[1] = args->map.range[1]; + } else { + /* The range is defined from the loaded data */ + range[0] = img->ranges[args->map.pixcpnt][0]; + range[1] = img->ranges[args->map.pixcpnt][1]; + } ransz = range[1] - range[0]; omp_set_num_threads(args->nthreads); @@ -785,38 +831,7 @@ pp_map(struct img* img, const struct args* args) } if(args->verbose) { - const int map_length = 65; - const int map_quarter = map_length / 4; - const int label_length = map_length / 4; - FOR_EACH(i, 0, map_length) { - const double u = (double)i / (double)(map_length-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); - if(i == 0 * map_quarter - || i == 1 * map_quarter - || i == 2 * map_quarter - || i == 3 * map_quarter - || i == 4 * map_quarter) { - fprintf(stderr, "\x1b[0m|"); - } else { - fprintf(stderr, "\x1b[48;5;%dm ", c256); - } - - } - fprintf(stderr, "\n"); - fprintf(stderr, "%-*.5g", label_length, range[0]); - fprintf(stderr, "%-*.5g", label_length, 0.25 * ransz + range[0]); - fprintf(stderr, "%-*.5g", label_length, 0.50 * ransz + range[0]); - fprintf(stderr, "%-*.5g", label_length, 0.75 * ransz + range[0]); - fprintf(stderr, "%-*.5g", label_length, range[1]); - fprintf(stderr, "\n"); + print_color_map(scmap, range); } exit: