Coverage Report

Created: 2025-12-03 07:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjxl/lib/jpegli/encode_internal.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_JPEGLI_ENCODE_INTERNAL_H_
7
#define LIB_JPEGLI_ENCODE_INTERNAL_H_
8
9
#include <cstddef>
10
#include <cstdint>
11
12
#include "lib/jpegli/bit_writer.h"
13
#include "lib/jpegli/common.h"
14
#include "lib/jpegli/common_internal.h"
15
#include "lib/jpegli/types.h"
16
17
namespace jpegli {
18
19
constexpr unsigned char kICCSignature[12] = {
20
    0x49, 0x43, 0x43, 0x5F, 0x50, 0x52, 0x4F, 0x46, 0x49, 0x4C, 0x45, 0x00};
21
constexpr int kICCMarker = JPEG_APP0 + 2;
22
23
constexpr int kDefaultProgressiveLevel = 0;
24
25
typedef int16_t coeff_t;
26
27
struct HuffmanCodeTable {
28
  int depth[256];
29
  int code[256];
30
};
31
32
struct Token {
33
  uint8_t context;
34
  uint8_t symbol;
35
  uint16_t bits;
36
0
  Token(int c, int s, int b) : context(c), symbol(s), bits(b) {}
37
};
38
39
struct TokenArray {
40
  Token* tokens;
41
  size_t num_tokens;
42
};
43
44
struct RefToken {
45
  uint8_t symbol;
46
  uint8_t refbits;
47
};
48
49
struct ScanTokenInfo {
50
  RefToken* tokens;
51
  size_t num_tokens;
52
  uint8_t* refbits;
53
  uint16_t* eobruns;
54
  size_t* restarts;
55
  size_t num_restarts;
56
  size_t num_nonzeros;
57
  size_t num_future_nonzeros;
58
  size_t token_offset;
59
  size_t restart_interval;
60
  size_t MCUs_per_row;
61
  size_t MCU_rows_in_scan;
62
  size_t blocks_in_MCU;
63
  size_t num_blocks;
64
};
65
66
}  // namespace jpegli
67
68
struct jpeg_comp_master {
69
  jpegli::RowBuffer<float> input_buffer[jpegli::kMaxComponents];
70
  jpegli::RowBuffer<float>* smooth_input[jpegli::kMaxComponents];
71
  jpegli::RowBuffer<float>* raw_data[jpegli::kMaxComponents];
72
  bool force_baseline;
73
  bool xyb_mode;
74
  uint8_t cicp_transfer_function;
75
  bool use_std_tables;
76
  bool use_adaptive_quantization;
77
  int progressive_level;
78
  size_t xsize_blocks;
79
  size_t ysize_blocks;
80
  size_t blocks_per_iMCU_row;
81
  jpegli::ScanTokenInfo* scan_token_info;
82
  JpegliDataType data_type;
83
  JpegliEndianness endianness;
84
  void (*input_method)(const uint8_t* row_in, size_t len,
85
                       float* row_out[jpegli::kMaxComponents]);
86
  void (*color_transform)(float* row[jpegli::kMaxComponents], size_t len);
87
  void (*downsample_method[jpegli::kMaxComponents])(
88
      float* rows_in[MAX_SAMP_FACTOR], size_t len, float* row_out);
89
  float* quant_mul[jpegli::kMaxComponents];
90
  float* zero_bias_offset[jpegli::kMaxComponents];
91
  float* zero_bias_mul[jpegli::kMaxComponents];
92
  int h_factor[jpegli::kMaxComponents];
93
  int v_factor[jpegli::kMaxComponents];
94
  // Array of Huffman tables that will be encoded in one or more DHT segments.
95
  // In progressive mode we compute all Huffman tables that will be used in any
96
  // of the scans, thus we can have more than 4 tables here.
97
  JHUFF_TBL* huffman_tables;
98
  size_t num_huffman_tables;
99
  // Array of num_huffman_tables slot ids, where the ith element is the slot id
100
  // of the ith Huffman table, as it appears in the DHT segment. The range of
101
  // the slot ids is 0..3 for DC and 16..19 for AC Huffman codes.
102
  uint8_t* slot_id_map;
103
  // Maps context ids to an index in the huffman_tables array. Each component in
104
  // each scan has a DC and AC context id, which are defined as follows:
105
  //   - DC context id is the component index (relative to cinfo->comp_info) of
106
  //     the scan component
107
  //   - AC context ids start at 4 and are increased for each component of each
108
  //     scan that have AC components (i.e. Se > 0)
109
  uint8_t* context_map;
110
  size_t num_contexts;
111
  // Array of cinfo->num_scans context ids, where the ith element is the context
112
  // id of the first AC component of the ith scan.
113
  uint8_t* ac_ctx_offset;
114
  // Array of num_huffman tables derived coding tables.
115
  jpegli::HuffmanCodeTable* coding_tables;
116
  float* diff_buffer;
117
  jpegli::RowBuffer<float> fuzzy_erosion_tmp;
118
  jpegli::RowBuffer<float> pre_erosion;
119
  jpegli::RowBuffer<float> quant_field;
120
  jvirt_barray_ptr* coeff_buffers;
121
  size_t next_input_row;
122
  size_t next_iMCU_row;
123
  size_t next_dht_index;
124
  size_t last_restart_interval;
125
  JCOEF last_dc_coeff[MAX_COMPS_IN_SCAN];
126
  jpegli::JpegBitWriter bw;
127
  float* dct_buffer;
128
  int32_t* block_tmp;
129
  jpegli::TokenArray* token_arrays;
130
  size_t cur_token_array;
131
  jpegli::Token* next_token;
132
  size_t num_tokens;
133
  size_t total_num_tokens;
134
  jpegli::RefToken* next_refinement_token;
135
  uint8_t* next_refinement_bit;
136
  float psnr_target;
137
  float psnr_tolerance;
138
  float min_distance;
139
  float max_distance;
140
};
141
142
#endif  // LIB_JPEGLI_ENCODE_INTERNAL_H_