tor-browser

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

enc_frame.h (4339B)


      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_FRAME_H_
      7 #define LIB_JXL_ENC_FRAME_H_
      8 
      9 #include <jxl/cms_interface.h>
     10 #include <jxl/memory_manager.h>
     11 #include <jxl/types.h>
     12 
     13 #include <cstddef>
     14 #include <cstdint>
     15 #include <string>
     16 #include <vector>
     17 
     18 #include "lib/jxl/base/data_parallel.h"
     19 #include "lib/jxl/base/status.h"
     20 #include "lib/jxl/enc_bit_writer.h"
     21 #include "lib/jxl/enc_cache.h"
     22 #include "lib/jxl/enc_params.h"
     23 #include "lib/jxl/encode_internal.h"
     24 #include "lib/jxl/frame_header.h"
     25 #include "lib/jxl/image_bundle.h"
     26 #include "lib/jxl/image_metadata.h"
     27 
     28 namespace jxl {
     29 
     30 struct AuxOut;
     31 
     32 // Information needed for encoding a frame that is not contained elsewhere and
     33 // does not belong to `cparams`.
     34 // TODO(lode): if possible, it might be better to replace FrameInfo and several
     35 // fields from ImageBundle (such as frame name and duration) by direct usage of
     36 // jxl::FrameHeader itself.
     37 struct FrameInfo {
     38  // TODO(veluca): consider adding more parameters, such as custom patches.
     39  bool save_before_color_transform = false;
     40  // Whether or not the input image bundle is already in the codestream
     41  // colorspace (as deduced by cparams).
     42  // TODO(veluca): this is a hack - ImageBundle doesn't have a simple way to say
     43  // "this is already in XYB".
     44  bool ib_needs_color_transform = true;
     45  FrameType frame_type = FrameType::kRegularFrame;
     46  size_t dc_level = 0;
     47  // Only used for kRegularFrame.
     48  bool is_last = true;
     49  bool is_preview = false;
     50  // Information for storing this frame for future use (only for non-DC frames).
     51  size_t save_as_reference = 0;
     52  // The source frame for blending of a next frame, matching the
     53  // save_as_reference value of a previous frame. Animated frames can use
     54  // save_as_reference values 1, 2 and 3, while composite still frames can use
     55  // save_as_reference values 0, 1, 2 and 3. The current C++ encoder
     56  // implementation is assuming and using 1 for all frames of animations, so
     57  // using that as the default value here.
     58  // Corresponds to BlendingInfo::source from the FrameHeader.
     59  size_t source = 1;
     60  // Corresponds to BlendingInfo::clamp from the FrameHeader.
     61  bool clamp = true;
     62  // Corresponds to BlendingInfo::alpha_channel from the FrameHeader, or set to
     63  // -1 to automatically choose it as the index of the first extra channel of
     64  // type alpha.
     65  int alpha_channel = -1;
     66 
     67  FrameOrigin origin{0, 0};
     68 
     69  bool blend = false;
     70  BlendMode blendmode = BlendMode::kBlend;
     71 
     72  JxlBitDepth image_bit_depth = {};
     73 
     74  // Animation-related information, corresponding to the timecode and duration
     75  // fields of the jxl::AnimationFrame of the jxl::FrameHeader.
     76  uint32_t duration = 0;
     77  uint32_t timecode = 0;
     78 
     79  std::string name;
     80 
     81  // If non-empty, uses this blending info for the extra channels, otherwise
     82  // automatically chooses it. The encoder API will fill this vector with the
     83  // extra channel info and allows more options. The non-API cjxl leaves it
     84  // empty and relies on the default behavior.
     85  std::vector<BlendingInfo> extra_channel_blending_info;
     86 };
     87 
     88 // Checks and adjusts CompressParams when they are all initialized.
     89 Status ParamsPostInit(CompressParams* p);
     90 
     91 // Encodes a single frame (including its header) into a byte stream.  Groups may
     92 // be processed in parallel by `pool`. metadata is the ImageMetadata encoded in
     93 // the codestream, and must be used for the FrameHeaders, do not use
     94 // ib.metadata.
     95 Status EncodeFrame(JxlMemoryManager* memory_manager,
     96                   const CompressParams& cparams_orig,
     97                   const FrameInfo& frame_info, const CodecMetadata* metadata,
     98                   JxlEncoderChunkedFrameAdapter& frame_data,
     99                   const JxlCmsInterface& cms, ThreadPool* pool,
    100                   JxlEncoderOutputProcessorWrapper* output_processor,
    101                   AuxOut* aux_out);
    102 
    103 Status EncodeFrame(JxlMemoryManager* memory_manager,
    104                   const CompressParams& cparams_orig,
    105                   const FrameInfo& frame_info, const CodecMetadata* metadata,
    106                   ImageBundle& ib, const JxlCmsInterface& cms,
    107                   ThreadPool* pool, BitWriter* writer, AuxOut* aux_out);
    108 
    109 }  // namespace jxl
    110 
    111 #endif  // LIB_JXL_ENC_FRAME_H_