openhtj2kenc
April 29, 2026 · View on GitHub
Part 15 (HTJ2K) compliant encoder. Produces either a raw codestream
(.j2c, .jhc) or an HTJ2K JPH file (.jph). Accepts PGM, PPM,
PGX, and TIFF (with libtiff) inputs. The default streaming path
handles all four formats — PGX with subsampled component sets
(4:2:2, 4:2:0) and basic TIFF (8/16-bit, RGB or grayscale,
single-strip or strip-compressed). Tiled TIFFs require -batch.
Full runtime help: open_htj2k_enc -h.
Synopsis
open_htj2k_enc -i <input-image(s)> -o <output> [options...]
Multiple input files can be passed as a comma-separated list. For example, to encode separate YCbCr component files:
open_htj2k_enc -i inputY.pgx,inputCb.pgx,inputCr.pgx -o output
-o takes the base name; the extension decides the container:
.j2c / .jhc for raw HTJ2K codestream, .jph for the JPH file
format.
Options
Tile and image structure
Stiles=Size- Tile size in
{height,width}format. Default is equal to the image size.
- Tile size in
Sorigin=Size- Offset from the reference grid origin to the image area. Default is
{0,0}.
- Offset from the reference grid origin to the image area. Default is
Stile_origin=Size- Offset from the reference grid origin to the first tile. Default is
{0,0}.
- Offset from the reference grid origin to the first tile. Default is
DWT and codeblock structure
Clevels=Int- Number of DWT decomposition levels. Valid range: 0–32. Default is 5.
Creversible=yes|noyesfor lossless mode,nofor lossy mode. Default is no.
Cblk=Size- Code-block size. Default is {64,64}.
Cprecincts=Size- Precinct size. Must be a power of two.
Cycc=yes|noyesto apply RGB→YCbCr color space conversion. Default is yes.
Corder=<LRCP|RLCP|RPCL|PCRL|CPRL>- Progression order. Default is LRCP.
Cuse_sop=yes|noyesto insert SOP (Start Of Packet) marker segments. Default is no.
Cuse_eph=yes|noyesto insert EPH (End of Packet Header) markers. Default is no.
Quantization and quality
Qstep=Float- Base step size for quantization. Valid range:
0.0 < Qstep <= 2.0.
- Base step size for quantization. Valid range:
Qguard=Int- Number of guard bits. Valid range: 0–8. Default is 1.
Qfactor=Int- Quality factor for lossy compression. Valid range: 0–100 (100 = best quality).
- When specified,
Qstepis ignored andCyccis set toyes.
JPH and component layout
-jph_color_space RGB|YCC- Declare the color space of the input components. Use
YCCif the inputs are already in YCbCr.
- Declare the color space of the input components. Use
Runtime
-num_threads Int- Number of threads.
0(default) uses all available hardware threads.
- Number of threads.
-batch- Use the batch (full-image) encode path. Loads the entire image into memory before encoding. The default path is line-based (streaming).
Examples
# Lossless encode, default DWT / codeblock settings
open_htj2k_enc -i input.ppm -o out.j2c Creversible=yes
# Lossy encode at quality 90, write to JPH file format
open_htj2k_enc -i input.ppm -o out.jph Qfactor=90
# Encode YCbCr components into a JPH file with explicit color space
open_htj2k_enc -i Y.pgx,Cb.pgx,Cr.pgx -o out.jph -jph_color_space YCC
# Lossless encode with 6 DWT levels and RPCL progression
open_htj2k_enc -i input.ppm -o out.j2c Creversible=yes Clevels=6 Corder=RPCL