1 // Copyright (c) the JPEG XL Project Authors. All rights reserved.
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_ENCODE_INTERNAL_H_
7 #define LIB_JPEGLI_ENCODE_INTERNAL_H_
11 #include "lib/jpegli/bit_writer.h"
12 #include "lib/jpegli/common.h"
13 #include "lib/jpegli/common_internal.h"
14 #include "lib/jpegli/encode.h"
18 constexpr unsigned char kICCSignature
[12] = {
19 0x49, 0x43, 0x43, 0x5F, 0x50, 0x52, 0x4F, 0x46, 0x49, 0x4C, 0x45, 0x00};
20 constexpr int kICCMarker
= JPEG_APP0
+ 2;
22 constexpr int kDefaultProgressiveLevel
= 0;
24 typedef int16_t coeff_t
;
26 struct HuffmanCodeTable
{
35 Token(int c
, int s
, int b
) : context(c
), symbol(s
), bits(b
) {}
48 struct ScanTokenInfo
{
56 size_t num_future_nonzeros
;
58 size_t restart_interval
;
60 size_t MCU_rows_in_scan
;
67 struct jpeg_comp_master
{
68 jpegli::RowBuffer
<float> input_buffer
[jpegli::kMaxComponents
];
69 jpegli::RowBuffer
<float>* smooth_input
[jpegli::kMaxComponents
];
70 jpegli::RowBuffer
<float>* raw_data
[jpegli::kMaxComponents
];
73 uint8_t cicp_transfer_function
;
75 bool use_adaptive_quantization
;
76 int progressive_level
;
79 size_t blocks_per_iMCU_row
;
80 jpegli::ScanTokenInfo
* scan_token_info
;
81 JpegliDataType data_type
;
82 JpegliEndianness endianness
;
83 void (*input_method
)(const uint8_t* row_in
, size_t len
,
84 float* row_out
[jpegli::kMaxComponents
]);
85 void (*color_transform
)(float* row
[jpegli::kMaxComponents
], size_t len
);
86 void (*downsample_method
[jpegli::kMaxComponents
])(
87 float* rows_in
[MAX_SAMP_FACTOR
], size_t len
, float* row_out
);
88 float* quant_mul
[jpegli::kMaxComponents
];
89 float* zero_bias_offset
[jpegli::kMaxComponents
];
90 float* zero_bias_mul
[jpegli::kMaxComponents
];
91 int h_factor
[jpegli::kMaxComponents
];
92 int v_factor
[jpegli::kMaxComponents
];
93 // Array of Huffman tables that will be encoded in one or more DHT segments.
94 // In progressive mode we compute all Huffman tables that will be used in any
95 // of the scans, thus we can have more than 4 tables here.
96 JHUFF_TBL
* huffman_tables
;
97 size_t num_huffman_tables
;
98 // Array of num_huffman_tables slot ids, where the ith element is the slot id
99 // of the ith Huffman table, as it appears in the DHT segment. The range of
100 // the slot ids is 0..3 for DC and 16..19 for AC Huffman codes.
101 uint8_t* slot_id_map
;
102 // Maps context ids to an index in the huffman_tables array. Each component in
103 // each scan has a DC and AC context id, which are defined as follows:
104 // - DC context id is the component index (relative to cinfo->comp_info) of
105 // the scan component
106 // - AC context ids start at 4 and are increased for each component of each
107 // scan that have AC components (i.e. Se > 0)
108 uint8_t* context_map
;
110 // Array of cinfo->num_scans context ids, where the ith element is the context
111 // id of the first AC component of the ith scan.
112 uint8_t* ac_ctx_offset
;
113 // Array of num_huffman tables derived coding tables.
114 jpegli::HuffmanCodeTable
* coding_tables
;
116 jpegli::RowBuffer
<float> fuzzy_erosion_tmp
;
117 jpegli::RowBuffer
<float> pre_erosion
;
118 jpegli::RowBuffer
<float> quant_field
;
119 jvirt_barray_ptr
* coeff_buffers
;
120 size_t next_input_row
;
121 size_t next_iMCU_row
;
122 size_t next_dht_index
;
123 size_t last_restart_interval
;
124 JCOEF last_dc_coeff
[MAX_COMPS_IN_SCAN
];
125 jpegli::JpegBitWriter bw
;
128 jpegli::TokenArray
* token_arrays
;
129 size_t cur_token_array
;
130 jpegli::Token
* next_token
;
132 size_t total_num_tokens
;
133 jpegli::RefToken
* next_refinement_token
;
134 uint8_t* next_refinement_bit
;
136 float psnr_tolerance
;
141 #endif // LIB_JPEGLI_ENCODE_INTERNAL_H_