01. grk_decompress - GrokImageCompression/grok GitHub Wiki

1. grk_decompress

grk_decompress

This program decompresses a JPEG 2000 image and stores it in another image format.

Supported input formats: JP2, J2K\J2C\JPC, JPH, JHC and MJ2 (Motion JPEG 2000) The codec will determine the file input format, regardless of file tag.

Supported output formats are JPEG, BMP, PNM, PGX, PNG, RAW and TIFF Valid output image extensions are jpg, .jpeg, .bmp, .pgm, .pgx, .pnm, .ppm, .pam, .png, .raw, .rawl, .tif and .tiff

• For PNG the library must have libpng available. • For TIF\\TIFF the library must have libtiff available. • For JPG\\JPEG the library must have a libjpeg variant available.

Limitations

• Grok supports up to and including 16 bit sample precision for decompression. This is a subset of the ISO standard, which allows up to 38 bit precision.

stdout

The decompresser can write output to stdout for the following formats: BMP,PNG, JPG, PNM, RAW and RAWL. To enable writing to stdout, please ensure that the -o parameter is not present in the command line, and that the --out-fmt parameter is set to one of the supported formats listed above.

Embedded ICC Profile

If there is an embedded ICC profile in the input file, then the profile will be stored in the output file for TIF\TIFF, JPG, BMP and PNG formats. For other formats, the profile will be applied to the decompressed image before it is stored.

IPTC (JP2 only)

If a compressed input contains IPTC metadata, this metadata will be stored to the output file if that output file is in TIF\TIFF format.

XMP (JP2\JPH only)

If a compressed input contains XMP metadata, this metadata will be stored to the output file if that output file is in TIF\\TIFF or PNG format.

EXIF (JP2\JPH only)

If a compressed input contains EXIF metadata, this metadata will be automatically stored to the output file if that output file is in JPEG or PNG format.

Important note on command line argument notation below: the outer square braces appear for clarity only,and should not be included in the actual command line argument. Square braces appearing inside the outer braces should be included.

-h

Print a brief help message and exit.

--help

Print a detailed help message and exit.

--version

Print library version and exit.

-i, --in-file [file]

Input file. Either this argument or the --batch-src argument described below is required. Valid input image extensions are J2K, JP2, JPC, JPH, JHC, MJ2 and MJP2. When using this option output file must be specified using -o.

Grok can also read directly from cloud storage using /vsis3/, /vsiaz/, /vsigs/, /vsiadls/ paths or https:// URLs. See Cloud Storage for details.

MJ2 Multi-Frame Decompress: When the input file is an MJ2 (Motion JPEG 2000) container, all frames are automatically extracted and saved as individually numbered output files. For example, if -o frame.png is specified, output files will be named frame_000.png, frame_001.png, frame_002.png, etc. See MJ2 (Motion JPEG 2000) for full details.

-o, --out-file [file]

Output file. Required when using -i option. See above for supported file types. If a PGX filename is given, there will be as many output files as there are components: an index starting from 0 will then be appended to the output filename, just before the pgx extension. If a PGM filename is given and there is more than one component, then only the first component will be written to the file. When decompressing an MJ2 file, the output file name serves as a template for numbered per-frame files (see -i above).

-y, --batch-src [directory path]

Path to the folder where the compressed images are stored. Either this argument or the -i argument described above is required. When image files are in the same directory as the executable, this can be indicated by a dot . argument. When using this option, the output format must be specified using --out-fmt. Output images are saved in the same folder.

-a, --out-dir [output directory]

Output directory where compressed files are stored. Only relevant when the --batch-src flag is set. Default: same directory as specified by --batch-src.

-O, --out-fmt [format]

Output format used to decompress the code streams. Required when --batch-src option is used. See above for supported formats.

-r, --reduce [reduce factor]

Reduce factor. Set the number of highest resolution levels to be discarded. The image resolution is effectively divided by 2 to the power of the number of discarded levels. The reduce factor is limited by the smallest total number of decomposition levels among tiles.

