libjxl

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

benchmark_codec_png.cc (2326B)


      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 #include "tools/benchmark/benchmark_codec_png.h"
      7 
      8 #include <stddef.h>
      9 #include <stdint.h>
     10 
     11 #include <string>
     12 #include <vector>
     13 
     14 #include "lib/extras/codec.h"
     15 #include "lib/extras/dec/apng.h"
     16 #include "lib/extras/dec/decode.h"
     17 #include "lib/extras/enc/apng.h"
     18 #include "lib/extras/time.h"
     19 #include "lib/jxl/base/span.h"
     20 #include "lib/jxl/base/status.h"
     21 #include "tools/benchmark/benchmark_args.h"
     22 #include "tools/benchmark/benchmark_codec.h"
     23 #include "tools/speed_stats.h"
     24 #include "tools/thread_pool_internal.h"
     25 
     26 namespace jpegxl {
     27 namespace tools {
     28 
     29 struct PNGArgs {
     30   // Empty, no PNG-specific args currently.
     31 };
     32 
     33 static PNGArgs* const pngargs = new PNGArgs;
     34 
     35 Status AddCommandLineOptionsPNGCodec(BenchmarkArgs* args) { return true; }
     36 
     37 // Lossless.
     38 class PNGCodec : public ImageCodec {
     39  public:
     40   explicit PNGCodec(const BenchmarkArgs& args) : ImageCodec(args) {}
     41 
     42   Status ParseParam(const std::string& param) override { return true; }
     43 
     44   Status Compress(const std::string& filename, const PackedPixelFile& ppf,
     45                   ThreadPool* pool, std::vector<uint8_t>* compressed,
     46                   jpegxl::tools::SpeedStats* speed_stats) override {
     47     const double start = jxl::Now();
     48     JXL_RETURN_IF_ERROR(
     49         jxl::Encode(ppf, jxl::extras::Codec::kPNG, compressed, pool));
     50     const double end = jxl::Now();
     51     speed_stats->NotifyElapsed(end - start);
     52     return true;
     53   }
     54 
     55   Status Decompress(const std::string& /*filename*/,
     56                     const Span<const uint8_t> compressed, ThreadPool* pool,
     57                     PackedPixelFile* ppf,
     58                     jpegxl::tools::SpeedStats* speed_stats) override {
     59     const double start = jxl::Now();
     60     JXL_RETURN_IF_ERROR(jxl::extras::DecodeImageAPNG(
     61         compressed, jxl::extras::ColorHints(), ppf));
     62     const double end = jxl::Now();
     63     speed_stats->NotifyElapsed(end - start);
     64     return true;
     65   }
     66 };
     67 
     68 ImageCodec* CreateNewPNGCodec(const BenchmarkArgs& args) {
     69   if (jxl::extras::GetAPNGEncoder() &&
     70       jxl::extras::CanDecode(jxl::extras::Codec::kPNG)) {
     71     return new PNGCodec(args);
     72   } else {
     73     return nullptr;
     74   }
     75 }
     76 
     77 }  // namespace tools
     78 }  // namespace jpegxl