Bug 1905042 - The AI Chat Sidebar stays open when the user disables the AI chat integ...
[gecko.git] / third_party / jpeg-xl / lib / jpegli / test_params.h
blob6ab9fa573ae601a00ac637ae55fcc923b0ad3815
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.
6 #ifndef LIB_JPEGLI_TEST_PARAMS_H_
7 #define LIB_JPEGLI_TEST_PARAMS_H_
9 #include <stddef.h>
10 #include <stdint.h>
12 #include <algorithm>
13 #include <vector>
15 #include "lib/jpegli/types.h"
17 namespace jpegli {
19 // We define this here as well to make sure that the *_api_test.cc tests only
20 // use the public API and therefore we don't include any *_internal.h headers.
21 template <typename T1, typename T2>
22 constexpr inline T1 DivCeil(T1 a, T2 b) {
23 return (a + b - 1) / b;
26 #define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0]))
28 static constexpr int kLastScan = 0xffff;
30 static uint32_t kTestColorMap[] = {
31 0x000000, 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0x00ffff,
32 0xff00ff, 0xffffff, 0x6251fc, 0x45d9c7, 0xa7f059, 0xd9a945,
33 0xfa4e44, 0xceaffc, 0xbad7db, 0xc1f0b1, 0xdbca9a, 0xfacac5,
34 0xf201ff, 0x0063db, 0x00f01c, 0xdbb204, 0xf12f0c, 0x7ba1dc};
35 static constexpr int kTestColorMapNumColors = ARRAY_SIZE(kTestColorMap);
37 static constexpr int kSpecialMarker0 = 0xe5;
38 static constexpr int kSpecialMarker1 = 0xe9;
39 static constexpr uint8_t kMarkerData[] = {0, 1, 255, 0, 17};
40 static constexpr uint8_t kMarkerSequence[] = {0xe6, 0xe8, 0xe7,
41 0xe6, 0xe7, 0xe8};
42 static constexpr size_t kMarkerSequenceLen = ARRAY_SIZE(kMarkerSequence);
44 enum JpegIOMode {
45 PIXELS,
46 RAW_DATA,
47 COEFFICIENTS,
50 struct CustomQuantTable {
51 int slot_idx = 0;
52 uint16_t table_type = 0;
53 int scale_factor = 100;
54 bool add_raw = false;
55 bool force_baseline = true;
56 std::vector<unsigned int> basic_table;
57 std::vector<unsigned int> quantval;
58 void Generate();
61 struct TestImage {
62 size_t xsize = 2268;
63 size_t ysize = 1512;
64 int color_space = 2; // JCS_RGB
65 size_t components = 3;
66 JpegliDataType data_type = JPEGLI_TYPE_UINT8;
67 JpegliEndianness endianness = JPEGLI_NATIVE_ENDIAN;
68 std::vector<uint8_t> pixels;
69 std::vector<std::vector<uint8_t>> raw_data;
70 std::vector<std::vector<int16_t>> coeffs;
71 void AllocatePixels() {
72 pixels.resize(ysize * xsize * components *
73 jpegli_bytes_per_sample(data_type));
75 void Clear() {
76 pixels.clear();
77 raw_data.clear();
78 coeffs.clear();
82 struct CompressParams {
83 int quality = 90;
84 bool set_jpeg_colorspace = false;
85 int jpeg_color_space = 0; // JCS_UNKNOWN
86 std::vector<int> quant_indexes;
87 std::vector<CustomQuantTable> quant_tables;
88 std::vector<int> h_sampling;
89 std::vector<int> v_sampling;
90 std::vector<int> comp_ids;
91 int override_JFIF = -1;
92 int override_Adobe = -1;
93 bool add_marker = false;
94 bool simple_progression = false;
95 // -1 is library default
96 // 0, 1, 2 is set through jpegli_set_progressive_level()
97 // 2 + N is kScriptN
98 int progressive_mode = -1;
99 unsigned int restart_interval = 0;
100 int restart_in_rows = 0;
101 int smoothing_factor = 0;
102 int optimize_coding = -1;
103 bool use_flat_dc_luma_code = false;
104 bool omit_standard_tables = false;
105 bool xyb_mode = false;
106 bool libjpeg_mode = false;
107 bool use_adaptive_quantization = true;
108 std::vector<uint8_t> icc;
110 int h_samp(int c) const { return h_sampling.empty() ? 1 : h_sampling[c]; }
111 int v_samp(int c) const { return v_sampling.empty() ? 1 : v_sampling[c]; }
112 int max_h_sample() const {
113 auto it = std::max_element(h_sampling.begin(), h_sampling.end());
114 return it == h_sampling.end() ? 1 : *it;
116 int max_v_sample() const {
117 auto it = std::max_element(v_sampling.begin(), v_sampling.end());
118 return it == v_sampling.end() ? 1 : *it;
120 int comp_width(const TestImage& input, int c) const {
121 return DivCeil(input.xsize * h_samp(c), max_h_sample() * 8) * 8;
123 int comp_height(const TestImage& input, int c) const {
124 return DivCeil(input.ysize * v_samp(c), max_v_sample() * 8) * 8;
128 enum ColorQuantMode {
129 CQUANT_1PASS,
130 CQUANT_2PASS,
131 CQUANT_EXTERNAL,
132 CQUANT_REUSE,
135 struct ScanDecompressParams {
136 int max_scan_number;
137 int dither_mode;
138 ColorQuantMode color_quant_mode;
141 struct DecompressParams {
142 float size_factor = 1.0f;
143 size_t chunk_size = 65536;
144 size_t max_output_lines = 16;
145 JpegIOMode output_mode = PIXELS;
146 JpegliDataType data_type = JPEGLI_TYPE_UINT8;
147 JpegliEndianness endianness = JPEGLI_NATIVE_ENDIAN;
148 bool set_out_color_space = false;
149 int out_color_space = 0; // JCS_UNKNOWN
150 bool crop_output = false;
151 bool do_block_smoothing = false;
152 bool do_fancy_upsampling = true;
153 bool skip_scans = false;
154 int scale_num = 1;
155 int scale_denom = 1;
156 bool quantize_colors = false;
157 int desired_number_of_colors = 256;
158 std::vector<ScanDecompressParams> scan_params;
161 } // namespace jpegli
163 #endif // LIB_JPEGLI_TEST_PARAMS_H_