What is a J2K File?
A J2K file contains the same raw JPEG 2000 codestream that other tools name .j2c or .jpc; the .j2k extension is a filename convention for that one format, not a separate codec or container. Its contents focus on compressed image data, not container metadata.
How J2K Files work
.j2k is one of several names for a raw JPEG 2000 codestream. OpenJPEG’s tools treat .j2k, .j2c, and .jpc as the same input format, and the IANA registration for the codestream media type image/j2c lists j2k as a file extension. Decoding begins from the codestream’s own headers, the SOC marker and the SIZ marker segment, not from a container signature or brand, and the marker segments that follow record the coding style, quantization, and progression order. Inside the stream, an image is coded as one or more rectangular tiles, and each tile’s compressed data is divided into packets, each belonging to one quality layer, resolution level, component, and precinct; the order of a tile’s packets is what lets a decoder stop early or decode at reduced resolution. A pipeline that needs container metadata can wrap the same codestream in a JP2 file, which stores it in a Contiguous Codestream box after the JPEG 2000 Signature, File Type, and JP2 Header boxes.
Key facts
- 1How should a pipeline detect a
.j2kfile? By content. A raw codestream begins with the bytesFF 4F FF 51, while a JP2 file begins with the 12-byte signature box00 00 00 0C 6A 50 20 20 0D 0A 87 0A. OpenJPEG’sopj_decompressshows the safer order of trust: it reads the leading bytes, and if they disagree with the extension it prints a warning that the extension is incorrect and decodes according to the bytes. Input whose leading bytes match no signature it knows is rejected as an unknown input format; the exception is a file named.jpt, which it accepts by extension without that check. - 2What decides whether a tool writes a
.j2kcodestream or a JP2 file? Usually the output file name. OpenJPEG’sopj_compressdocuments.j2kand.jp2as its output extensions, and Pillow chooses the form from the extension unlessno_jp2is set, which forces a raw codestream. Renaming an existing file converts nothing: the bytes remain a codestream or a JP2 file whatever the suffix says. - 3Is a
.j2kfile lossy? The name does not say. The core syntax allows both the 5-3 reversible and the 9-7 irreversible wavelet filter, and both OpenJPEG’sopj_compressand Pillow use the reversible filter unless told otherwise. A reversible filter is still no proof of lossless content: compression ratios or quality targets given to the encoder can make quality layers lossy, and whether the complete file is still lossless depends on the target for the last layer. Theopj_compressmanual describes its example-r 20,10,1as “compress 20x, then 10x, then lossless”: lossless when every layer is decoded, lossy when only the earlier ones are. T.800 also notes that a reversible transform may be used in truncated codestreams to provide lossy compression. - 4What does the progression order change? The order in which each tile’s packets appear, and therefore what a partial read of that tile yields. T.800 defines five orders, written LRCP, RLCP, RPCL, PCRL, and CPRL, signaled in the COD marker segment and changeable with POC marker segments. Layer-first order (LRCP) lets quality improve as data arrives; resolution-first order (RLCP) delivers low-resolution versions of all components first. Because the order applies within a tile, it does not guarantee an early view of the whole image in a multi-tile file: T.800 permits but does not require an encoder to interleave tile-parts from different tiles, and without interleaving a sequential read reaches a tile’s data only after all the data of the tiles stored before it. T.800 also lets a tile’s data be truncated by discarding trailing bytes, provided the tile length marker segment parameters reflect the truncation, so the chosen order determines what a shortened tile still contains.
When J2K Files matter
Format detection should inspect the file contents because extensions alone do not reliably distinguish JPEG 2000 variants. Selecting a container-only parser may cause a valid J2K asset to fail.
Sources
- Rec. ITU-T T.800 (06/2019) | ISO/IEC 15444-1:2019: JPEG 2000 core coding system (the freely available edition used for this entry; superseded by the paid 07/2024 edition)
- IANA media type registration: image/j2c (extensions j2c and j2k)
- OpenJPEG source: opj_decompress.c (extension table and signature detection)
- OpenJPEG opj_compress manual page (output extensions, transform and progression options)
- Pillow handbook: JPEG 2000 reading and saving options