Coverage Report

Created: 2026-06-30 07:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjxl/lib/extras/enc/jxl.h
Line
Count
Source
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_EXTRAS_ENC_JXL_H_
7
#define LIB_EXTRAS_ENC_JXL_H_
8
9
#include <jxl/encode.h>
10
#include <jxl/memory_manager.h>
11
#include <jxl/parallel_runner.h>
12
#include <jxl/stats.h>
13
#include <jxl/thread_parallel_runner.h>
14
15
#include <cstddef>
16
#include <cstdint>
17
#include <vector>
18
19
namespace jxl {
20
namespace extras {
21
22
class PackedPixelFile;
23
24
struct JXLOption {
25
  JXLOption(JxlEncoderFrameSettingId id, int64_t val, size_t frame_index)
26
0
      : id(id), is_float(false), ival(val), frame_index(frame_index) {}
27
  JXLOption(JxlEncoderFrameSettingId id, float val, size_t frame_index)
28
0
      : id(id), is_float(true), fval(val), frame_index(frame_index) {}
29
30
  JxlEncoderFrameSettingId id;
31
  bool is_float;
32
  union {
33
    int64_t ival;
34
    float fval;
35
  };
36
  size_t frame_index;
37
};
38
39
struct JXLCompressParams {
40
  std::vector<JXLOption> options;
41
42
  // Target butteraugli distance, 0.0 means lossless.
43
  float distance = 1.0f;
44
  float alpha_distance = 0.0f;
45
46
  // If set to true, forces container mode.
47
  bool use_container = false;
48
49
  // Whether to enable/disable byte-exact jpeg reconstruction for jpeg inputs.
50
  bool jpeg_store_metadata = true;
51
  bool jpeg_strip_exif = false;
52
  bool jpeg_strip_xmp = false;
53
  bool jpeg_strip_jumbf = false;
54
55
  // Whether to create brob boxes.
56
  bool compress_boxes = true;
57
58
  // Upper bound on the intensity level present in the image in nits (zero means
59
  // that the library chooses a default).
60
  float intensity_target = 0;
61
  int already_downsampled = 1;
62
  int upsampling_mode = -1;
63
64
  // Overrides for bitdepth, codestream level and alpha premultiply.
65
  size_t override_bitdepth = 0;
66
  int32_t codestream_level = -1;
67
  int32_t premultiply = -1;
68
69
  // If runner_opaque is set, the encoder uses this parallel runner.
70
  JxlParallelRunner runner = JxlThreadParallelRunner;
71
  void* runner_opaque = nullptr;
72
73
  // If memory_manager is set, encoder uses it.
74
  JxlMemoryManager* memory_manager = nullptr;
75
76
  JxlEncoderOutputProcessor output_processor = {};
77
  JxlDebugImageCallback debug_image = nullptr;
78
  void* debug_image_opaque = nullptr;
79
  JxlEncoderStats* stats = nullptr;
80
  bool allow_expert_options = false;
81
82
0
  void AddOption(JxlEncoderFrameSettingId id, int64_t val) {
83
0
    options.emplace_back(id, val, 0);
84
0
  }
85
0
  void AddFloatOption(JxlEncoderFrameSettingId id, float val) {
86
0
    options.emplace_back(id, val, 0);
87
0
  }
88
0
  bool HasOutputProcessor() const {
89
0
    return (output_processor.get_buffer != nullptr &&
90
0
            output_processor.release_buffer != nullptr &&
91
0
            output_processor.set_finalized_position != nullptr);
92
0
  }
93
};
94
95
bool EncodeImageJXL(const JXLCompressParams& params, const PackedPixelFile& ppf,
96
                    const std::vector<uint8_t>* jpeg_bytes,
97
                    std::vector<uint8_t>* compressed);
98
99
}  // namespace extras
100
}  // namespace jxl
101
102
#endif  // LIB_EXTRAS_ENC_JXL_H_