// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. #ifndef LIB_EXTRAS_ENC_ENCODE_H_ #define LIB_EXTRAS_ENC_ENCODE_H_ // Facade for image encoders. #include #include #include "lib/extras/dec/decode.h" #include "lib/jxl/base/compiler_specific.h" #include "lib/jxl/base/data_parallel.h" #include "lib/jxl/base/padded_bytes.h" #include "lib/jxl/base/span.h" #include "lib/jxl/base/status.h" #include "lib/jxl/codec_in_out.h" #include "lib/jxl/field_encodings.h" // MakeBit namespace jxl { namespace extras { struct EncodedImage { // One (if the format supports animations or the image has only one frame) or // more sequential bitstreams. std::vector> bitstreams; // If the format does not support embedding color profiles into the bitstreams // above, it will be present here, to be written as a separate file. If it // does support them, this field will be empty. std::vector icc; }; class Encoder { public: static std::unique_ptr FromExtension(std::string extension); virtual ~Encoder() = default; virtual std::vector AcceptedFormats() const = 0; // Any existing data in encoded_image is discarded. virtual Status Encode(const PackedPixelFile& ppf, EncodedImage* encoded_image, ThreadPool* pool = nullptr) const = 0; void SetOption(std::string name, std::string value) { options_[std::move(name)] = std::move(value); } protected: const std::unordered_map& options() const { return options_; } private: std::unordered_map options_; }; // TODO(sboukortt): consider exposing this as part of the C API. Status SelectFormat(const std::vector& accepted_formats, const JxlBasicInfo& basic_info, JxlPixelFormat* format); } // namespace extras } // namespace jxl #endif // LIB_EXTRAS_ENC_ENCODE_H_