-l, --layers [number of layers]

Number of layers. Set the maximum number of quality layers to decode. If there are fewer quality layers than the specified number, all quality layers will be decoded.

-d, --region [x0,y0,x1,y1]

Decompress region. If (X,Y) is a location in the image, then it will only be decoded if x0 <= X < x1 and y0 <= Y < y1. By default, the entire image is decoded.

There are two ways of specifying the decompress region:

  1. pixel coordinates relative to image origin - region is specified in 32 bit integers.

Example: if image coordinates on canvas are (50,50,1050,1050) and region is specified as -d 100,100,200,200, then a region with canvas coordinates (150,150,250,250) is decompressed

  1. pixel coordinates relative to image origin and scaled as double point to unit square [0,0,1,1]

The above example would be specified as -d 0.1,0.1,0.2,0.2

Note: there is one ambiguous case, namely -d 0,0,1,1, which could be interpreted as either scaled or un-scaled. We treat this case as a scaled pixel region.

-m, --random-access [random access flags]

Disable support for random access code stream markers if present: PLT, TLM or PLM.

The random access flags value passed in is an OR'd combination of the following flags:

1   Disable PLT marker if present
2   Disable TLM marker if present
4   Disable PLM marker if present

Example: -m 0 would disable all three markers.

-c, --compression [compression value]

Compress output image data. Currently, this flag is only applicable when output format is set to TIF. Possible values are {NONE, LZW,JPEG, PACKBITS. ZIP,LZMA,ZSTD,WEBP}. Default value is NONE.

-L, --compression-level [compression level]

"Quality" of compression. Currently only implemented for PNG format. For PNG, compression level ranges from 0 (no compression) up to 9. Grok default value is 3.

Note: PNG is always lossless, so using a different level will not affect the image quality. It only changes the speed vs file size tradeoff.

-t, --tile-index [tile index]

Only decode tile with specified index. Index follows the JPEG2000 convention from top-left to bottom-right. By default all tiles are decoded.

-p, --precision [component 0 precision[C|S],component 1 precision[C|S],...]

Force precision (bit depth) of components. There must be at least one value present, but there is no limit on the number of values. The last values are ignored if too many values. If there are fewer values than components, the last value is used for the remaining components. If C is specified (default), values are clipped. If S is specified, values are scaled. Specifying a 0 value indicates use of the original bit depth.

Example:

 -p 8C,8C,8C

Clip all components of a 16 bit RGB image to 8 bits.

-f, --force-rgb

Force output image color space to RGB. For TIF/TIFF or PNG output formats, the ICC profile will be applied in this case - default behaviour is to stored the profile in the output file, if supported.

-u, --upsample

Sub-sampled components will be upsampled to image size.

-s, --split-pnm

Split output components into different files when writing to PNM.

-X, --xml [output file name]

Store XML metadata to file, if it exists in compressed file. File name will be set to output file name + ".xml"

-W, --log-file [output file name]

Log to file. File name will be set to output file name

-H, --num-threads [number of threads]

Number of threads used for T1 decompression. Default is total number of logical cores.

-e, --repetitions [number of repetitions]

Number of repetitions, for either a single image, or a folder of images. Default value is 1. Unlimited repetitions are specified by a value of 0.

-z, --duration [duration]

Duration in seconds for a batch decompress job. grk_decompress will exit when duration has been reached.

-g, --plugin-path [plugin path]

Path to Grok plugin, which handles T1 decompression. Default search path for plugin is in same folder as grk_decompress binary.

-G, --device-id [device ID]

For Grok plugin running on multi-GPU system. Specifies which single GPU accelerator to run codec on. If the flag is set to -1, all GPUs are used in round-robin scheduling. If set to -2, then plugin is disabled and decompression is done on the CPU. Default value: 0.

-k, --kernel-build [kernel build options]

Kernel build options for GPU plugin.