diff --git a/lib/src/gpu/applygainmap_gl.cpp b/lib/src/gpu/applygainmap_gl.cpp index 6e3677db..934a93dd 100644 --- a/lib/src/gpu/applygainmap_gl.cpp +++ b/lib/src/gpu/applygainmap_gl.cpp @@ -136,13 +136,13 @@ static const std::string applyGainMapShader = R"__SHADER__( uniform float logMinBoost; uniform float logMaxBoost; uniform float weight; - uniform float displayBoost; + uniform float normalize; float applyGainMapSample(const float channel, float gain) { gain = pow(gain, 1.0f / gamma); float logBoost = logMinBoost * (1.0f - gain) + logMaxBoost * gain; logBoost = exp2(logBoost * weight); - return channel * logBoost / displayBoost; + return channel * logBoost / normalize; } vec3 applyGain(const vec3 color, const vec3 gain) { @@ -317,7 +317,7 @@ uhdr_error_info_t applyGainMapGLES(uhdr_raw_image_t* sdr_intent, uhdr_raw_image_ GLint logMinBoostLocation = glGetUniformLocation(shaderProgram, "logMinBoost"); GLint logMaxBoostLocation = glGetUniformLocation(shaderProgram, "logMaxBoost"); GLint weightLocation = glGetUniformLocation(shaderProgram, "weight"); - GLint displayBoostLocation = glGetUniformLocation(shaderProgram, "displayBoost"); + GLint normalizeLocation = glGetUniformLocation(shaderProgram, "normalize"); glUniform1i(pWidthLocation, sdr_intent->w); glUniform1i(pHeightLocation, sdr_intent->h); @@ -335,7 +335,10 @@ uhdr_error_info_t applyGainMapGLES(uhdr_raw_image_t* sdr_intent, uhdr_raw_image_ gainmap_weight = 1.0f; } glUniform1f(weightLocation, gainmap_weight); - glUniform1f(displayBoostLocation, display_boost); + float normalize = 1.0f; + if (output_ct == UHDR_CT_HLG) normalize = kHlgMaxNits / kSdrWhiteNits; + else if (output_ct == UHDR_CT_PQ) normalize = kPqMaxNits / kSdrWhiteNits; + glUniform1f(normalizeLocation, normalize); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, yuvTexture); diff --git a/lib/src/jpegr.cpp b/lib/src/jpegr.cpp index dbcb80ca..0043526f 100644 --- a/lib/src/jpegr.cpp +++ b/lib/src/jpegr.cpp @@ -1477,7 +1477,7 @@ uhdr_error_info_t JpegR::applyGainMap(uhdr_raw_image_t* sdr_intent, uhdr_raw_ima JobQueue jobQueue; std::function applyRecMap = [sdr_intent, gainmap_img, dest, &jobQueue, &idwTable, - output_ct, &gainLUT, display_boost, + output_ct, &gainLUT, #if !USE_APPLY_GAIN_LUT gainmap_metadata, gainmap_weight, #endif @@ -1530,7 +1530,6 @@ uhdr_error_info_t JpegR::applyGainMap(uhdr_raw_image_t* sdr_intent, uhdr_raw_ima #endif } - rgb_hdr = rgb_hdr / display_boost; size_t pixel_idx = x + y * dest->stride[UHDR_PLANE_PACKED]; switch (output_ct) { @@ -1545,6 +1544,7 @@ uhdr_error_info_t JpegR::applyGainMap(uhdr_raw_image_t* sdr_intent, uhdr_raw_ima #else ColorTransformFn hdrOetf = hlgOetf; #endif + rgb_hdr = rgb_hdr * kSdrWhiteNits / kHlgMaxNits; rgb_hdr = hlgInverseOotfApprox(rgb_hdr); Color rgb_gamma_hdr = hdrOetf(rgb_hdr); uint32_t rgba_1010102 = colorToRgba1010102(rgb_gamma_hdr); @@ -1558,6 +1558,7 @@ uhdr_error_info_t JpegR::applyGainMap(uhdr_raw_image_t* sdr_intent, uhdr_raw_ima #else ColorTransformFn hdrOetf = pqOetf; #endif + rgb_hdr = rgb_hdr * kSdrWhiteNits / kPqMaxNits; Color rgb_gamma_hdr = hdrOetf(rgb_hdr); uint32_t rgba_1010102 = colorToRgba1010102(rgb_gamma_hdr); reinterpret_cast(dest->planes[UHDR_PLANE_PACKED])[pixel_idx] =