Skip to content

Commit

Permalink
Fix a few conditions (libjxl#2947)
Browse files Browse the repository at this point in the history
  • Loading branch information
sboukortt authored Nov 15, 2023
1 parent f1fd4c3 commit 54eb36c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/jxl/cms/color_management.cc
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ Status PrimariesToXYZ(float rx, float ry, float gx, float gy, float bx,

// Adapts whitepoint x, y to D50
Status AdaptToXYZD50(float wx, float wy, float matrix[9]) {
bool ok = (wx >= 0) || (wx <= 1) || (wy > 0) || (wy <= 1);
bool ok = (wx >= 0) && (wx <= 1) && (wy > 0) && (wy <= 1);
if (!ok) {
// Out of range values can cause division through zero
// further down with the bradford adaptation too.
Expand Down
11 changes: 6 additions & 5 deletions lib/jxl/render_pipeline/stage_tone_mapping.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,25 @@ class ToneMappingStage : public RenderPipelineStage {
// No tone mapping requested.
return;
}
const auto& tf = output_encoding_info_.orig_color_encoding.Tf();
if (tf.IsPQ() && output_encoding_info_.desired_intensity_target <
output_encoding_info_.orig_intensity_target) {
const auto& orig_tf = output_encoding_info_.orig_color_encoding.Tf();
const auto& dest_tf = output_encoding_info_.color_encoding.Tf();
if (orig_tf.IsPQ() && output_encoding_info_.desired_intensity_target <
output_encoding_info_.orig_intensity_target) {
tone_mapper_ = jxl::make_unique<ToneMapper>(
/*source_range=*/std::pair<float, float>(
0, output_encoding_info_.orig_intensity_target),
/*target_range=*/
std::pair<float, float>(
0, output_encoding_info_.desired_intensity_target),
output_encoding_info_.luminances);
} else if (tf.IsHLG() && !tf.IsHLG()) {
} else if (orig_tf.IsHLG() && !dest_tf.IsHLG()) {
hlg_ootf_ = jxl::make_unique<HlgOOTF>(
/*source_luminance=*/output_encoding_info_.orig_intensity_target,
/*target_luminance=*/output_encoding_info_.desired_intensity_target,
output_encoding_info_.luminances);
}

if (tf.IsPQ() && (tone_mapper_ || hlg_ootf_)) {
if (dest_tf.IsPQ() && (tone_mapper_ || hlg_ootf_)) {
to_intensity_target_ =
10000.f / output_encoding_info_.orig_intensity_target;
from_desired_intensity_target_ =
Expand Down

0 comments on commit 54eb36c

Please sign in to comment.