---
name: "libopenjp2"
section: "3"
platform: "linux"
package: "openjpeg2"
version: "2.5.4-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libopenjp2"
---

# libopenjp2(3)

a library for reading and writing JPEG2000 image files.

## NAME

libopenjp2 - a library for reading and writing JPEG2000 image files.

## SYNOPSIS

**#include \<openjpeg.h\>**

### CONVERSION FORMATS

**PGX: imagetopgx() / pgxtoimage()**

**PXM: imagetopnm() / pnmtoimage()**

**BMP: imagetobmp() / bmptoimage()**

**TIF: imagetotif() / tiftoimage()**

**RAW: imagetoraw() / rawtoimage()**

**TGA: imagetotga() / tgatoimage()**

**PNG: imagetopng() / pngtoimage()**

**YUV: imagetoyuv() / yuvtoimage() (MJ2)**

### READ

**opj\_set\_default\_decoder\_parameters(opj\_dparameters\_t \**params*);**

**opj\_dinfo\_t \*opj\_create\_decompress(OPJ\_CODEC\_FORMAT *format*);**

**opj\_event\_mgr\_t \*opj\_set\_event\_mgr(opj\_common\_ptr *info*, opj\_event\_mgr\_t \**event\_mgr*, void \**context*);**

**void opj\_setup\_decoder(opj\_dinfo\_t \**dinfo*, opj\_dparameters\_t \* *params*);**

**opj\_cio\_t \*opj\_cio\_open(opj\_common\_ptr *info*, unsigned char \**buf*, int *buf\_len*);**

**opj\_image\_t \*opj\_decode(opj\_dinfo\_t \**dinfo*, opj\_cio\_t \**cio*);**

**void opj\_cio\_close(opj\_cio\_t \**cio*);**

**void opj\_destroy\_decompress(opj\_dinfo\_t \**dinfo*);**

**void opj\_image\_destroy(opj\_image\_t \**image*);**

### WRITE

**void opj\_set\_default\_encoder\_parameters(opj\_cparameters\_t \**params*);**

/\* **opj\_image\_t \*FORMATtoimage(const char \**fname*, opj\_cparameters\_t \**params*);**

\*/\
 **opj\_cinfo\_t\* opj\_create\_compress(OPJ\_CODEC\_FORMAT *format*);**

**opj\_event\_mgr\_t \*opj\_set\_event\_mgr(opj\_common\_ptr *info*, opj\_event\_mgr\_t \**event\_mgr*, void \**context*);**

**void opj\_setup\_encoder(opj\_cinfo\_t \**cinfo*, opj\_cparameters\_t \**params*, opj\_image\_t \**image*);**

**opj\_cio\_t \*opj\_cio\_open(opj\_common\_ptr *cinfo*, *NULL*, *0*);**

**bool opj\_encode(opj\_cinfo\_t \**cinfo*, opj\_cio\_t \**cio*, opj\_image\_t \**image*, char \**index*);**

**void opj\_cio\_close(opj\_cio\_t \**cio*);**

**void opj\_destroy\_compress(opj\_cinfo\_t \**cinfo*);**

**void opj\_image\_destroy(opj\_image\_t \**image*);**

### GENERAL

**void opj\_image\_create(int *numcmpts*, opj\_image\_cmptparm\_t \**cmptparms*, OPJ\_COLOR\_SPACE *clrspc*);**

**int cio\_tell(opj\_cio\_t \**cio*);**

**void cio\_seek(opj\_cio\_t \**cio*, int *pos*);**

**opj\_image\_t \*opj\_decode\_with\_info(opj\_dinfo\_t \**dinfo*, opj\_cio\_t \**cio*, opj\_codestream\_info\_t \**cstr\_info*);**

**bool opj\_encode\_with\_info(opj\_cinfo\_t \**cinfo*, opj\_cio\_t \**cio*, opj\_image\_t \**image*, opj\_codestream\_info\_t \**cstr\_info*);**

**void opj\_destroy\_cstr\_info(opj\_codestream\_info\_t \**cstr\_info*);**

**const char \*opj\_version(*void*);**

## OPJ\_CODEC\_FORMAT

**CODEC\_J2K or CODEC\_JPT or CODEC\_JP2**

## OPJ\_COLOR\_SPACE

**CLRSPC\_UNKNOWN or CLRSPC\_UNSPECIFIED or CLRSPC\_SRGB or CLRSPC\_GRAY or CLRSPC\_SYCC**

## DECOMPRESSION PARAMETERS

