// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
int send_table[NUM_QUANT_TBLS] = {}; if (write_all_tables) { for (int i = 0; i < NUM_QUANT_TBLS; ++i) { if (cinfo->quant_tbl_ptrs[i]) send_table[i] = 1;
}
} else { for (int c = 0; c < cinfo->num_components; ++c) {
send_table[cinfo->comp_info[c].quant_tbl_no] = 1;
}
}
bool is_baseline = true; for (int i = 0; i < NUM_QUANT_TBLS; ++i) { if (!send_table[i]) continue;
JQUANT_TBL* quant_table = cinfo->quant_tbl_ptrs[i]; if (quant_table == nullptr) {
JPEGLI_ERROR("Missing quant table %d", i);
} int precision = 0; for (UINT16 q : quant_table->quantval) { if (q > 255) {
precision = 1;
is_baseline = false;
}
} if (quant_table->sent_table) { continue;
}
data[pos++] = (precision << 4) + i; for (size_t j = 0; j < DCTSIZE2; ++j) { int val_idx = kJPEGNaturalOrder[j]; int val = quant_table->quantval[val_idx]; if (val == 0) {
JPEGLI_ERROR("Invalid quantval 0.");
} if (precision) {
data[pos++] = val >> 8;
}
data[pos++] = val & 0xFFu;
}
quant_table->sent_table = TRUE;
} if (pos > 4) {
data[2] = (pos - 2) >> 8u;
data[3] = (pos - 2) & 0xFFu;
WriteOutput(cinfo, data, pos);
} return is_baseline;
}
void WriteScanHeader(j_compress_ptr cinfo, int scan_index) {
jpeg_comp_master* m = cinfo->master; const jpeg_scan_info* scan_info = &cinfo->scan_info[scan_index];
cinfo->restart_interval = m->scan_token_info[scan_index].restart_interval; if (cinfo->restart_interval != m->last_restart_interval) {
EncodeDRI(cinfo);
m->last_restart_interval = cinfo->restart_interval;
}
size_t num_dht = 0; if (scan_index == 0) { // For the first scan we emit all DC and at most 4 AC Huffman codes. for (size_t i = 0, num_ac = 0; i < m->num_huffman_tables; ++i) { if (m->slot_id_map[i] >= 16 && num_ac++ >= 4) break;
++num_dht;
}
} elseif (scan_info->Ss > 0) { // For multi-scan sequential and progressive DC scans we have already // emitted all Huffman codes that we need before the first scan. For // progressive AC scans we only need at most one new Huffman code. if (m->context_map[m->ac_ctx_offset[scan_index]] == m->next_dht_index) {
num_dht = 1;
}
} if (num_dht > 0) {
EncodeDHT(cinfo, m->next_dht_index, num_dht);
m->next_dht_index += num_dht;
}
EncodeSOS(cinfo, scan_index);
}
void WriteBlock(const int32_t* JXL_RESTRICT symbols, const int32_t* JXL_RESTRICT extra_bits, constint num_nonzeros, constbool emit_eob, const HuffmanCodeTable* JXL_RESTRICT dc_code, const HuffmanCodeTable* JXL_RESTRICT ac_code,
JpegBitWriter* JXL_RESTRICT bw) { int symbol = symbols[0];
WriteBits(bw, dc_code->depth[symbol], dc_code->code[symbol] | extra_bits[0]); for (int i = 1; i < num_nonzeros; ++i) {
symbol = symbols[i]; if (symbol > 255) {
WriteBits(bw, ac_code->depth[0xf0], ac_code->code[0xf0]);
symbol -= 256; if (symbol > 255) {
WriteBits(bw, ac_code->depth[0xf0], ac_code->code[0xf0]);
symbol -= 256; if (symbol > 255) {
WriteBits(bw, ac_code->depth[0xf0], ac_code->code[0xf0]);
symbol -= 256;
}
}
}
WriteBits(bw, ac_code->depth[symbol],
ac_code->code[symbol] | extra_bits[i]);
} if (emit_eob) {
WriteBits(bw, ac_code->depth[0], ac_code->code[0]);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.