Repository navigation
Faster decoding. On one thread, lossy (9/7) HTJ2K images decode 24% faster than
with 0.29.1 on an Apple M1 Max and 10% faster on Zen 5 (batches of 768 x 512
RGB images; 16% for a 16384 x 16384 image on Zen 5), and their peak memory is
6-12% lower. The HT block decoder writes quad pairs that a MEL run of zeros
covers without decoding them, and the line-based inverse DWT advances only the
rows a new row can let advance and runs the four 9/7 vertical lifting steps of a
row pair in one pass with NEON, AVX2 and AVX-512. Region decoding skips what
lies outside the request: with a column window only the code-blocks and tiles
that meet it are decoded, tile rows above a row window are skipped, and a
reduced decode stops reading packets after the last resolution it needs. A
1024 x 1024 window of a 16384 x 16384 HTJ2K image takes 132 ms instead of
227 ms in one tile and 38 ms instead of 196 ms in 1024 x 1024 tiles; a 1/32
thumbnail takes 20 ms instead of 42 ms.
Also fixes an endless loop of the JPIP precinct index on DFS codestreams
(0.25.0 to 0.29.1) and an HT decoder that wrote into the codestream buffer, and
the RTP receiver now accepts Main Packets with an XTRAB extension, as RFC 9828
requires.
Encoded and decoded output are byte-identical to 0.29.1, except that with a
column window (set_col_range()) the pixels outside the window are now
indeterminate, as documented.
Changed
- Decoder, region decoding: each resolution level writes a zero row for every row
above the row window (set_row_range()) to keep its inverse DWT in step; it no
longer clears the row once its eight ring slots hold zeros. A 1024 x 1024
window 15000 rows down a 16384 x 16384 image took 18 ms more than one at the
top; it now takes 3 ms more. - Decoder, resolution reduction: when the progression runs through the
resolutions outermost (RPCL, RLCP, or LRCP of one layer, without POC), a
tile's packets are read only up to the last resolution decoded; the rest are
neither parsed nor given code-blocks. A 1/32 thumbnail of a 16384 x 16384
HTJ2K image (RPCL) takes 20 ms instead of 42 ms on one thread, 17 ms of it the
codestream copy, and a 1024 x 1024 window at 1/4 resolution 34 ms instead of
55 ms. The output is the same. - Decoder, region decoding: with a column window (
set_col_range()),
invoke_line_based_stream()andinvoke_line_based_stream_reuse()decode
only the code-blocks that meet the window, widened by the synthesis filter's
reach at each resolution, and with several tile columns only the tiles that
meet it. They decoded every code-block of the window's rows (and every tile
of each tile row) before. A 1024 x 1024 window of a 16384 x 16384 HTJ2K
image now takes 132 ms instead of 227 ms (one tile) and 80 ms instead of
196 ms (1024 x 1024 tiles) on one thread, the codestream copy included. The
pixels inside the window are the same as before; outside it they are
indeterminate, as documented.invoke_line_based()still decodes the full
width. - Decoder, region decoding with several tiles: tile rows that end above a row
window (set_row_range()) are no longer decoded, and with several tile
columns and a column window the per-tile-row accumulator is filled in the
window's columns only (it was a zeroed full-width buffer of every component,
about 200 MB for a 16384-wide tile row of 1024 rows). For the 1024 x 1024
tiles above, a 1024 x 1024 window takes 38 ms instead of 80 ms. - Encoder and transcoder, several quality layers: the packets of a layer no
longer visit the code-blocks of a precinct band that has no bytes in that
layer. A 116-byte codestream declaring 65535 layers made the transcoder
visit every code-block for each of 65535 empty packets per precinct (0.73 s;
more than 25 s under AddressSanitizer, a fuzzer timeout); it takes 0.17 s.
The output is byte-identical. - Decoder, line-based inverse DWT: after each row it fetches, the scheduler
looks only at the rows that row can let advance, instead of about twenty rows
once per lifting step; and on NEON builds the four 9/7 vertical lifting steps
of a row pair run in one pass over the columns. One thread, 768 x 512 RGB
HTJ2K images throughinvoke_line_based_stream(): 9/7 decodes are 8% faster
on an Apple M1 Max (10% for 512 x 512 images) and 4% faster on Zen 5, 5/3
decodes about 1% faster. The output is byte-identical. - Decoder, HT cleanup pass: two quads that one MEL run of zeros covers, in zero
context, code no other bits; the NEON and WebAssembly kernels now write them
as zeros without running the VLC, U-VLC and MagSgn decoding, and the AVX2
kernel's MagSgn step writes groups of insignificant quads directly. One
thread, 9/7 HTJ2K at about 4 bpp: 16% faster on an Apple M1 Max for
768 x 512 images and 13-15% for 4K to 16K images; WebAssembly 8-12% faster;
Zen 5 3% faster. 5/3 decodes change by less than 1%. The output is
byte-identical. - Decoder, HT cleanup pass on NEON: the MagSgn bits of a quad pair are
extracted with per-lane shifts instead of multiplies, and without branching on
the data. 5/3 decodes 1% faster on an Apple M1 Max. The output is
byte-identical. - Decoder,
invoke_line_based_stream()on one thread: the rows of a
component with an irreversible (float) transform are read where its inverse
DWT leaves them instead of being copied into a per-strip buffer first. 9/7
decodes are 1-1.6% faster on Zen 5, and their peak memory drops by the
buffer (a 7680 x 4320 RGB image: 50.5 MB -> 44.8 MB). The output is
byte-identical. - Decoder, line-based inverse DWT on x86-64: the four 9/7 vertical lifting
steps of a row pair run in one pass over the columns with AVX2 and AVX-512 as
well, as they already did on NEON. One thread on Zen 5: 9/7 decodes 2.4%
faster with AVX-512 and about 4% with AVX2 (x86-64-v3), 5% for a 16384 x
16384 image. The output is byte-identical.
Fixed
- RTP receiver (
open_htj2k_rtp_recvand the WebAssembly RTP module): a Main
Packet whose XTRAC field is not 0 was refused. RFC 9828 (section 8.4) requires
a receiver to accept it and ignore the XTRAB extension, XTRAC 4-byte words
after the 8-byte header; the receiver now skips XTRAB and reads the codestream
after it. (Senders still set XTRAC to 0, section 7.6.) - JPIP: a codestream whose COC marker refers to a DFS decomposition (ISO/IEC
15444-2) hung the precinct index in an endless loop: the index read the DFS
index byte0xffas 255 decomposition levels and counted the resolutions
with an 8-bit counter. A JPIP server indexing such a file, and a JPIP client
given such a main header by a server, never returned (102 bytes were
enough). The index now refuses DFS codestreams, which it never supported.
Affected 0.25.0 to 0.29.1. - Decoder: a decode limited to a column window (
set_col_range()with the
single-tile reuse path) read IDWT row buffers in columns outside the window
that nothing had written. The value only chose between two ways of computing
the same samples, so the output was right, but the read was of uninitialised
memory (MemorySanitizer reports it). The buffers are now zeroed the first time
a window leaves columns out. Full-width decodes are unchanged. - Decoder: decoding an HTJ2K codestream changed it. The HT block decoder
replaced the last two bytes of every code-block's cleanup segment in the
codestream buffer, which withinit_borrow()is the caller's: a second decode
of the same buffer failed, two decoders could not share one buffer, and a
read-only buffer (a read-only memory mapping) would fault. The decoder now
only reads the codestream; the output is unchanged. Part 1 codestreams were
not affected.