typedef struct opj\_dparameters \
 {\
     /\*\
     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.\
     if != 0, then original dimension divided by 2^(reduce);\
     if == 0 or not used, image is decoded to the full resolution\
     \*/\
     **int** cp\_reduce;\
     /\*\
     Set the maximum number of quality layers to decode.\
     If there are less quality layers than the specified number, \
     all the quality layers are decoded.\
     if != 0, then only the first "layer" layers are decoded;\
     if == 0 or not used, all the quality layers are decoded\
     \*/\
     **int** cp\_layer;

    /\*command line encoder parameters (not used inside the library) \*/\
     /\* input file name \*/\
     **char** infile\[OPJ\_PATH\_LEN\];\
     /\* output file name \*/\
     **char** outfile\[OPJ\_PATH\_LEN\];\
     /\* input file format: see OPJ\_CODEC\_FORMAT \*/\
     **int** decod\_format;\
     /\* output file format \*/\
     **int** cod\_format;

    /\*JPWL decoding parameters \*/\
     /\* activates the JPWL correction capabilities \*/\
     **bool** jpwl\_correct;\
     /\* expected number of components \*/\
     **int** jpwl\_exp\_comps;\
     /\* maximum number of tiles \*/\
     **int** jpwl\_max\_tiles;

    /\*\
     Specify whether the decoding should be done on the entire \
     codestream, or be limited to the main header\
     Limiting the decoding to the main header makes it possible \
     to extract the characteristics of the codestream\
     if == NO\_LIMITATION, the entire codestream is decoded;\
     if == LIMIT\_TO\_MAIN\_HEADER, only the main header is decoded;\
     \*/\
     **OPJ\_LIMIT\_DECODING** cp\_limit\_decoding;\
 } opj\_dparameters\_t;

## COMPRESSION PARAMETERS

