fprintf(stdout, "## grk_decompress\n");
fprintf(stdout, "\n");
fprintf(stdout, "This program decompresses a JPEG 2000 image and stores it in another image\n");
fprintf(stdout, "format.\n");
fprintf(stdout, "\n");
fprintf(stdout, "Supported input formats: `JP2` and `J2K\\J2C`\n");
fprintf(stdout, "Supported input image extensions are `.jp2` and `.j2k\\.j2c`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Supported output formats are `JPEG`, `BMP`, `PNM`, `PGX`, `PNG`, `RAW` and\n");
fprintf(stdout, "`TIFF`\n");
fprintf(stdout, "Valid output image extensions are `jpg`, `.jpeg`, `.bmp`, `.pgm`, `.pgx`,\n");
fprintf(stdout, "`.pnm`, `.ppm`, `.pam`, `.png`, `.raw`, `.rawl`, `.tif` and `.tiff`\n");
fprintf(stdout, "\n");
fprintf(stdout, "* For `PNG` the library must have `libpng` available.\n");
fprintf(stdout, "* For `TIF\\\\TIFF` the library must have `libtiff` available.\n");
fprintf(stdout, "* For `JPG\\\\JPEG` the library must have a `libjpeg` variant available.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### Limitations\n");
fprintf(stdout, "\n");
fprintf(stdout, "* Grok supports up to and including 16 bit sample precision for decompression.\n");
fprintf(stdout, "This is a subset of the ISO standard, which allows up to 38 bit precision.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### stdout\n");
fprintf(stdout, "\n");
fprintf(stdout, "The decompresser can write output to `stdout` for the following formats:\n");
fprintf(stdout, "`BMP`,`PNG`, `JPG`, `PNM`, `RAW` and `RAWL`.  To enable writing to `stdout`,\n");
fprintf(stdout, "please ensure that the `-o` parameter is **not** present in the command line,\n");
fprintf(stdout, "and that the `-out_fmt` parameter is set to one of the supported formats listed\n");
fprintf(stdout, "above. Note: the verbose flag `-v` will be ignored in this mode, as verbose\n");
fprintf(stdout, "output would corrupt the output file.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### Embedded ICC Profile\n");
fprintf(stdout, "\n");
fprintf(stdout, "If there is an embedded ICC profile in the input file, then the profile will be\n");
fprintf(stdout, "stored in the output file for `TIF\\TIFF`, `JPG`, `BMP` and `PNG` formats. For\n");
fprintf(stdout, "other formats, the profile will be applied to the decompressed image before it\n");
fprintf(stdout, "is stored.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### IPTC (JP2 only)\n");
fprintf(stdout, "\n");
fprintf(stdout, "If a compressed input contains `IPTC` metadata, this metadata will be stored to\n");
fprintf(stdout, "the output file if that output file is in `TIF\\TIFF` format.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### XMP (JP2 only)\n");
fprintf(stdout, "\n");
fprintf(stdout, "If a compressed input contains `XMP` metadata, this metadata will be stored to\n");
fprintf(stdout, "the output file if that output file is in `TIF\\\\TIFF` or `PNG` format.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### Exif (JP2 only)\n");
fprintf(stdout, "\n");
fprintf(stdout, "To transfer Exif and all other meta-data tags, use the command line argument\n");
fprintf(stdout, "`-V` described below. To transfer the tags, Grok uses the\n");
fprintf(stdout, "[ExifTool](https://exiftool.org/) Perl module. ExifTool must be installed for\n");
fprintf(stdout, "this command line argument to work properly. Note: transferring Exif tags may\n");
fprintf(stdout, "add a few hundred ms to the decompress time, depending on the system.\n");
fprintf(stdout, "\n");
fprintf(stdout, "**Important note on command line argument notation below**: the outer square\n");
fprintf(stdout, "braces appear for clarity only,and **should not** be included in the actual\n");
fprintf(stdout, "command line argument. Square braces appearing inside the outer braces\n");
fprintf(stdout, "**should** be included.\n");
fprintf(stdout, "\n");
fprintf(stdout, "\n");
fprintf(stdout, "####   `-h,  -help`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Print a help message and exit.\n");
fprintf(stdout, "\n");
fprintf(stdout, "####   `-version`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Print library version and exit.\n");
fprintf(stdout, "\n");
fprintf(stdout, "####  `-v, -verbose`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Output information and warnings about decoding to console (errors are always\n");
fprintf(stdout, "output). Console is silent by default.\n");
fprintf(stdout, "\n");
fprintf(stdout, "####  `-i, -in_file [file]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Input file. Either this argument or the `-img_dir` argument described below is\n");
fprintf(stdout, "required. Valid input image extensions are J2K, JP2 and JPC. When using this\n");
fprintf(stdout, "option output file must be specified using -o.\n");
fprintf(stdout, "\n");
fprintf(stdout, "####  `-o, -out_file [file]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Output file. Required when using `-i` option. See above for supported file\n");
fprintf(stdout, "types. If a `PGX` filename is given, there will be as many output files as there\n");
fprintf(stdout, "are components: an index starting from 0 will then be appended to the output\n");
fprintf(stdout, "filename, just before the `pgx` extension. If a `PGM` filename is given and\n");
fprintf(stdout, "there is more than one component, then only the first component will be written\n");
fprintf(stdout, "to the file.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-y, -img_dir [directory path]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Path to the folder where the compressed images are stored. Either this argument\n");
fprintf(stdout, "or the `-i` argument described above is required. When image files are in the\n");
fprintf(stdout, "same directory as the executable, this can be indicated by a dot `.` argument.\n");
fprintf(stdout, "When using this option, the output format must be specified using `-out_fmt`.\n");
fprintf(stdout, "Output images are saved in the same folder.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-a, -out_dir [output directory]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Output directory where compressed files are stored. Only relevant when the\n");
fprintf(stdout, "`-img_dir` flag is set. Default: same directory as specified by `-img_dir`.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-O, -out_fmt [format]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Output format used to decompress the code streams. Required when `-img_dir`\n");
fprintf(stdout, "option is used. See above for supported formats.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-r, -reduce [reduce factor]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Reduce factor. Set the number of highest resolution levels to be discarded. The\n");
fprintf(stdout, "image resolution is effectively divided by 2 to the power of the number of\n");
fprintf(stdout, "discarded levels. The reduce factor is limited by the smallest total number of\n");
fprintf(stdout, "decomposition levels among tiles.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-l, -layer [layer number]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Layer number. Set the maximum number of quality layers to decode. If there are\n");
fprintf(stdout, "fewer quality layers than the specified number, all quality layers will be\n");
fprintf(stdout, "decoded.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-d, -region [x0,y0,x1,y1]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Decompress a region of the image. If `(X,Y)` is a location in the image, then it\n");
fprintf(stdout, "will only be decoded\n");
fprintf(stdout, "if `x0 <= X < x1` and `y0 <= Y < y1`. By default, the entire image is decoded.\n");
fprintf(stdout, "\n");
fprintf(stdout, "There are two ways of specifying the decompress region:\n");
fprintf(stdout, "\n");
fprintf(stdout, "1. pixel coordinates relative to image origin - region is specified in 32 bit\n");
fprintf(stdout, "integers.\n");
fprintf(stdout, "\n");
fprintf(stdout, "Example: if image coordinates on canvas are `(50,50,1050,1050)` and region is\n");
fprintf(stdout, "specified as `-d 100,100,200,200`,\n");
fprintf(stdout, "then a region with canvas coordinates `(150,150,250,250)` is decompressed\n");
fprintf(stdout, "\n");
fprintf(stdout, "2. pixel coordinates relative to image origin and scaled as floating point to\n");
fprintf(stdout, "unit square `[0,0,1,1]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "The above example would be specified as `-d 0.1,0.1,0.2,0.2`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Note: there is one ambiguous case, namely `-d 0,0,1,1`, which could be\n");
fprintf(stdout, "interpreted as either scaled or un-scaled.\n");
fprintf(stdout, "We treat this case as a **scaled** pixel region.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-m, -random_access [random access flags]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Toggle support for random access code stream markers if present : PLT,TLM or\n");
fprintf(stdout, "PLM;\n");
fprintf(stdout, "\n");
fprintf(stdout, "The random access flags value passed in is an or'd combination of the following\n");
fprintf(stdout, "flags\n");
fprintf(stdout, "\n");
fprintf(stdout, "```\n");
fprintf(stdout, "1   use PLT marker if present\n");
fprintf(stdout, "2   use TLM marker if present\n");
fprintf(stdout, "4   use PLM marker if present\n");
fprintf(stdout, "```\n");
fprintf(stdout, "example: `-m 0` would disable all three markers.\n");
fprintf(stdout, "\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-c, -compression [compression value]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Compress output image data. Currently, this flag is only applicable when output\n");
fprintf(stdout, "format is set\n");
fprintf(stdout, "to `TIF`. Possible values are {`NONE`, `LZW`,`JPEG`, `PACKBITS`.\n");
fprintf(stdout, "`ZIP`,`LZMA`,`ZSTD`,`WEBP`}.\n");
fprintf(stdout, "Default value is `NONE`.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-L, -compression_level [compression level]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "\"Quality\" of compression. Currently only implemented for `PNG` format.\n");
fprintf(stdout, "For `PNG`, compression level ranges from 0 (no compression) up to 9.\n");
fprintf(stdout, "Grok default value is 3.\n");
fprintf(stdout, "\n");
fprintf(stdout, "Note: PNG is always lossless, so using a different level will not affect the\n");
fprintf(stdout, "image quality. It only changes\n");
fprintf(stdout, "the speed vs file size tradeoff.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-t, -tile_index [tile index]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Only decode tile with specified index. Index follows the JPEG2000 convention\n");
fprintf(stdout, "from top-left to bottom-right. By default all tiles are decoded.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-p, -precision [component 0 precision[C|S],component 1\n");
fprintf(stdout, "precision[C|S],...]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Force precision (bit depth) of components. There must be at least one value\n");
fprintf(stdout, "present, but there is no limit on the number of values.\n");
fprintf(stdout, "The last values are ignored if too many values. If there are fewer values than\n");
fprintf(stdout, "components, the last value is used for the remaining components. If `C` is\n");
fprintf(stdout, "specified (default), values are clipped. If `S` is specified, values are scaled.\n");
fprintf(stdout, "Specifying a `0` value indicates use of the original bit depth.\n");
fprintf(stdout, "\n");
fprintf(stdout, "Example:\n");
fprintf(stdout, "\n");
fprintf(stdout, "-p 8C,8C,8c\n");
fprintf(stdout, "\n");
fprintf(stdout, "Clip all components of a 16 bit RGB image to 8 bits.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-f, -force_rgb`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Force output image color space to `RGB`. For `TIF/TIFF` or `PNG` output formats,\n");
fprintf(stdout, "the ICC profile will be applied in this case - default behaviour is to stored\n");
fprintf(stdout, "the profile in the output file, if supported.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-u, -upsample`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Sub-sampled components will be upsampled to image size.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-s, -split_pnm`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Split output components into different files when writing to `PNM`.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-X, -xml [output file name]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Store XML metadata to file, if it exists in compressed file. File name will be\n");
fprintf(stdout, "set to `output file name + \".xml\"`\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-V, -transfer_exif_tags`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Transfer all Exif tags to output file. Note: [ExifTool](https://exiftool.org/)\n");
fprintf(stdout, "must be installed for this command line\n");
fprintf(stdout, "argument to work correctly.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-W, -logfile [output file name]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Log to file. File name will be set to `output file name`\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-H, -num_threads [number of threads]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Number of threads used for T1 compression. Default is total number of logical\n");
fprintf(stdout, "cores.\n");
fprintf(stdout, "\n");
fprintf(stdout, "####  `-e, -repetitions [number of repetitions]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Number of repetitions, for either a single image, or a folder of images. Default\n");
fprintf(stdout, "is 1. 0 signifies unlimited repetitions.\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-g, -plugin_path [plugin path]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "Path to Grok plugin, which handles T1 decompression.\n");
fprintf(stdout, "Default search path for plugin is in same folder as `grk_decompress` binary\n");
fprintf(stdout, "\n");
fprintf(stdout, "#### `-G, -device_id [device ID]`\n");
fprintf(stdout, "\n");
fprintf(stdout, "For Grok plugin running on multi-GPU system. Specifies which single GPU\n");
fprintf(stdout, "accelerator to run codec on.\n");
fprintf(stdout, "If the flag is set to -1, all GPUs are used in round-robin scheduling. If set to\n");
fprintf(stdout, "-2, then plugin is disabled and\n");
fprintf(stdout, "compression is done on the CPU. Default value: 0.\n");
