htpp

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

commit e5d3a827b1722505a8b10326c1326b16810e17fa
parent 9598e4996c7e340261b94ae82b52d85d54023a3a
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 30 Oct 2023 16:37:01 +0100

Merge branch 'release_0.5'

Diffstat:
M.gitignore | 12+++++-------
AMakefile | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MREADME.md | 113++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Dcmake/CMakeLists.txt | 105-------------------------------------------------------------------------------
Aconfig.mk | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ddoc/htpp.1.scd | 257-------------------------------------------------------------------------------
Ahtpp.1 | 299+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amake.sh | 41+++++++++++++++++++++++++++++++++++++++++
Msrc/htpp.c | 71++++++++++++++++-------------------------------------------------------
9 files changed, 584 insertions(+), 477 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,11 +1,9 @@ .gitignore -CMakeCache.txt -CMakeFiles -Makefile -tmp -[Bb]uild* +[Bb]uild *.sw[po] -*.[ao] +*.[od] *~ +.config tags - +src/htpp_version.h +htpp diff --git a/Makefile b/Makefile @@ -0,0 +1,87 @@ +# Copyright (C) 2018-2020, 2023 |Méso|Star> (contact@meso-star.com) +# Copyright (C) 2018, 2019 Centre National de la Recherche Scientifique +# Copyright (C) 2018, 2019 Université Paul Sabatier +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +.POSIX: +.SUFFIXES: # Clean up default inference rules + +include config.mk + +################################################################################ +# Library building +################################################################################ +SRC = src/htpp.c +OBJ = $(SRC:.c=.o) +DEP = $(SRC:.c=.d) + +build_library: .config $(DEP) + @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) htpp + +$(DEP) $(OBJ): config.mk + +htpp: $(OBJ) + $(CC) $(CFLAGS) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(DPDC_LIBS) + +.config: config.mk + @if ! $(PKG_CONFIG) --atleast-version $(SCMAP_VERSION) scmap; then \ + echo "scmap $(SCMAP_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \ + echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi + @echo "config done" > $@ + +src/htpp.d: src/htpp_version.h + +src/htpp_version.h: src/htpp_version.h.in config.mk + sed -e 's#@VERSION_MAJOR@#$(VERSION_MAJOR)#g' \ + -e 's#@VERSION_MINOR@#$(VERSION_MINOR)#g' \ + -e 's#@VERSION_PATCH@#$(VERSION_PATCH)#g' \ + src/htpp_version.h.in > $@ + +.SUFFIXES: .c .d .o +.c.d: + @$(CC) $(CFLAGS) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + +.c.o: + $(CC) $(CFLAGS) $(DPDC_CFLAGS) -c $< -o $@ + +################################################################################ +# Installation +################################################################################ +install: build_library + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/bin" htpp + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/htpp" COPYING README.md + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/man/man1" htpp.1 + +uninstall: + rm -f "$(DESTDIR)$(PREFIX)/bin/htpp" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/htpp/COPYING" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/htpp/README.md" + rm -f "$(DESTDIR)$(PREFIX)/share/man/man1/htpp.1" + +################################################################################ +# Miscellaneous targets +################################################################################ +all: build_library + +clean: + rm -f $(OBJ) htpp .config + +distclean: clean + rm -f $(DEP) src/htpp_version.h + +lint: + shellcheck -o all make.sh + mandoc -Tlint -Wall htpp.1 || [ $$? -le 1 ] diff --git a/README.md b/README.md @@ -1,29 +1,34 @@ # htpp -This program is used to post process images saved in the -[htrdr-image](https://gitlab.com/meso-star/htrdr/-/blob/master/doc/htrdr-image.5.scd) -file format. - -## How to build - -This program is compatible GNU/Linux 64-bits. It relies on the -[CMake](http://www.cmake.org) and the -[RCMake](https://gitlab.com/vaplv/rcmake/) packages to build. It also depends -on the [RSys](https://gitlab.com/vaplv/rsys/) library and on the -[OpenMP](http://www.openmp.org) 1.2 specification to parallelize its -computations. It optionally depends on [scdoc](https://sr.ht/~sircmpwn/scdoc/) -which, if available, is used to generate the htpp man page. - -First ensure that CMake is installed on your system. Then install the RCMake -package as well as the aforementioned prerequisites. Finally, generate the -project from the `cmake/CMakeLists.txt` file by appending to the -`CMAKE_PREFIX_PATH` variable the install directories of its dependencies. The -resulting project can be edited, built, tested and installed as any CMake -project. Refer to the [CMake](https://cmake.org/documentation) for further -informations on CMake. +This tool post-processes images saved in htrdr-image format. + +## Requirements + +- C compiler +- POSIX make +- pkg-config +- [RSys](https://gitlab.com/vaplv/rsys) +- [Star Color Map](https://gitlab.com/meso-star/star-cmap) +- [mandoc](https://mandoc.bsd.lv) + +## Installation + +Edit config.mk as needed, then run: + + make clean install ## Release notes +### Version 0.5 + +- Write the man page directly in mdoc's roff macros, instead of using + the intermediate scdoc source. +- Replace CMake by Makefile as build system. +- Update compiler and linker flags to increase the security and + robustness of generated binaries. +- Provide a pkg-config file to link the library as an external + dependency. + ### Version 0.4.4 Fix a typo in the man page @@ -36,9 +41,9 @@ Fix a typo in the man page ### Version 0.4.2 -- Fix a wrong assertion on the range of the data to display: in debug `htpp` - was stopping and reporting an error if the data to display all had the same - value. +- Fix a wrong assertion on the range of the data to display: in debug + `htpp` was stopping and reporting an error if the data to display all + had the same value. - Fix the CMake file for MSVC build. ### Version 0.4.1 @@ -49,55 +54,57 @@ Fix a typo in the man page ### Version 0.4 -- Add the `gnuplot` parameter to the `-m` option. Once set, the result image is - written as a gnuplot script rather than a PPM image. This script generates a - PNG image with an embedded color ramp. -- Fix the tone map operator: the exposure term is now also applied to the white - radiance to ensure that it effectively corresponds to the white color in the - output image. +- Add the `gnuplot` parameter to the `-m` option. Once set, the result + image is written as a gnuplot script rather than a PPM image. This + script generates a PNG image with an embedded color ramp. +- Fix the tone map operator: the exposure term is now also applied to + the white radiance to ensure that it effectively corresponds to the + white color in the output image. ### Version 0.3 - Add the `-i` option that regroups all the options controlling the - post-processing of the pixel color. The options `-e` and `-w` that defined - the exposure and the white scale factor are thus removed. -- Add support of raw data visualisation through color palettes. The `-m` option - enables the mapping of a pixel component to a color ramp. Both, the pixel - component to visualise and the palette to use can be set through this option. - The data range to visualise can also be fixed. When this option is defined, - the `-v` option can be used to displays into the terminal the color ramp and - its associated values. + post-processing of the pixel color. The options `-e` and `-w` that + defined the exposure and the white scale factor are thus removed. +- Add support of raw data visualisation through color palettes. The `-m` + option enables the mapping of a pixel component to a color ramp. Both, + the pixel component to visualise and the palette to use can be set + through this option. The data range to visualise can also be fixed. + When this option is defined, the `-v` option can be used to displays + into the terminal the color ramp and its associated values. - Remove the `-u` and `-T` options that are previously used to roughly - visualise the per pixel uncertainties and the estimate of the per realisation - time: the new `-m` option proposes a far more efficient alternative. + visualise the per pixel uncertainties and the estimate of the per + realisation time: the new `-m` option proposes a far more efficient + alternative. ### Version 0.2.1 - Update how the image exposure is handled: the pixels are multiplied by - the exposure priorly to their tone mapping. Previously, it was the tone - mapped pixels that were multiplied by the exposure. + the exposure priorly to their tone mapping. Previously, it was the + tone mapped pixels that were multiplied by the exposure. - Fix the man page that wrongly described the tone mapping operator. ### Version 0.2 -- Fix the XYZ to sRGB conversion: the reference white was not correctly set. -- Fix the gamma correction of the linear sRGB color: there was an issue in the - used formulae. +- Fix the XYZ to sRGB conversion: the reference white was not correctly + set. +- Fix the gamma correction of the linear sRGB color: there was an issue + in the used formulae. ### Version 0.1 - Handle the update of the htrdr-image file format introduced by - [htrdr](https://gitlab.com/meso-star/htrdr/) 0.1 that adds to each pixel the - estimation of the per realisation path computation time. + [htrdr](https://gitlab.com/meso-star/htrdr/) 0.1 that adds to each + pixel the estimation of the per realisation path computation time. ## Copyright notice -Copyright © 2018-2020, 2023 [|Méso|Star>](https://www.meso-star.com) (<contact@meso-star.com>) -Copyright © 2018-2019 Centre National de la Recherche Scientifique -Copyright © 2018-2019 Université Paul Sabatier +Copyright © 2018-2020, 2023 |Méso|Star> (contact@meso-star.com) +Copyright © 2018, 2019 Centre National de la Recherche Scientifique +Copyright © 2018, 2019 Université Paul Sabatier ## License -`htpp` is free software released under the GPL v3+ license: GNU GPL version 3 -or later. You are welcome to redistribute it under certain conditions; refer to -the COPYING file for details. +htpp is free software released under the GPL v3+ license: GNU GPL +version 3 or later. You are welcome to redistribute it under certain +conditions; refer to the COPYING file for details. diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -1,105 +0,0 @@ -# Copyright (C) 2018-2020, 2023 |Méso|Star> (contact@meso-star.com) -# Copyright (C) 2018-2019 Centre National de la Recherche Scientifique -# Copyright (C) 2018-2019 Université Paul Sabatier -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -cmake_minimum_required(VERSION 3.1) -project(htpp C) - -set(HTPP_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src) - -################################################################################ -# Check dependencies -################################################################################ -find_package(RCMake 0.3 REQUIRED) -find_package(RSys 0.9 REQUIRED) -find_package(StarCMap 0.0 REQUIRED) -find_package(OpenMP 1.2 REQUIRED) - -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR}) -include(rcmake) -include(rcmake_runtime) - -include_directories( - ${RSys_INCLUDE_DIR} - ${StarCMap_INCLUDE_DIR} - ${CMAKE_CURRENT_BINARY_DIR}) - -################################################################################ -# Configure and define targets -################################################################################ -set(VERSION_MAJOR 0) -set(VERSION_MINOR 4) -set(VERSION_PATCH 4) -set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) - -configure_file(${HTPP_SOURCE_DIR}/htpp_version.h.in - ${CMAKE_CURRENT_BINARY_DIR}/htpp_version.h @ONLY) - -set(HTPP_FILES_SRC htpp.c) -set(HTPP_FILES_DOC COPYING README.md) - -# Prepend each file in the `HTPP_FILES_<SRC|INC>' list by `HTPP_SOURCE_DIR' -rcmake_prepend_path(HTPP_FILES_SRC ${HTPP_SOURCE_DIR}) -rcmake_prepend_path(HTPP_FILES_DOC ${PROJECT_SOURCE_DIR}/../) - -add_executable(htpp ${HTPP_FILES_SRC}) - -if(CMAKE_COMPILER_IS_GNUCC) - set(MATH_LIB m) -endif() - -target_link_libraries(htpp RSys StarCMap ${MATH_LIB} ${GETOPT_LIB}) -set_target_properties(htpp PROPERTIES COMPILE_FLAGS "${OpenMP_C_FLAGS}") - -if(CMAKE_COMPILER_IS_GNUCC) - target_link_libraries(htpp m) - set_target_properties(htpp PROPERTIES LINK_FLAGS "${OpenMP_C_FLAGS}") -endif() - -set_target_properties(htpp PROPERTIES - COMPILE_FLAGS "${OpenMP_C_FLAGS}" - VERSION ${VERSION} - SOVERSION ${VERSION_MAJOR}) - -################################################################################ -# Man page -############################################################################### -find_program(SCDOC NAMES scdoc) -if(NOT SCDOC) - message(WARNING - "The `scdoc' program is missing. " - "The htpp man page cannot be generated.") -else() - set(_src ${PROJECT_SOURCE_DIR}/../doc/htpp.1.scd) - add_custom_command( - OUTPUT htpp.1 - COMMAND ${SCDOC} < ${_src} > htpp.1 - DEPENDS ${_src} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Buid ROFF man page htpp.1" - VERBATIM) - add_custom_target(man-roff ALL DEPENDS htpp.1) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/htpp.1 DESTINATION share/man/man1) -endif() - -################################################################################ -# Define output & install directories -################################################################################ -install(TARGETS htpp - ARCHIVE DESTINATION bin - LIBRARY DESTINATION lib - RUNTIME DESTINATION bin) -install(FILES ${HTPP_FILES_DOC} DESTINATION share/doc/htpp) diff --git a/config.mk b/config.mk @@ -0,0 +1,76 @@ +VERSION_MAJOR = 0 +VERSION_MINOR = 5 +VERSION_PATCH = 0 +VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) +PREFIX = /usr/local + +LIB_TYPE = SHARED +#LIB_TYPE = STATIC + +BUILD_TYPE = RELEASE +#BUILD_TYPE = DEBUG + +################################################################################ +# Tools +################################################################################ +CC = cc +PKG_CONFIG = pkg-config + +################################################################################ +# Dependencies +################################################################################ +PCFLAGS_SHARED = +PCFLAGS_STATIC = --static +PCFLAGS = $(PCFLAGS_$(LIB_TYPE)) + +SCMAP_VERSION = 0.1 +SCMAP_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags scmap) +SCMAP_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs scmap) + +RSYS_VERSION = 0.14 +RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) +RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) + +DPDC_CFLAGS = $(SCMAP_CFLAGS) $(RSYS_CFLAGS) -fopenmp +DPDC_LIBS = $(SCMAP_LIBS) $(RSYS_LIBS) -fopenmp -lm + +################################################################################ +# Compilation options +################################################################################ +WFLAGS =\ + -Wall\ + -Wcast-align\ + -Wconversion\ + -Wextra\ + -Wmissing-declarations\ + -Wmissing-prototypes\ + -Wshadow + +# Increase security/robustness of the generated binaries +CFLAGS_HARDENED =\ + -D_FORTIFY_SOURCES=2\ + -fcf-protection=full\ + -fPIE\ + -fstack-clash-protection\ + -fstack-protector-strong + +CFLAGS_COMMON =\ + -std=c89\ + -pedantic\ + -fvisibility=hidden\ + -fstrict-aliasing\ + $(CFLAGS_HARDENED)\ + $(WFLAGS) + +CFLAGS_RELEASE = -O2 -DNDEBUG $(CFLAGS_COMMON) +CFLAGS_DEBUG = -g $(CFLAGS_COMMON) +CFLAGS = $(CFLAGS_$(BUILD_TYPE)) + +################################################################################ +# Linker options +################################################################################ +LDFLAGS_HARDENED = -pie -Wl,-z,relro,-z,now + +LDFLAGS_DEBUG = +LDFLAGS_RELEASE = -s +LDFLAGS = $(LDFLAGS_$(BUILD_TYPE)) $(LDFLAGS_HARDENED) diff --git a/doc/htpp.1.scd b/doc/htpp.1.scd @@ -1,257 +0,0 @@ -htpp(1) - -; Copyright (C) 2018-2020, 2023 |Méso|Star> (contact@meso-star.com) -; Copyright (C) 2018-2019 Centre National de la Recherche Scientifique -; Copyright (C) 2018-2019 Université Paul Sabatier -; -; This program is free software: you can redistribute it and/or modify -; it under the terms of the GNU General Public License as published by -; the Free Software Foundation, either version 3 of the License, or -; (at your option) any later version. -; -; This program is distributed in the hope that it will be useful, -; but WITHOUT ANY WARRANTY; without even the implied warranty of -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -; GNU General Public License for more details. -; -; You should have received a copy of the GNU General Public License -; along with this program. If not, see <http://www.gnu.org/licenses/>. - -# NAME - -htpp - High-Tune: Post-Process - -# SYNOPSIS - -htpp [_option_] ... [_input_] - -# DESCRIPTION - -*htpp* post-processes an *htrdr-image*(5) and converts it to a PPM [1] image or a -*gnuplot*(1) script. If _input_ is not defined, the input image is read from -standard input. Two post-processing procedures are provided: image color -post-processing (*-i* option) and mapping of a given pixel component to a color -gradient (*-m* option). By default, *htpp* post-processes the color of the -image. - -## Color post-processsing - -To post-process image colors (*-i* option) *htpp* assumes that the first, third -and fifth components of each input pixel encode a color in the CIE 1931 XYZ -color space. First, *htpp* applies tone correction to these colors via the -following filmic tone mapping operator [2]: - -``` -out-color = f(in-color * exposure) / f(white-value * exposure) -``` - -with: - -``` -f(x) = (x * (A*x + C*B) + D*E) / (x*(A*x + B + D*F)) - E/F - -A = 0.15 -B = 0.50 -C = 0.10 -D = 0.20 -E = 0.02 -F = 0.30 -``` - -The term _exposure_ is a user-defined parameter provided via the _exposure_ -image option. If not set, a default _exposure_ of 1 is used. The _white-value_ -is either set by the user via the _white_ image option or calculated -automatically as the luminance such that 99.5% of the pixel luminances are below -_white-value_. - -After the tone correction function is applied, pixels are transformed from the -CIE 1931 XYZ color space to the linear sRGB color space before being gamma -corrected. Finally, the resulting pixel components are truncated between [0, 1] -and finally encoded to 8 bits. - -## Map a value to a color gradient - -The mapping of a pixel component to a color gradient is controlled by the *-m* -option. The pixel component to be post-processed is defined by the _pixcpnt_ -mapping option. *htpp* normalizes this component to its range across the whole -image or to the _range_ mapping option if set. The resulting value is then -mapped to a color gradient whose name is defined by the _palette_ mapping -option; see the PALETTES section for a list of available color gradients. - -# OPTIONS - -*-f* - Force overwrite of the _output_ file. - -*-h* - List short help and exit. - -*-i* <_sub-option_>[:<_sub-option_> ...] - Post-process the color of the *htrdr-image*(5). The first, the third and the - fifth pixel components are assumed to store the pixel color encoded into the - CIE 1931 XYZ color space. Available sub-options are: - - *default* - Use the default values of the sub-options. - - *exposure*=_real_ - Pixel exposure. By default its value is 1. - - *white*=_radiance_ - Radiance in the _input_ image that will represent the white color in - _output_. If not defined, the white value is automatically computed from - the radiance of the _input_ image. - -*-m* <_sub-option_>[:<_sub-option_> ...] - Map a pixel component to a regular color. Available sub options are: - - *default* - Use the default values of the sub-options. - - *palette*=_palette-name_ - Color palette to use. See the _PALETTES_ section for a complete - list of supported palettes. The default palette is _inferno_. - - *pixcpnt*=_pixel-component_ - Index in [0, 7] of the pixel component to map. The default pixel component - is the first one, i.e. *pixcpnt*=0. - - *range*=_min_,_max_ - 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. This is the default - comportment. - - *gnuplot* - The _output_ image is formatted as a gnuplot script rather than a PPM - image. Once executed, the script generates a PNG image with an embedded - color ramp. Note that this script can be edited in order to adjust the - generated image to any requirements. - -*-o* _output_ - File where the result is written. If not defined, write _output_ to standard - output. - -*-t* _threads-count_ - Hint on the number of threads to use. By default use as many threads as CPU - cores. - -*-v* - Make *htpp* verbose. When used in pixel color post-processing (*-i* option), - *htpp* displays the radiance of the _white_ color in the output image. When - mapping a pixel component to a color gradient (*-m* option), *htpp* displays - the color gradient and its associated values. - -*--version* - Display version information and exit. - -# EXAMPLES - -Post-process the *htrdr-image*(5) saved in _img.htrdr_ and write the resulting -PPM image in _img.ppm_. Use the *-f* option to overwrite _img.ppm_ if it -already exists: - -``` -htpp -f -o img.ppm img.htrdr -``` - -Convert _img.htrdr_ and visualise the resulting image by redirecting the -standard output to the *feh*(1) image viewer. Use an _exposure_ of _0.2_ and -explicitly define the white color to _31.2_ W/sr/m²: - -``` -htpp -i exposure=0.2:white=31.2 img.htrdr | feh - -``` - -Use the *-m* option to map the values of the second pixel component clamped in [0, 2] -to the color ramp _magma_. - -``` -htpp -v -m pixcpnt=1:palette=magma:range=0,2 img.htrdr | feh - -``` - -Use the *-m* option to map the values of the sixth pixel component and write -it as a gnuplot script. Run *gnuplot*(1) to generate a PNG of the result and -visualise the resulting image with *feh*(1). - -``` -htpp -m pixcpnt=6:gnuplot -o img.gp img.htrdr -gnuplot img.gp | feh - -``` - -# PALETTES - -This section lists the available palettes that can be used to map a pixel -component to a color (*-m* option): - -- accent -- blues -- brbg -- bugn -- bupu -- chromajs -- dark2 -- gnbu -- gnpu -- greens -- greys -- inferno -- jet -- magma -- moreland -- oranges -- orrd -- paired -- parula -- pastel1 -- pastel2 -- piyg -- plasma -- prgn -- pubu -- pubugn -- puor -- purd -- purples -- rdbu -- rdgy -- rdpu -- rdylbu -- rdylgn -- reds -- sand -- set1 -- set2 -- set3 -- spectral -- viridis -- whgnbu -- whylrd -- ylgn -- ylgnbu -- ylorbr -- ylorrd -- ylrd - -# COPYRIGHT - -Copyright © 2018, 2019, 2020, 2023 |Méso|Star> <contact@meso-star.com>++ -Copyright © 2018, 2019 Centre National de la Recherche Scientifique++ -Copyright © 2018, 2019 Université Paul Sabatier - -# LICENSE - -*htpp* is free software released under the GPLv3+ license: GNU GPL version 3 or -later <https://gnu.org/licenses/gpl.html>. You are free to change and -redistribute it. There is NO WARRANTY, to the extent permitted by law. - -# SEE ALSO - -. Portable PixMap - <http://netpbm.sourceforge.net/doc/ppm.html> -. Filmic tone mapping operator - - <http://filmicworlds.com/blog/filmic-tonemapping-operators/> -. Star-ColorMap - <https://gitlab.com/meso-star/star-cmap> - -*feh*(1), -*gnuplot*(1), -*htrdr-image*(5) diff --git a/htpp.1 b/htpp.1 @@ -0,0 +1,299 @@ +.\" Copyright (C) 2018-2020, 2023 |Méso|Star> (contact@meso-star.com) +.\" Copyright (C) 2018, 2019 Centre National de la Recherche Scientifique +.\" Copyright (C) 2018, 2019 Université Paul Sabatier +.\" +.\" This program is free software: you can redistribute it and/or modify +.\" it under the terms of the GNU General Public License as published by +.\" the Free Software Foundation, either version 3 of the License, or +.\" (at your option) any later version. +.\" +.\" This program is distributed in the hope that it will be useful, +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.\" GNU General Public License for more details. +.\" +.\" You should have received a copy of the GNU General Public License +.\" along with this program. If not, see <http://www.gnu.org/licenses/>. +.Dd September 11, 2023 +.Dt HTPP 1 +.Os +.Sh NAME +.Nm htpp +.Nd post-processing of +.Xr htrdr-image 5 +images +.Sh SYNOPSIS +.Nm +.Op Fl fhVv +.Op Fl i Ar image_option Ns Op : Ns Ar image_option ... +.Op Fl m Ar map_option Ns Op : Ns Ar map_option ... +.Op Fl o Ar output +.Op Fl t Ar threads_count +.Op Ar input +.Sh DESCRIPTION +.Nm +post-processes a +.Xr htrdr-image 5 +and converts it into a PPM image or +.Xr gnuplot 1 +script. +.Pp +If +.Ar input +is not set, the image to post-process is read from standard input. +Similarly, if the +.Ar output +file is not defined, then the result is written to the standard output. +.Pp +Two post-processing procedures are provided: image color post-processing +.Pq option Fl i +and mapping of a given pixel component to a color gradient +.Pq option Fl m . +By default, +.Nm +post-processes the image color. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl f +Force overwriting of +.Ar output +file. +.It Fl h +Display short help. +.It Fl i Ar image_option Ns Op : Ns Ar image_option ... +Color post-processing. +The first third and fifth components of each pixel of the input +.Xr htrdr-image 5 +are assumed to encode a color in the CIE 1931 XYZ color space. +The colors are first tone-mapped as follows: +.Pp +.Dl out_color = f Ns Po in_color * exposure Pc / f Ns Po white * exposure Pc +.Pp +with: +.Bd -literal -offset Ds +.No f Ns Po Va x Pc = Po Va x Ns * Ns Po A* Ns Va x No + C*B Pc + D*E Pc Ns \ +/ Ns Po Va x Ns * Ns Po A* Ns Va x No + B + D*F Pc Pc - E/F +A = 0.15 +B = 0.50 +C = 0.10 +D = 0.20 +E = 0.02 +F = 0.30 +.Ed +.Pp +Exposure and white color values are user settings +.Pq see below . +Once tone-mapped, pixels are transformed from CIE 1931 XYZ color space to +linear sRGB color space before being gamma-corrected. +Finally, the resulting pixel components are truncated between +.Bq 0, 1 +before being encoded on 8 bits. +.Pp +The post-processing options are as follows: +.Bl -tag -width Ds +.It Cm default +Use default options. +.It Cm exposure= Ns Ar real +Pixel exposure. +Its default value is 1. +.It Cm white= Ns Ar radiance +Radiance value representing white color (in W/sr/m^2). +If not defined, it is set such that 99.5% of the input pixel radiance is less +than its value. +.El +.It Fl m Ar map_option Ns Op : Ns Ar map_option ... +Matching pixel component to a color gradient. +The component to be post-processed is defined by the +.Cm pixcpnt +option. +The component is normalized according to its range over the whole image, or a +user-defined range if defined. +It is finally converted into a color gradient whose name is defined by the +.Cm palette +option. +.Pp +The color matching options are as follows: +.Bl -tag -width Ds +.It Cm default +Use default options. +.It Cm palette= Ns Ar palette_name +Palette to use. +If it is not defined, it takes on the inferno value. +The valid palette names are: +.Pp +.Bl -item -compact -offset Ds +.It +accent +.It +blues +.It +brbg +.It +bugn +.It +bupu +.It +chromajs +.It +dark2 +.It +gnbu +.It +gnpu +.It +greens +.It +greys +.It +inferno +.It +jet +.It +magma +.It +moreland +.It +oranges +.It +orrd +.It +paired +.It +parula +.It +pastel1 +.It +pastel2 +.It +piyg +.It +plasma +.It +prgn +.It +pubu +.It +pubugn +.It +puor +.It +purd +.It +purples +.It +rdbu +.It +rdgy +.It +rdpu +.It +rdylbu +.It +rdylgn +.It +reds +.It +sand +.It +set1 +.It +set2 +.It +set3 +.It +spectral +.It +viridis +.It +whgnbu +.It +whylrd +.It +ylgn +.It +ylgnbu +.It +ylorbr +.It +ylorrd +.It +ylrd +.El +.It Cm pixcpnt= Ns Ar pixel_component +Index of the pixel component to be be mapped. +It must lie within the range +.Bq 0, 7 . +By default it is set to 0, i.e. the first pixel component. +.It Cm range= Ns Ar min , Ns Ar max +Range ov values to be mapped. +A degenerated range +.Pq i.e. Ar min No >= Ar max +means that the range is that of the pixel component over the whole image. +This is the default behavior. +.It Cm gnuplot +Write an output gnuplot script that generates a PNG image with a built-in color +ramp. +.El +.It Fl o Ar output +Output file. +If not defined, data is written to standard output. +.It Fl t Ar threads_count +Indication of the number of threads to be used. +By default, +.Nm +uses many threads as processor cores. +.It Fl v +Make +.Nm +verbose. +Messages are printed on the standard error. +When used as part of pixel color post-processing +.Pq option Fl i , +.Nm +displays the radiance of the white color in the output image. +When mapping a pixel component to a color gradient +.Pq option Fl m , +it displays the color gradient and its associated values. +.It Fl V +Display the version number and exit. +.El +.Sh EXIT STATUS +.Ex -std +.Sh EXAMPLES +Post-process +.Pa img.htrdr +and write the resulting PPM image to +.Pa img.ppm . +Use the +.Fl f +option to overwrite +.Pa img.ppm +if the file already exists. +Use an exposure of 0.2 and explicitly set the white color to 31.2 W/sr/m^2: +.Pp +.Dl htpp -i exposure=0.2:white=31.2 -fo img.ppm img.htrdr +.Pp +Clamp the values of the second pixel component in +.Bq 0, 2 +and map the result to the magma color ramp: +.Pp +.Dl htpp -vm pixcpnt=1:palette=magma:range=0,2 -fo map.ppm img.htrdr +.Pp +Same as above, but use +.Xr gnuplot 1 +to embed the magma color ramp in the output +.Pa map.png +file: +.Bd -literal -offset Ds +htpp -vm pixcpnt=1:palette=magma:range=0,2:gnuplot img.htrdr \\ +| gnuplot - > map.png +.Ed +.Sh SEE ALSO +.Xr gnuplot 1 , +.Xr htrdr-image 5 , +.Xr ppm 5 +.Sh HISTORY +.Nm +was originally developed to post-process images produced by +.Xr htrdr 1 . diff --git a/make.sh b/make.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# Copyright (C) 2018-2020, 2023 |Méso|Star> (contact@meso-star.com) +# Copyright (C) 2018, 2019 Centre National de la Recherche Scientifique +# Copyright (C) 2018, 2019 Université Paul Sabatier +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +set -e + +install() +{ + prefix=$1 + shift 1 + + mkdir -p "${prefix}" + + for i in "$@"; do + dst="${prefix}/${i##*/}" + + if cmp -s "${i}" "${dst}"; then + printf "Up to date %s\n" "${dst}" + else + printf "Installing %s\n" "${dst}" + cp "${i}" "${prefix}" + fi + done +} + +"$@" diff --git a/src/htpp.c b/src/htpp.c @@ -1,6 +1,6 @@ /* Copyright (C) 2018-2020, 2023 |Méso|Star> (contact@meso-star.com) - * Copyright (C) 2018-2019 Centre National de la Recherche Scientifique - * Copyright (C) 2018-2019 Université Paul Sabatier + * Copyright (C) 2018, 2019 Centre National de la Recherche Scientifique + * Copyright (C) 2018, 2019 Université Paul Sabatier * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -112,47 +112,12 @@ static const struct img IMG_NULL = IMG_NULL__; * Helper functions ******************************************************************************/ static void -print_help(const char* cmd) +usage(void) { - ASSERT(cmd); - - printf( -"Usage: %s [options] [image]\n" -"Post process a htrdr-image(5) and convert the result in a regular PPM\n" -"image or in a gnuplot script. If no image name is defined, read the \n" -"image data from 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 <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 <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"); - printf( -" -t <threads-count>\n" -" hint on the number of threads to use.\n" -" By default use as many threads as CPU cores.\n"); printf( -" -v make the program verbose.\n"); - printf( -" --version display version information and exit.\n"); - printf("\n"); - printf( -"htpp is free software released under the GNU GPL license, version 3 or\n" -"later. You are free to change or redistribute it under certain\n" -"conditions <http://gnu.org/licenses/gpl.html>.\n"); +"usage: htpp [-fhVv] [-i image_option[:image_option ...]]\n" +" [-m map_option[:map_option ...]] [-o output]\n" +" [-t threads_count] [input]\n"); } static res_T @@ -334,27 +299,15 @@ static res_T args_init(struct args* args, const int argc, char** argv) { int opt; - int i; res_T res = RES_OK; ASSERT(args && argc && argv); - FOR_EACH(i, 1, argc) { - if(!strcmp(argv[i], "--version")) { - printf("High-Tune: Post-Process %d.%d.%d\n", - HTPP_VERSION_MAJOR, - HTPP_VERSION_MINOR, - HTPP_VERSION_PATCH); - args->quit = 1; - goto exit; - } - } - /* Begin the optstring by ':' to make silent getopt */ - while((opt = getopt(argc, argv, "fhi:m:o:t:v")) != -1) { + while((opt = getopt(argc, argv, "fhi:m:o:t:vV")) != -1) { switch(opt) { case 'f': args->force_overwrite = 1; break; case 'h': - print_help(argv[0]); + usage(); args_release(args); args->quit = 1; goto exit; @@ -372,6 +325,13 @@ args_init(struct args* args, const int argc, char** argv) if(res == RES_OK && args->nthreads <= 0) res = RES_BAD_ARG; break; case 'v': args->verbose = 1; break; + case 'V': + printf("High-Tune: Post-Process %d.%d.%d\n", + HTPP_VERSION_MAJOR, + HTPP_VERSION_MINOR, + HTPP_VERSION_PATCH); + args->quit = 1; + goto exit; default: res = RES_BAD_ARG; break; } if(res != RES_OK) { @@ -393,6 +353,7 @@ exit: optind = 1; return res; error: + usage(); args_release(args); goto exit; }