htpp

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

commit 2b15a44864f5e10c61d96c5aea498d0282d3f4a2
parent 0508bdc98c9d4e91a606c93aa0f0604f5cfbd1e9
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue,  2 Jul 2019 15:17:20 +0200

Merge branch 'release_0.2'

Diffstat:
MREADME.md | 6++++++
Mcmake/CMakeLists.txt | 2+-
Mdoc/htpp.1.txt | 12++++++------
Msrc/htpp.c | 34+++++++++++++++++++---------------
4 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/README.md b/README.md @@ -29,6 +29,12 @@ informations on CMake. ## Release notes +### 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. + ### Version 0.1 - Handle the update of the htrdr-image file format introduced by diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -35,7 +35,7 @@ include_directories(${RSys_INCLUDE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) # Configure and define targets ################################################################################ set(VERSION_MAJOR 0) -set(VERSION_MINOR 1) +set(VERSION_MINOR 2) set(VERSION_PATCH 0) set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) diff --git a/doc/htpp.1.txt b/doc/htpp.1.txt @@ -54,9 +54,9 @@ either defined by the user through the *-w* option or automatically computed as the luminance from which roughly all image pixels have a luminance less than _white-scale_. Currently, *htpp* empirically defines _white-scale_ as the luminance greater than the luminance of 99.5% of the pixels. Once tone mapped, -the pixels are transformed from the CIE 1931 XYZ color space to the sRGB color -space. Finally, the resulting pixel components are clamped to [0, 1] and -encoded on 8-bits. +the pixels are transformed from the CIE 1931 XYZ color space to the sRGB +linear color space before to be gamma corrected. Finally, the resulting pixel +components are clamped to [0, 1] and encoded on 8-bits. OPTIONS ------- @@ -125,9 +125,9 @@ NOTES COPYRIGHT --------- -Copyright &copy; 2018 CNRS, |Meso|Star> <contact@meso-star.com>, Université -Paul Sabatier <contact-edstar@laplace.univ-tlse.fr>. *htpp* is free software -released under the GPLv3+ license: GNU GPL version 3 or later +Copyright &copy; 2018-2019 CNRS, |Meso|Star> <contact@meso-star.com>, +Université Paul Sabatier <contact-edstar@laplace.univ-tlse.fr>. *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. diff --git a/src/htpp.c b/src/htpp.c @@ -285,32 +285,36 @@ filmic_tone_mapping(double pixel[3], const double exposure, const double Ymax) } static double* -XYZ_to_RGB(double XYZ[3]) +XYZ_to_sRGB(double XYZ[3]) { - const double mat[9] = { /* D65 */ + #define D65_x 0.31271 + #define D65_y 0.32902 + const double D65[3] = {D65_x / D65_y, 1.0, (1 - D65_x - D65_y) / D65_y}; + const double mat[9] = { /* XYZ to sRGB matrix */ 3.2404542, -0.9692660, 0.0556434, -1.5371385, 1.8760108, -0.2040259, -0.4985314, 0.0415560, 1.0572252 }; - double* RGB = XYZ; + double* sRGB = XYZ; + double* XYZ_D65 = XYZ; ASSERT(XYZ); - d33_muld3(RGB, mat, XYZ); - RGB[0] = MMAX(RGB[0], 0); - RGB[1] = MMAX(RGB[1], 0); - RGB[2] = MMAX(RGB[2], 0); - return RGB; + d3_mul(XYZ_D65, XYZ, D65); + d33_muld3(sRGB, mat, XYZ_D65); + sRGB[0] = MMAX(sRGB[0], 0); + sRGB[1] = MMAX(sRGB[1], 0); + sRGB[2] = MMAX(sRGB[2], 0); + return sRGB; } static double* -RGB_to_sRGB(double RGB[3]) +sRGB_gamma_correct(double sRGB[3]) { - double* sRGB = RGB; int i; FOR_EACH(i, 0, 3) { - if(RGB[i] <= 0.0031308) { - sRGB[i] = RGB[i] * 12.92; + if(sRGB[i] <= 0.0031308) { + sRGB[i] = sRGB[i] * 12.92; } else { - sRGB[i] = 1.055 * pow(RGB[i], 1.0/2.4); + sRGB[i] = 1.055 * pow(sRGB[i], 1.0/2.4) - 0.055; } } return sRGB; @@ -566,8 +570,8 @@ main(int argc, char** argv) filmic_tone_mapping(pixel, args.exposure, Ymax); /* Tone map the RGB pixel */ if(args.pixdata == PIXEL_RADIANCE) { - XYZ_to_RGB(pixel); /* Convert in RGB color space */ - RGB_to_sRGB(pixel); /* Convert in sRGB color space (i.e. gamma correction) */ + XYZ_to_sRGB(pixel); /* Convert in RGB color space */ + sRGB_gamma_correct(pixel); /* Convert in sRGB color space (i.e. gamma correction) */ } }