/src/libjxl/lib/jpegli/test_params.h
Line | Count | Source (jump to first uncovered line) |
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_JPEGLI_TEST_PARAMS_H_ |
7 | | #define LIB_JPEGLI_TEST_PARAMS_H_ |
8 | | |
9 | | #include <stddef.h> |
10 | | #include <stdint.h> |
11 | | |
12 | | #include <algorithm> |
13 | | #include <vector> |
14 | | |
15 | | #include "lib/jpegli/types.h" |
16 | | |
17 | | namespace jpegli { |
18 | | |
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; |
24 | | } |
25 | | |
26 | | #define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0])) |
27 | | |
28 | | static constexpr int kLastScan = 0xffff; |
29 | | |
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); |
36 | | |
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); |
43 | | |
44 | | enum JpegIOMode { |
45 | | PIXELS, |
46 | | RAW_DATA, |
47 | | COEFFICIENTS, |
48 | | }; |
49 | | |
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(); |
59 | | }; |
60 | | |
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 | 0 | void AllocatePixels() { |
72 | 0 | pixels.resize(ysize * xsize * components * |
73 | 0 | jpegli_bytes_per_sample(data_type)); |
74 | 0 | } |
75 | 0 | void Clear() { |
76 | 0 | pixels.clear(); |
77 | 0 | raw_data.clear(); |
78 | 0 | coeffs.clear(); |
79 | 0 | } |
80 | | }; |
81 | | |
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; |
109 | | |
110 | 0 | int h_samp(int c) const { return h_sampling.empty() ? 1 : h_sampling[c]; } |
111 | 0 | int v_samp(int c) const { return v_sampling.empty() ? 1 : v_sampling[c]; } |
112 | 0 | int max_h_sample() const { |
113 | 0 | auto it = std::max_element(h_sampling.begin(), h_sampling.end()); |
114 | 0 | return it == h_sampling.end() ? 1 : *it; |
115 | 0 | } |
116 | 0 | int max_v_sample() const { |
117 | 0 | auto it = std::max_element(v_sampling.begin(), v_sampling.end()); |
118 | 0 | return it == v_sampling.end() ? 1 : *it; |
119 | 0 | } |
120 | 0 | int comp_width(const TestImage& input, int c) const { |
121 | 0 | return DivCeil(input.xsize * h_samp(c), max_h_sample() * 8) * 8; |
122 | 0 | } |
123 | 0 | int comp_height(const TestImage& input, int c) const { |
124 | 0 | return DivCeil(input.ysize * v_samp(c), max_v_sample() * 8) * 8; |
125 | 0 | } |
126 | | }; |
127 | | |
128 | | enum ColorQuantMode { |
129 | | CQUANT_1PASS, |
130 | | CQUANT_2PASS, |
131 | | CQUANT_EXTERNAL, |
132 | | CQUANT_REUSE, |
133 | | }; |
134 | | |
135 | | struct ScanDecompressParams { |
136 | | int max_scan_number; |
137 | | int dither_mode; |
138 | | ColorQuantMode color_quant_mode; |
139 | | }; |
140 | | |
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; |
159 | | }; |
160 | | |
161 | | } // namespace jpegli |
162 | | |
163 | | #endif // LIB_JPEGLI_TEST_PARAMS_H_ |