libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

enc_gamma_correct.h (953B)


      1 // Copyright (c) the JPEG XL Project Authors. All rights reserved.
      2 //
      3 // Use of this source code is governed by a BSD-style
      4 // license that can be found in the LICENSE file.
      5 
      6 #ifndef LIB_JXL_ENC_GAMMA_CORRECT_H_
      7 #define LIB_JXL_ENC_GAMMA_CORRECT_H_
      8 
      9 // Deprecated: sRGB transfer function. Use JxlCms instead.
     10 
     11 #include <cmath>
     12 
     13 #include "lib/jxl/base/compiler_specific.h"
     14 
     15 namespace jxl {
     16 
     17 // Values are in [0, 1].
     18 static JXL_INLINE double Srgb8ToLinearDirect(double srgb) {
     19   if (srgb <= 0.0) return 0.0;
     20   if (srgb <= 0.04045) return srgb / 12.92;
     21   if (srgb >= 1.0) return 1.0;
     22   return std::pow((srgb + 0.055) / 1.055, 2.4);
     23 }
     24 
     25 // Values are in [0, 1].
     26 static JXL_INLINE double LinearToSrgb8Direct(double linear) {
     27   if (linear <= 0.0) return 0.0;
     28   if (linear >= 1.0) return 1.0;
     29   if (linear <= 0.0031308) return linear * 12.92;
     30   return std::pow(linear, 1.0 / 2.4) * 1.055 - 0.055;
     31 }
     32 
     33 }  // namespace jxl
     34 
     35 #endif  // LIB_JXL_ENC_GAMMA_CORRECT_H_