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