libjxl

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

benchmark_codec.h (3168B)


      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 TOOLS_BENCHMARK_BENCHMARK_CODEC_H_
      7 #define TOOLS_BENCHMARK_BENCHMARK_CODEC_H_
      8 
      9 #include <stdint.h>
     10 
     11 #include <deque>
     12 #include <string>
     13 #include <vector>
     14 
     15 #include "lib/extras/packed_image.h"
     16 #include "lib/extras/packed_image_convert.h"
     17 #include "lib/jxl/base/data_parallel.h"
     18 #include "lib/jxl/base/span.h"
     19 #include "lib/jxl/base/status.h"
     20 #include "lib/jxl/butteraugli/butteraugli.h"
     21 #include "lib/jxl/codec_in_out.h"
     22 #include "lib/jxl/image.h"
     23 #include "tools/args.h"
     24 #include "tools/benchmark/benchmark_args.h"
     25 #include "tools/benchmark/benchmark_stats.h"
     26 #include "tools/cmdline.h"
     27 #include "tools/speed_stats.h"
     28 #include "tools/thread_pool_internal.h"
     29 
     30 namespace jpegxl {
     31 namespace tools {
     32 
     33 using ::jxl::CodecInOut;
     34 using ::jxl::Span;
     35 using ::jxl::extras::PackedPixelFile;
     36 
     37 // Thread-compatible.
     38 class ImageCodec {
     39  public:
     40   explicit ImageCodec(const BenchmarkArgs& args)
     41       : args_(args),
     42         butteraugli_target_(1.0f),
     43         q_target_(100.0f),
     44         bitrate_target_(0.0f) {}
     45 
     46   virtual ~ImageCodec() = default;
     47 
     48   void set_description(const std::string& desc) { description_ = desc; }
     49   const std::string& description() const { return description_; }
     50 
     51   virtual void ParseParameters(const std::string& parameters);
     52 
     53   virtual Status ParseParam(const std::string& param);
     54 
     55   virtual Status Compress(const std::string& filename,
     56                           const PackedPixelFile& ppf, ThreadPool* pool,
     57                           std::vector<uint8_t>* compressed,
     58                           jpegxl::tools::SpeedStats* speed_stats) = 0;
     59 
     60   virtual Status Decompress(const std::string& filename,
     61                             const Span<const uint8_t> compressed,
     62                             ThreadPool* pool, PackedPixelFile* ppf,
     63                             jpegxl::tools::SpeedStats* speed_stats) = 0;
     64 
     65   virtual void GetMoreStats(BenchmarkStats* stats) {}
     66 
     67   virtual bool IgnoreAlpha() const { return false; }
     68 
     69   virtual Status CanRecompressJpeg() const { return false; }
     70   virtual Status RecompressJpeg(const std::string& filename,
     71                                 const std::vector<uint8_t>& data,
     72                                 std::vector<uint8_t>* compressed,
     73                                 jpegxl::tools::SpeedStats* speed_stats) {
     74     return false;
     75   }
     76 
     77   virtual std::string GetErrorMessage() const { return error_message_; }
     78 
     79  protected:
     80   const BenchmarkArgs& args_;
     81   std::string params_;
     82   std::string description_;
     83   float butteraugli_target_;
     84   float q_target_;
     85   float bitrate_target_;
     86   std::string error_message_;
     87 };
     88 
     89 using ImageCodecPtr = std::unique_ptr<ImageCodec>;
     90 
     91 // Creates an image codec by name, e.g. "jxl" to get a new instance of the
     92 // jxl codec. Optionally, behind a colon, parameters can be specified,
     93 // then ParseParameters of the codec gets called with the part behind the colon.
     94 ImageCodecPtr CreateImageCodec(const std::string& description);
     95 
     96 }  // namespace tools
     97 }  // namespace jpegxl
     98 
     99 #endif  // TOOLS_BENCHMARK_BENCHMARK_CODEC_H_