// 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.
// Tries to generalize zig-zag order to non-square blocks. Surprisingly, in // square block frequency along the (i + j == const) diagonals is roughly the // same. For historical reasons, consecutive diagonals are traversed // in alternating directions - so called "zig-zag" (or "snake") order. template <bool is_lut> staticvoid CoeffOrderAndLut(AcStrategy acs, coeff_order_t* out) {
size_t cx = acs.covered_blocks_x();
size_t cy = acs.covered_blocks_y();
CoefficientLayout(&cy, &cx);
// CoefficientLayout ensures cx >= cy. // We compute the zigzag order for a cx x cx block, then discard all the // lines that are not multiple of the ratio between cx and cy.
size_t xs = cx / cy;
size_t xsm = xs - 1;
size_t xss = CeilLog2Nonzero(xs); // First half of the block
size_t cur = cx * cy; for (size_t i = 0; i < cx * kBlockDim; i++) { for (size_t j = 0; j <= i; j++) {
size_t x = j;
size_t y = i - j; if (i % 2) std::swap(x, y); if ((y & xsm) != 0) continue;
y >>= xss;
size_t val = 0; if (x < cx && y < cy) {
val = y * cx + x;
} else {
val = cur++;
} if (is_lut) {
out[y * cx * kBlockDim + x] = val;
} else {
out[val] = y * cx * kBlockDim + x;
}
}
} // Second half for (size_t ip = cx * kBlockDim - 1; ip > 0; ip--) {
size_t i = ip - 1; for (size_t j = 0; j <= i; j++) {
size_t x = cx * kBlockDim - 1 - (i - j);
size_t y = cx * kBlockDim - 1 - j; if (i % 2) std::swap(x, y); if ((y & xsm) != 0) continue;
y >>= xss;
size_t val = cur++; if (is_lut) {
out[y * cx * kBlockDim + x] = val;
} else {
out[val] = y * cx * kBlockDim + x;
}
}
}
}
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.