tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

dec_xyb.h (3312B)


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