Repository navigation
v0.21.0
Minor release: OpenHTJ2K now encodes JPEG 2000 Part 1 as well as HTJ2K.
Cmodes=0 on the command line, or cod_params::codeblock_style = 0
through the API, codes every code-block with the Part 1 EBCOT/MQ coder
in its default mode, so the codestream is readable by any JPEG 2000
decoder, and lossless output is the same size as OpenJPEG's. Part 1
decoding is about 30% faster. Lossy precision is fixed on both sides:
the decoder rounds every output sample to the nearest LSB, so lossy
decodes change from earlier releases by up to 1 LSB at 8 and 12 bits and
up to 8 LSB at 16 bits (lossless output is byte-identical); the encoder
keeps every input bit above 13 bits; and Part 1 and HT code-blocks that
carry the same quantization indices now decode identically. Codestreams
with more than 16 components, or with out-of-order COC markers, no
longer crash the decoder. The API is unchanged apart from the new
accepted value codeblock_style = 0.
Added
Encoder
- ISO/IEC 15444-1 (Part 1) block coding.
Cmodes=0on the command line, or
cod_params::codeblock_style = 0through the API, codes every code-block
with the EBCOT/MQ coder of Part 1 instead of the HT coder, so the codestream
can be read by any JPEG 2000 decoder: Rsiz carries no HT flag and no CAP
marker is written. The coder runs in the default mode with one codeword
segment per code-block and one quality layer; the mode switches BYPASS,
RESET, RESTART, CAUSAL, ERTERM and SEGMARK are rejected for now, and.jph
output still requires HT. Lossless output is the same size as OpenJPEG's
(within 0.02% on kodim23) and about 9% smaller than the HT coder's, and a
lossy stream carries exactly the quantisation indices of the HT stream made
with the same Qfactor. The passes and the MQ coder are new code
(block_encoding.cpp,mq_encoder.hpp) on the packed stripe-column state
the Part 1 decoder uses, and the 9-bit zero-coding context table is now
shared by both. New round-trip tests cover lossless, lossy, odd sizes,
multi-precinct RPCL output and the.jphrefusal.
Performance
Decoder
- Part 1 (EBCOT) code-blocks decode about 30% faster: 28-38% fewer cycles
on four Part 1 conformance files and on 3840×2160 RGB lossless, lossy and
BYPASS codestreams (Ryzen 9 9950X, one thread, native, x86-64-v3 and
generic builds). The coding passes keep each 4-sample stripe column's
significance, sign, refinement and visited flags in one 32-bit word,
the MQ decoder is inlined into the passes, and the reconstruction
mid-point is written into each sample as it is decoded, so Part 1
decoding no longer uses a per-sample state array. Output is
byte-identical.
Fixed
Encoder
- Lossy encoding of samples above 13 bits truncated the input: each sample
was right-shifted by (bit depth - 13) in integer arithmetic before the
forward transform, so a 16-bit image lost its three low bits before coding
(up to 7 LSB of error, MSE about 19 on a fine-step round trip even with the
decoder fix below). The DC offset is now subtracted in the input domain and
the 2^(13 - bit depth) scale is applied in float, which is exact, in both
the streaming and the whole-image encoder, with and without the colour
transform. A 16-bit fine-step round trip now has MSE 0.005 (grey) and 0.1
(RGB through the ICT); codestreams for 8- to 13-bit input are byte-identical
to before, and encode time is unchanged (within noise at 8 and 16 bits,
Ryzen 9 9950X, one thread). New 16-bit RGB round-trip tests
(tests/data/rgb16_full_range.ppm) cover the colour-transform path.
Decoder
- Lossy output was rounded wrongly. The float sample was truncated toward
zero to the 13-bit fractional grid before the shift to the output bit
depth, so samples below mid-grey came out 1 LSB too bright on part of the
image (2.2% of all samples at 8 bits, 44% at 12 bits), and above 13 bits
the output kept only 13 bits of precision (up to 8 LSB of error on 16-bit
images). Every finalize path (line-based, streaming, planar uint8/uint16
and the fused colour-transform kernels on every ISA) now rounds
v * 2^-ds half up in one step, the fixed-point convention
(x + 2^(ds-1)) >> ds extended to every sign of ds, which also retires the
whole-row scalar fall-back the fused kernels took above 13 bits. Against
an independent decoder's float reference the MSE drops from 0.0197 to
0.0027 (8-bit, Qfactor 90), 0.44 to 0.0006 (12-bit) and 20.7 to 0.013
(16-bit). Lossy decodes change from earlier releases by at most 1 LSB
at 8 and 12 bits and by up to 8 LSB at 16 bits; lossless output is
byte-identical. New fine-step round-trip tests pin the 12-bit and 16-bit
results. Native decode time is unchanged (within noise on 8-, 12- and
16-bit 4K streams, Ryzen 9 9950X, one thread); the WASM SIMD build decodes
8-bit 4K 3% faster and 16-bit 4K 31-33% faster, since its fused kernel no
longer falls back to scalar code above 13 bits. - Lossy (9/7) Part 1 code-blocks were dequantized through an integer
fixed-point pipeline that rounded every subband sample to the 13-bit
fractional grid and discarded quantization-index bits below bit 16 whenever
M_b exceeded 15, while HT code-blocks were dequantized with one float
multiply. The same quantization indices therefore decoded to different
images depending on the block coder: by up to 1 LSB at 8-bit depth, and at
16-bit depth by up to 16 LSB on our own Qfactor 90 output and 39 LSB on a
fine-step codestream from another encoder, measured against an independent
decoder. Part 1 code-blocks without an ROI shift now use the same float
multiply as HT code-blocks in the scalar, AVX2, AVX-512 and NEON builds, so
a Part 1 and an HT codestream carrying the same indices decode to
byte-identical images. Decoding of codestreams with an RGN marker is
unchanged. - Codestreams with more than 16 components crashed or exhausted memory in
the line-based decoder (the row-callback path the command-line decoder
uses, and the planar paths), a regression since 0.13.0. Two per-component
tables in the strip driver were fixed 16-entry stack arrays indexed by
the component count, so from the 17th component on the strip row count
and row stride came from uninitialised stack memory; on the 257-component
conformance filep0_13.j2kthis allocated more than 90 GB before the
kernel killed the process. The tables are now sized by the component
count. - Main-header COC markers are matched by their component index instead of
being assumed to come one per component in ascending order. The loop
that computes the minimum DWT level count read past the end of the COC
list when the last COC was not for the last component (a crash on
p0_13.j2kandds0_ht_13_b11.j2k, #483), and out-of-order COCs were
skipped when computing both that minimum and the maximum safereduce.
Both files are now decoded by the test suite and checked against the
conformance references for their first four components.