// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
// Desaturate out-of-gamut pixels. This is done by mixing each pixel // with just enough gray of the target luminance to make all // components non-negative. // - For saturation preservation, if a component is still larger than // 1 then the pixel is normalized to have a maximum component of 1. // That will reduce its luminance. // - For luminance preservation, getting all components below 1 is // done by mixing in yet more gray. That will desaturate it further. const V zero = Zero(df); const V one = Set(df, 1);
V gray_mix_saturation = zero;
V gray_mix_luminance = zero; for (const V* ch : {red, green, blue}) { const V& val = *ch; const V val_minus_gray = Sub(val, luminance); const V inv_val_minus_gray =
Div(one, IfThenElse(Eq(val_minus_gray, zero), one, val_minus_gray)); const V val_over_val_minus_gray = Mul(val, inv_val_minus_gray);
gray_mix_saturation =
IfThenElse(Ge(val_minus_gray, zero), gray_mix_saturation,
Max(gray_mix_saturation, val_over_val_minus_gray));
gray_mix_luminance =
Max(gray_mix_luminance,
IfThenElse(Le(val_minus_gray, zero), gray_mix_saturation,
Sub(val_over_val_minus_gray, inv_val_minus_gray)));
} const V gray_mix = Clamp(
MulAdd(Set(df, preserve_saturation),
Sub(gray_mix_saturation, gray_mix_luminance), gray_mix_luminance),
zero, one); for (V* const ch : {red, green, blue}) {
V& val = *ch;
val = MulAdd(gray_mix, Sub(luminance, val), val);
} const V max_clr = Max(Max(one, *red), Max(*green, *blue)); const V normalizer = Div(one, max_clr); for (V* const ch : {red, green, blue}) {
V& val = *ch;
val = Mul(val, normalizer);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.