// 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.
for (constauto& encoding : encodings) { if (encoding.mode != QuantEncoding::kQuantModeLibrary ||
encoding.predefined != 0) {
all_default = false;
}
} // TODO(janwas): better bound return writer->WithMaxBits(512 * 1024, layer, aux_out, [&]() -> Status {
writer->Write(1, TO_JXL_BOOL(all_default)); if (!all_default) { for (size_t i = 0; i < encodings.size(); i++) {
JXL_RETURN_IF_ERROR(EncodeQuant(memory_manager, encodings[i], i,
DequantMatrices::required_size_x[i],
DequantMatrices::required_size_y[i],
writer, modular_frame_encoder));
}
} returntrue;
});
}
Status DequantMatricesEncodeDC(const DequantMatrices& matrices,
BitWriter* writer, LayerType layer,
AuxOut* aux_out) { bool all_default = true; constfloat* dc_quant = matrices.DCQuants(); for (size_t c = 0; c < 3; c++) { if (dc_quant[c] != kDCQuant[c]) {
all_default = false;
}
} return writer->WithMaxBits(
1 + sizeof(float) * kBitsPerByte * 3, layer, aux_out, [&]() -> Status {
writer->Write(1, TO_JXL_BOOL(all_default)); if (!all_default) { for (size_t c = 0; c < 3; c++) {
JXL_RETURN_IF_ERROR(F16Coder::Write(dc_quant[c] * 128.0f, writer));
}
} returntrue;
});
}
Status DequantMatricesSetCustomDC(JxlMemoryManager* memory_manager,
DequantMatrices* matrices, constfloat* dc) {
matrices->SetDCQuant(dc); // Roundtrip encode/decode DC to ensure same values as decoder.
BitWriter writer{memory_manager}; // TODO(eustas): should it be LayerType::Quant?
JXL_RETURN_IF_ERROR(
DequantMatricesEncodeDC(*matrices, &writer, LayerType::Header, nullptr));
writer.ZeroPadToByte();
BitReader br(writer.GetSpan()); // Called only in the encoder: should fail only for programmer errors.
JXL_RETURN_IF_ERROR(matrices->DecodeDC(&br));
JXL_RETURN_IF_ERROR(br.Close()); returntrue;
}
Status DequantMatricesScaleDC(JxlMemoryManager* memory_manager,
DequantMatrices* matrices, constfloat scale) { float dc[3]; for (size_t c = 0; c < 3; ++c) {
dc[c] = matrices->InvDCQuant(c) * (1.0f / scale);
}
JXL_RETURN_IF_ERROR(DequantMatricesSetCustomDC(memory_manager, matrices, dc)); returntrue;
}
Status DequantMatricesRoundtrip(JxlMemoryManager* memory_manager,
DequantMatrices* matrices) { // Do not pass modular en/decoder, as they only change entropy and not // values.
BitWriter writer{memory_manager}; // TODO(eustas): should it be LayerType::Quant?
JXL_RETURN_IF_ERROR(DequantMatricesEncode(memory_manager, *matrices, &writer,
LayerType::Header, nullptr));
writer.ZeroPadToByte();
BitReader br(writer.GetSpan()); // Called only in the encoder: should fail only for programmer errors.
JXL_RETURN_IF_ERROR(matrices->Decode(memory_manager, &br));
JXL_RETURN_IF_ERROR(br.Close()); returntrue;
}
Status DequantMatricesSetCustom(DequantMatrices* matrices, const std::vector<QuantEncoding>& encodings,
ModularFrameEncoder* encoder) {
JXL_ENSURE(encoder != nullptr);
JXL_ENSURE(encodings.size() == kNumQuantTables);
JxlMemoryManager* memory_manager = encoder->memory_manager();
matrices->SetEncodings(encodings); for (size_t i = 0; i < encodings.size(); i++) { if (encodings[i].mode == QuantEncodingInternal::kQuantModeRAW) {
JXL_RETURN_IF_ERROR(encoder->AddQuantTable(
DequantMatrices::required_size_x[i] * kBlockDim,
DequantMatrices::required_size_y[i] * kBlockDim, encodings[i], i));
}
}
JXL_RETURN_IF_ERROR(DequantMatricesRoundtrip(memory_manager, matrices)); returntrue;
}
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.