libjxl

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

dec_xyb.h (3230B)


      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_DEC_XYB_H_
      7 #define LIB_JXL_DEC_XYB_H_
      8 
      9 // XYB -> linear sRGB.
     10 
     11 #include <jxl/cms_interface.h>
     12 
     13 #include <cstddef>
     14 #include <cstdint>
     15 
     16 #include "lib/jxl/base/compiler_specific.h"
     17 #include "lib/jxl/base/data_parallel.h"
     18 #include "lib/jxl/base/status.h"
     19 #include "lib/jxl/color_encoding_internal.h"
     20 #include "lib/jxl/image.h"
     21 #include "lib/jxl/image_metadata.h"
     22 
     23 namespace jxl {
     24 
     25 // Parameters for XYB->sRGB conversion.
     26 struct OpsinParams {
     27   float inverse_opsin_matrix[9 * 4];
     28   float opsin_biases[4];
     29   float opsin_biases_cbrt[4];
     30   float quant_biases[4];
     31   void Init(float intensity_target);
     32 };
     33 
     34 struct OutputEncodingInfo {
     35   //
     36   // Fields depending only on image metadata
     37   //
     38   ColorEncoding orig_color_encoding;
     39   // Used for the HLG OOTF and PQ tone mapping.
     40   float orig_intensity_target;
     41   // Opsin inverse matrix taken from the metadata.
     42   float orig_inverse_matrix[9];
     43   bool default_transform;
     44   bool xyb_encoded;
     45   //
     46   // Fields depending on output color encoding
     47   //
     48   // The requested color encoding.
     49   ColorEncoding color_encoding;
     50   // This is expected as the output of the conversion from XYB.
     51   // It is equal to `color_encoding`, but with a linear tone response curve.
     52   ColorEncoding linear_color_encoding;
     53   bool color_encoding_is_original;
     54   // Contains an opsin matrix that converts to the primaries of the output
     55   // encoding.
     56   OpsinParams opsin_params;
     57   bool all_default_opsin;
     58   // Used for Gamma and DCI transfer functions.
     59   float inverse_gamma;
     60   // Luminances of color_encoding's primaries, used for the HLG inverse OOTF and
     61   // for PQ tone mapping.
     62   // Default to sRGB's.
     63   float luminances[3];
     64   // Used for the HLG inverse OOTF and PQ tone mapping.
     65   float desired_intensity_target;
     66   bool cms_set = false;
     67   JxlCmsInterface color_management_system;
     68 
     69   Status SetFromMetadata(const CodecMetadata& metadata);
     70   Status MaybeSetColorEncoding(const ColorEncoding& c_desired);
     71 
     72  private:
     73   Status SetColorEncoding(const ColorEncoding& c_desired);
     74 };
     75 
     76 // Converts `inout` (not padded) from opsin to linear sRGB in-place. Called from
     77 // per-pass postprocessing, hence parallelized.
     78 void OpsinToLinearInplace(Image3F* JXL_RESTRICT inout, ThreadPool* pool,
     79                           const OpsinParams& opsin_params);
     80 
     81 // Converts `opsin:rect` (opsin may be padded, rect.x0 must be vector-aligned)
     82 // to linear sRGB. Called from whole-frame encoder, hence parallelized.
     83 void OpsinToLinear(const Image3F& opsin, const Rect& rect, ThreadPool* pool,
     84                    Image3F* JXL_RESTRICT linear,
     85                    const OpsinParams& opsin_params);
     86 
     87 // Bt.601 to match JPEG/JFIF. Inputs are _signed_ YCbCr values suitable for DCT,
     88 // see F.1.1.3 of T.81 (because our data type is float, there is no need to add
     89 // a bias to make the values unsigned).
     90 void YcbcrToRgb(const Image3F& ycbcr, Image3F* rgb, const Rect& rect);
     91 
     92 bool HasFastXYBTosRGB8();
     93 void FastXYBTosRGB8(const float* input[4], uint8_t* output, bool is_rgba,
     94                     size_t xsize);
     95 
     96 }  // namespace jxl
     97 
     98 #endif  // LIB_JXL_DEC_XYB_H_