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_DJXL_H_
7 #define TOOLS_DJXL_H_
8 
9 #include <stddef.h>
10 
11 #include "jxl/decode.h"
12 #include "lib/jxl/aux_out.h"
13 #include "lib/jxl/base/data_parallel.h"
14 #include "lib/jxl/base/override.h"
15 #include "lib/jxl/base/padded_bytes.h"
16 #include "lib/jxl/base/status.h"
17 #include "lib/jxl/codec_in_out.h"
18 #include "lib/jxl/dec_params.h"
19 #include "tools/args.h"
20 #include "tools/box/box.h"
21 #include "tools/cmdline.h"
22 #include "tools/speed_stats.h"
23 
24 namespace jpegxl {
25 namespace tools {
26 
27 // Common JPEG XL decompress arguments.
28 struct DecompressArgs {
29   // Initialize non-static default options.
30   DecompressArgs() = default;
31 
32   // Add all the command line options to the CommandLineParser. Note that the
33   // options are tied to the instance that this was called on.
34   void AddCommandLineOptions(CommandLineParser* cmdline);
35 
36   // Validate the passed arguments, checking whether all passed options are
37   // compatible. Returns whether the validation was successful.
38   jxl::Status ValidateArgs(const CommandLineParser& cmdline);
39 
40   // Common djxl parameters.
41   const char* file_in = nullptr;
42   const char* file_out = nullptr;
43   size_t num_threads;
44   bool use_sjpeg = false;
45   size_t jpeg_quality = 95;
46   bool decode_to_pixels = false;
47   bool version = false;
48   jxl::Override print_profile = jxl::Override::kDefault;
49 
50   size_t num_reps = 1;
51 
52   // Format parameters:
53 
54   size_t bits_per_sample = 0;
55   bool tone_map = false;
56   std::pair<float, float> display_nits = {0.f, jxl::kDefaultIntensityTarget};
57   std::string color_space;  // description or path to ICC profile
58 
59   jxl::DecompressParams params;
60 
61   // If true, print the effective amount of bytes read from the bitstream.
62   bool print_read_bytes = false;
63   bool quiet = false;
64 
65   // References (ids) of specific options to check if they were matched.
66   CommandLineParser::OptionId opt_num_threads_id = -1;
67   CommandLineParser::OptionId opt_jpeg_quality_id = -1;
68 };
69 
70 // Decompresses and notifies SpeedStats of elapsed time.
71 jxl::Status DecompressJxlToPixels(const jxl::Span<const uint8_t> compressed,
72                                   const jxl::DecompressParams& params,
73                                   jxl::ThreadPool* pool,
74                                   jxl::CodecInOut* JXL_RESTRICT io,
75                                   SpeedStats* JXL_RESTRICT stats);
76 
77 jxl::Status DecompressJxlToJPEG(const JpegXlContainer& container,
78                                 const DecompressArgs& args,
79                                 jxl::ThreadPool* pool, jxl::PaddedBytes* output,
80                                 SpeedStats* JXL_RESTRICT stats);
81 
82 jxl::Status WriteJxlOutput(const DecompressArgs& args, const char* file_out,
83                            jxl::CodecInOut& io,
84                            jxl::ThreadPool* pool = nullptr);
85 
86 }  // namespace tools
87 }  // namespace jpegxl
88 
89 #endif  // TOOLS_DJXL_H_
90