typedef struct opj\_cparameters \
 {\
     /\* size of tile: tile\_size\_on = false (not in argument) \
     or tile\_size\_on = true (in argument) \*/\
     **bool** tile\_size\_on;\
     /\* XTOsiz \*/\
     **int** cp\_tx0;\
     /\* YTOsiz \*/\
     **int** cp\_ty0;\
     /\* XTsiz \*/\
     **int** cp\_tdx;\
     /\* YTsiz \*/\
     **int** cp\_tdy;\
     /\* allocation by rate/distortion \*/\
     **int** cp\_disto\_alloc;\
     /\* allocation by fixed layer \*/\
     **int** cp\_fixed\_alloc;\
     /\* add fixed\_quality \*/\
     **int** cp\_fixed\_quality;\
     /\* fixed layer \*/\
     **int \***cp\_matrice;\
     /\* comment for coding \*/\
     **char \***cp\_comment;\
     /\* coding style \*/\
     **int** csty;\
     /\* progression order:\
        PROG\_UNKNOWN, LRCP(default), RLCP, RPCL, PCRL, CPRL \*/\
     **OPJ\_PROG\_ORDER** prog\_order;\
     /\* progression order changes \*/\
     **opj\_poc\_t** POC\[32\];\
     /\* number of progression order changes (POC), default: 0 \*/\
     **int** numpocs;\
     /\* number of layers \*/\
     **int** tcp\_numlayers;\
     /\* rates of layers \*/\
     **float** tcp\_rates\[100\];\
     /\* different psnr for successive layers \*/\
     **float** tcp\_distoratio\[100\];\
     /\* number of resolutions \*/\
     **int** numresolution;\
     /\* initial code block width, default: 64 \*/\
     **int** cblockw\_init;\
     /\* initial code block height, default: 64 \*/\
     **int** cblockh\_init;\
     /\* mode switch (cblk\_style) \*/\
     /\* 1 : use the irreversible DWT 9-7, \
         0 : use lossless compression (default) \*/\
     **int** irreversible;\
     /\* region of interest: affected component in \[0..3\], \
         \-1 means no ROI \*/\
     **int** roi\_compno;\
     /\* region of interest: upshift value \*/\
     **int** roi\_shift;\
     /\* number of precinct size specifications \*/\
     **int** res\_spec;\
     /\* initial precinct width \*/\
     **int** prcw\_init\[J2K\_MAXRLVLS\];\
     /\* initial precinct height \*/\
     **int** prch\_init\[J2K\_MAXRLVLS\];

    /\*command line encoder parameters (not used inside the library) \*/\
     /\* input file name \*/\
     **char** infile\[OPJ\_PATH\_LEN\];\
     /\* output file name \*/\
     **char** outfile\[OPJ\_PATH\_LEN\];\
     /\* DEPRECATED. Index generation is now handled with the\
         opj\_encode\_with\_info() function. Set to NULL \*/\
     **int** index\_on;\
     /\* DEPRECATED. Index generation is now handled with the\
         opj\_encode\_with\_info() function. Set to NULL \*/\
     **char** index\[OPJ\_PATH\_LEN\];\
     /\* subimage encoding: origin image offset in x direction \*/\
     **int** image\_offset\_x0;\
     /\* subimage encoding: origin image offset in y direction \*/\
     **int** image\_offset\_y0;\
     /\* subsampling value for dx \*/\
     **int** subsampling\_dx;\
     /\* subsampling value for dy \*/\
     **int** subsampling\_dy;\
     /\* input file format \*/\
     **int** decod\_format;\
     /\* output file format: see OPJ\_CODEC\_FORMAT \*/\
     **int** cod\_format;

    /\*JPWL encoding parameters \*/\
     /\* enables writing of EPC in MH, thus activating JPWL \*/\
     **bool** jpwl\_epc\_on;\
     /\* error protection method for MH (0,1,16,32,37-128) \*/\
     **int** jpwl\_hprot\_MH;\
     /\* tile number of header protection specification (\>=0) \*/\
     **int** jpwl\_hprot\_TPH\_tileno\[JPWL\_MAX\_NO\_TILESPECS\];\
     /\* error protection methods for TPHs (0,1,16,32,37-128) \*/\
     **int** jpwl\_hprot\_TPH\[JPWL\_MAX\_NO\_TILESPECS\];\
     /\* tile number of packet protection specification (\>=0) \*/\
     **int** jpwl\_pprot\_tileno\[JPWL\_MAX\_NO\_PACKSPECS\];\
     /\* packet number of packet protection specification (\>=0) \*/\
     **int** jpwl\_pprot\_packno\[JPWL\_MAX\_NO\_PACKSPECS\];\
     /\* error protection methods for packets (0,1,16,32,37-128) \*/\
     **int** jpwl\_pprot\[JPWL\_MAX\_NO\_PACKSPECS\];\
     /\* enables writing of ESD, (0=no/1/2 bytes) \*/\
     **int** jpwl\_sens\_size;\
     /\* sensitivity addressing size (0=auto/2/4 bytes) \*/\
     **int** jpwl\_sens\_addr;\
     /\* sensitivity range (0-3) \*/\
     **int** jpwl\_sens\_range;\
     /\* sensitivity method for MH (-1=no,0-7) \*/\
     **int** jpwl\_sens\_MH;\
     /\* tile number of sensitivity specification (\>=0) \*/\
     **int** jpwl\_sens\_TPH\_tileno\[JPWL\_MAX\_NO\_TILESPECS\];\
     /\* sensitivity methods for TPHs (-1=no,0-7) \*/\
     **int** jpwl\_sens\_TPH\[JPWL\_MAX\_NO\_TILESPECS\];

    /\* Digital Cinema compliance: OFF-not compliant, \
        CINEMA2K\_24, CINEMA2K\_48, CINEMA4K\_24 \*/\
     **OPJ\_CINEMA\_MODE** cp\_cinema;\
     /\* Maximum rate for each component. \
         If == 0, component size limitation is not considered \*/\
     **int** max\_comp\_size;\
     /\* Profile name\*/\
     **OPJ\_RSIZ\_CAPABILITIES** cp\_rsiz;\
     /\* Tile part generation\*/\
     **char** tp\_on;\
     /\* Flag for Tile part generation\*/\
     **char** tp\_flag;\
     /\* MCT (multiple component transform) \*/\
     **char** tcp\_mct;\
 } opj\_cparameters\_t;

## AUTHORS

Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium

Copyright (c) 2002-2014, Professor Benoit Macq

Copyright (c) 2001-2003, David Janssens

Copyright (c) 2002-2003, Yannick Verschueren

Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe

Copyright (c) 2005, Herve Drolon, FreeImage Team

Copyright (c) 2006-2007, Parvatha Elangovan

## SEE ALSO

[**image\_to\_j2k**(1)](/image_to_j2k/1.md) [**j2k\_to\_image**(1)](/j2k_to_image/1.md) [**j2k\_dump**(1)](/j2k_dump/1.md)

**JPWL\_image\_to\_j2k**(1) **JPWL\_j2k\_to\_image**(1)

**extract\_j2k\_from\_mj2**(1) **wrap\_j2k\_in\_mj2**(1)  **frames\_to\_mj2**(1) **mj2\_to\_frames**(1)
