OpenJPEG: openjpeg.c File Reference

OpenJPEG 2.5.0

Functions
openjpeg.c File Reference
`#include "opj_includes.h"`

## Functions
OPJ_BOOL OPJ_CALLCONV | opj_set_info_handler (opj_codec_t *p_codec, opj_msg_callback p_callback, void *p_user_data)
| Set the info handler use by openjpeg.
OPJ_BOOL OPJ_CALLCONV | opj_set_warning_handler (opj_codec_t *p_codec, opj_msg_callback p_callback, void *p_user_data)
| Set the warning handler use by openjpeg.
OPJ_BOOL OPJ_CALLCONV | opj_set_error_handler (opj_codec_t *p_codec, opj_msg_callback p_callback, void *p_user_data)
| Set the error handler use by openjpeg.
static OPJ_SIZE_T | opj_read_from_file (void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data)
static OPJ_UINT64 | opj_get_data_length_from_file (void *p_user_data)
static OPJ_SIZE_T | opj_write_from_file (void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data)
static OPJ_OFF_T | opj_skip_from_file (OPJ_OFF_T p_nb_bytes, void *p_user_data)
static OPJ_BOOL | opj_seek_from_file (OPJ_OFF_T p_nb_bytes, void *p_user_data)
static void | opj_close_from_file (void *p_user_data)
const char *OPJ_CALLCONV | opj_version (void)
opj_codec_t *OPJ_CALLCONV | opj_create_decompress (OPJ_CODEC_FORMAT p_format)
| Creates a J2K/JP2 decompression structure.
void OPJ_CALLCONV | opj_set_default_decoder_parameters (opj_dparameters_t *parameters)
| Set decoding parameters to default values.
OPJ_BOOL OPJ_CALLCONV | opj_codec_set_threads (opj_codec_t *p_codec, int num_threads)
| Allocates worker threads for the compressor/decompressor.
OPJ_BOOL OPJ_CALLCONV | opj_setup_decoder (opj_codec_t *p_codec, opj_dparameters_t *parameters)
| Setup the decoder with decompression parameters provided by the user and with the message handler provided by the user.
OPJ_API OPJ_BOOL OPJ_CALLCONV | opj_decoder_set_strict_mode (opj_codec_t *p_codec, OPJ_BOOL strict)
| Set strict decoding parameter for this decoder.
OPJ_BOOL OPJ_CALLCONV | opj_read_header (opj_stream_t *p_stream, opj_codec_t *p_codec, opj_image_t **p_image)
| Decodes an image header.
OPJ_BOOL OPJ_CALLCONV | opj_set_decoded_components (opj_codec_t *p_codec, OPJ_UINT32 numcomps, const OPJ_UINT32 *comps_indices, OPJ_BOOL apply_color_transforms)
| Restrict the number of components to decode.
OPJ_BOOL OPJ_CALLCONV | opj_decode (opj_codec_t *p_codec, opj_stream_t *p_stream, opj_image_t *p_image)
| Decode an image from a JPEG-2000 codestream.
OPJ_BOOL OPJ_CALLCONV | opj_set_decode_area (opj_codec_t *p_codec, opj_image_t *p_image, OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, OPJ_INT32 p_end_x, OPJ_INT32 p_end_y)
| Sets the given area to be decoded.
OPJ_BOOL OPJ_CALLCONV | opj_read_tile_header (opj_codec_t *p_codec, opj_stream_t *p_stream, OPJ_UINT32 *p_tile_index, OPJ_UINT32 *p_data_size, OPJ_INT32 *p_tile_x0, OPJ_INT32 *p_tile_y0, OPJ_INT32 *p_tile_x1, OPJ_INT32 *p_tile_y1, OPJ_UINT32 *p_nb_comps, OPJ_BOOL *p_should_go_on)
| Reads a tile header.
OPJ_BOOL OPJ_CALLCONV | opj_decode_tile_data (opj_codec_t *p_codec, OPJ_UINT32 p_tile_index, OPJ_BYTE *p_data, OPJ_UINT32 p_data_size, opj_stream_t *p_stream)
| Reads a tile data.
OPJ_BOOL OPJ_CALLCONV | opj_get_decoded_tile (opj_codec_t *p_codec, opj_stream_t *p_stream, opj_image_t *p_image, OPJ_UINT32 tile_index)
| Get the decoded tile from the codec.
OPJ_BOOL OPJ_CALLCONV | opj_set_decoded_resolution_factor (opj_codec_t *p_codec, OPJ_UINT32 res_factor)
| Set the resolution factor of the decoded image.
opj_codec_t *OPJ_CALLCONV | opj_create_compress (OPJ_CODEC_FORMAT p_format)
| Creates a J2K/JP2 compression structure.
void OPJ_CALLCONV | opj_set_default_encoder_parameters (opj_cparameters_t *parameters)
| Set encoding parameters to default values, that means :
OPJ_BOOL OPJ_CALLCONV | opj_setup_encoder (opj_codec_t *p_codec, opj_cparameters_t *parameters, opj_image_t *p_image)
| Setup the encoder parameters using the current image and using user parameters.
OPJ_BOOL OPJ_CALLCONV | opj_encoder_set_extra_options (opj_codec_t *p_codec, const char *const *options)
| Specify extra options for the encoder.
OPJ_BOOL OPJ_CALLCONV | opj_start_compress (opj_codec_t *p_codec, opj_image_t *p_image, opj_stream_t *p_stream)
| Start to compress the current image.
OPJ_BOOL OPJ_CALLCONV | opj_encode (opj_codec_t *p_info, opj_stream_t *p_stream)
| Encode an image into a JPEG-2000 codestream.
OPJ_BOOL OPJ_CALLCONV | opj_end_compress (opj_codec_t *p_codec, opj_stream_t *p_stream)
| End to compress the current image.
OPJ_BOOL OPJ_CALLCONV | opj_end_decompress (opj_codec_t *p_codec, opj_stream_t *p_stream)
| Read after the codestream if necessary.
OPJ_BOOL OPJ_CALLCONV | opj_set_MCT (opj_cparameters_t *parameters, OPJ_FLOAT32 *pEncodingMatrix, OPJ_INT32 *p_dc_shift, OPJ_UINT32 pNbComp)
| Sets the MCT matrix to use.
OPJ_BOOL OPJ_CALLCONV | opj_write_tile (opj_codec_t *p_codec, OPJ_UINT32 p_tile_index, OPJ_BYTE *p_data, OPJ_UINT32 p_data_size, opj_stream_t *p_stream)
| Writes a tile with the given data.
void OPJ_CALLCONV | opj_destroy_codec (opj_codec_t *p_codec)
| Destroy a decompressor handle.
void OPJ_CALLCONV | opj_dump_codec (opj_codec_t *p_codec, OPJ_INT32 info_flag, FILE *output_stream)
| Dump the codec information into the output stream.
opj_codestream_info_v2_t *OPJ_CALLCONV | opj_get_cstr_info (opj_codec_t *p_codec)
| Get the codestream information from the codec.
void OPJ_CALLCONV | opj_destroy_cstr_info (opj_codestream_info_v2_t **cstr_info)
| Destroy Codestream information after compression or decompression.
opj_codestream_index_t *OPJ_CALLCONV | opj_get_cstr_index (opj_codec_t *p_codec)
| Get the codestream index from the codec.
void OPJ_CALLCONV | opj_destroy_cstr_index (opj_codestream_index_t **p_cstr_index)
opj_stream_t *OPJ_CALLCONV | opj_stream_create_default_file_stream (const char *fname, OPJ_BOOL p_is_read_stream)
| Create a stream from a file identified with its filename with default parameters (helper function)
opj_stream_t *OPJ_CALLCONV | opj_stream_create_file_stream (const char *fname, OPJ_SIZE_T p_size, OPJ_BOOL p_is_read_stream)
| Create a stream from a file identified with its filename with a specific buffer size.
void *OPJ_CALLCONV | opj_image_data_alloc (OPJ_SIZE_T size)
| Allocator for opj_image_t->comps[].data To be paired with opj_image_data_free.
void OPJ_CALLCONV | opj_image_data_free (void *ptr)
| Destructor for opj_image_t->comps[].data To be paired with opj_image_data_alloc.

## Function Documentation

## ◆ opj_close_from_file()

static void opj_close_from_file | ( | void * | p_user_data | ) |
| static

Referenced by opj_stream_create_file_stream().

## ◆ opj_codec_set_threads()

OPJ_BOOL OPJ_CALLCONV opj_codec_set_threads | ( | opj_codec_t * | p_codec,
|  | int | num_threads
| ) |  |

Allocates worker threads for the compressor/decompressor.

By default, only the main thread is used. If this function is not used, but the OPJ_NUM_THREADS environment variable is set, its value will be used to initialize the number of threads. The value can be either an integer number, or "ALL_CPUS". If OPJ_NUM_THREADS is set and this function is called, this function will override the behaviour of the environment variable.

This function must be called after opj_setup_decoder() and before opj_read_header() for the decoding side, or after opj_setup_encoder() and before opj_start_compress() for the encoding side.

Parameters

  p_codec | decompressor or compressor handler
  num_threads | number of threads.

Returns
  OPJ_TRUE if the function is successful.

References opj_codec_private::m_codec, OPJ_FALSE, and opj_codec_private::opj_set_threads.

## ◆ opj_create_compress()

opj_codec_t *OPJ_CALLCONV opj_create_compress | ( | OPJ_CODEC_FORMAT | format | ) |

Creates a J2K/JP2 compression structure.

Parameters

  format | Coder to select

Returns
  Returns a handle to a compressor if successful, returns NULL otherwise

References opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_compression, opj_codec_private::m_event_mgr, opj_calloc(), OPJ_CODEC_J2K, OPJ_CODEC_JP2, OPJ_CODEC_JPT, OPJ_CODEC_UNKNOWN, OPJ_FALSE, opj_free(), opj_j2k_create_compress(), opj_j2k_destroy(), opj_j2k_encode(), opj_j2k_encoder_set_extra_options(), opj_j2k_end_compress(), opj_j2k_set_threads(), opj_j2k_setup_encoder(), opj_j2k_start_compress(), opj_j2k_write_tile(), opj_jp2_create(), opj_jp2_destroy(), opj_jp2_encode(), opj_jp2_encoder_set_extra_options(), opj_jp2_end_compress(), opj_jp2_set_threads(), opj_jp2_setup_encoder(), opj_jp2_start_compress(), opj_jp2_write_tile(), opj_set_default_event_handler(), and opj_codec_private::opj_set_threads.

## ◆ opj_create_decompress()

opj_codec_t *OPJ_CALLCONV opj_create_decompress | ( | OPJ_CODEC_FORMAT | format | ) |

Creates a J2K/JP2 decompression structure.

Parameters

  format | Decoder to select

Returns
  Returns a handle to a decompressor if successful, returns NULL otherwise

References opj_codec_private::is_decompressor, j2k_dump(), j2k_get_cstr_index(), j2k_get_cstr_info(), jp2_dump(), jp2_get_cstr_index(), jp2_get_cstr_info(), opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_decompression, opj_codec_private::m_event_mgr, opj_calloc(), OPJ_CODEC_J2K, OPJ_CODEC_JP2, OPJ_CODEC_JPT, OPJ_CODEC_UNKNOWN, opj_codec_private::opj_dump_codec, opj_free(), opj_codec_private::opj_get_codec_index, opj_codec_private::opj_get_codec_info, opj_j2k_create_decompress(), opj_j2k_decode(), opj_j2k_decode_tile(), opj_j2k_decoder_set_strict_mode(), opj_j2k_destroy(), opj_j2k_end_decompress(), opj_j2k_get_tile(), opj_j2k_read_header(), opj_j2k_read_tile_header(), opj_j2k_set_decode_area(), opj_j2k_set_decoded_components(), opj_j2k_set_decoded_resolution_factor(), opj_j2k_set_threads(), opj_j2k_setup_decoder(), opj_jp2_create(), opj_jp2_decode(), opj_jp2_decode_tile(), opj_jp2_decoder_set_strict_mode(), opj_jp2_destroy(), opj_jp2_end_decompress(), opj_jp2_get_tile(), opj_jp2_read_header(), opj_jp2_read_tile_header(), opj_jp2_set_decode_area(), opj_jp2_set_decoded_components(), opj_jp2_set_decoded_resolution_factor(), opj_jp2_set_threads(), opj_jp2_setup_decoder(), opj_set_default_event_handler(), opj_codec_private::opj_set_threads, and OPJ_TRUE.

Referenced by j2k_to_pnm().

## ◆ opj_decode()

OPJ_BOOL OPJ_CALLCONV opj_decode | ( | opj_codec_t * | p_decompressor,
|  | opj_stream_t * | p_stream,
|  | opj_image_t * | p_image
| ) |  |

Decode an image from a JPEG-2000 codestream.

Parameters

  p_decompressor | decompressor handle
  p_stream | Input buffer stream
  p_image | the decoded image

Returns
  true if success, otherwise false

References opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_decompression, opj_codec_private::m_event_mgr, and OPJ_FALSE.

Referenced by j2k_to_pnm().

## ◆ opj_decode_tile_data()

OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data | ( | opj_codec_t * | p_codec,
|  | OPJ_UINT32 | p_tile_index,
|  | OPJ_BYTE * | p_data,
|  | OPJ_UINT32 | p_data_size,
|  | opj_stream_t * | p_stream
| ) |  |

Reads a tile data.

This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before. The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.

Note: opj_decode_tile_data() should not be used together with opj_set_decoded_components().

Parameters

  p_codec | the jpeg2000 codec.
  p_tile_index | the index of the tile being decoded, this should be the value set by opj_read_tile_header.
  p_data | pointer to a memory block that will hold the decoded data.
  p_data_size | size of p_data. p_data_size should be bigger or equal to the value set by opj_read_tile_header.
  p_stream | the stream to decode.

Returns
  true if the data could be decoded.

References opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_decompression, opj_codec_private::m_event_mgr, and OPJ_FALSE.

## ◆ opj_decoder_set_strict_mode()

OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decoder_set_strict_mode | ( | opj_codec_t * | p_codec,
|  | OPJ_BOOL | strict
| ) |  |

Set strict decoding parameter for this decoder.

If strict decoding is enabled, partial bit streams will fail to decode. If strict decoding is disabled, the decoder will decode partial bitstreams as much as possible without erroring

Parameters

  p_codec | decompressor handler
  strict | OPJ_TRUE to enable strict decoding, OPJ_FALSE to disable

Returns
  true if the decoder is correctly set

References EVT_ERROR, opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_decompression, opj_codec_private::m_event_mgr, opj_event_msg(), OPJ_FALSE, and OPJ_TRUE.

## ◆ opj_destroy_codec()

void OPJ_CALLCONV opj_destroy_codec | ( | opj_codec_t * | p_codec | ) |

Destroy a decompressor handle.

Parameters

  p_codec | decompressor handle to destroy

References opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_compression, opj_codec_private::m_decompression, and opj_free().

Referenced by j2k_to_pnm().

## ◆ opj_destroy_cstr_index()

void OPJ_CALLCONV opj_destroy_cstr_index | ( | opj_codestream_index_t ** | p_cstr_index | ) |

References j2k_destroy_cstr_index().

## ◆ opj_destroy_cstr_info()

void OPJ_CALLCONV opj_destroy_cstr_info | ( | opj_codestream_info_v2_t ** | cstr_info | ) |

Destroy Codestream information after compression or decompression.

Parameters

  cstr_info | Codestream information structure

References opj_free().

Referenced by j2k_get_cstr_info().

## ◆ opj_dump_codec()

void OPJ_CALLCONV opj_dump_codec | ( | opj_codec_t * | p_codec,
|  | OPJ_INT32 | info_flag,
|  | FILE * | output_stream
| ) |  |

Dump the codec information into the output stream.

Parameters

  p_codec | the jpeg2000 codec.
  info_flag | type of information dump.
  output_stream | output stream where dump the information gotten from the codec.

References opj_codec_private::m_codec, and opj_codec_private::opj_dump_codec.

## ◆ opj_encode()

OPJ_BOOL OPJ_CALLCONV opj_encode | ( | opj_codec_t * | p_codec,
|  | opj_stream_t * | p_stream
| ) |  |

Encode an image into a JPEG-2000 codestream.

Parameters

  p_codec | compressor handle
  p_stream | Output buffer stream

Returns
  Returns true if successful, returns false otherwise

References opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_compression, opj_codec_private::m_event_mgr, and OPJ_FALSE.

## ◆ opj_encoder_set_extra_options()

OPJ_BOOL OPJ_CALLCONV opj_encoder_set_extra_options | ( | opj_codec_t * | p_codec,
|  | const char *const * | p_options
| ) |  |

Specify extra options for the encoder.

This may be called after opj_setup_encoder() and before opj_start_compress()

This is the way to add new options in a fully ABI compatible way, without extending the opj_cparameters_t structure.

Currently supported options are:

- PLT=YES/NO. Defaults to NO. If set to YES, PLT marker segments, indicating the length of each packet in the tile-part header, will be written. Since 2.4.0
- TLM=YES/NO. Defaults to NO (except for Cinema and IMF profiles). If set to YES, TLM marker segments, indicating the length of each tile-part part will be written. Since 2.4.0
- GUARD_BITS=value. Number of guard bits in [0,7] range. Default value is 2. 1 may be used sometimes (like in SMPTE DCP Bv2.1 Application Profile for 2K images). Since 2.5.0

Parameters

  p_codec | Compressor handle
  p_options | Compression options. This should be a NULL terminated array of strings. Each string is of the form KEY=VALUE.

Returns
  OPJ_TRUE in case of success.

Since
  2.4.0

References opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_compression, opj_codec_private::m_event_mgr, and OPJ_FALSE.

## ◆ opj_end_compress()

OPJ_BOOL OPJ_CALLCONV opj_end_compress | ( | opj_codec_t * | p_codec,
|  | opj_stream_t * | p_stream
| ) |  |

End to compress the current image.

Parameters

  p_codec | Compressor handle
  p_stream | Input stgream

References opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_compression, opj_codec_private::m_event_mgr, and OPJ_FALSE.

## ◆ opj_end_decompress()

OPJ_BOOL OPJ_CALLCONV opj_end_decompress | ( | opj_codec_t * | p_codec,
|  | opj_stream_t * | p_stream
| ) |  |

Read after the codestream if necessary.

Parameters

  p_codec | the JPEG2000 codec to read.
  p_stream | the JPEG2000 stream.

References opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_decompression, opj_codec_private::m_event_mgr, and OPJ_FALSE.

Referenced by j2k_to_pnm().

## ◆ opj_get_cstr_index()

opj_codestream_index_t *OPJ_CALLCONV opj_get_cstr_index | ( | opj_codec_t * | p_codec | ) |

Get the codestream index from the codec.

Parameters

  p_codec | the jpeg2000 codec.

Returns
  a pointer to a codestream index structure.

References opj_codec_private::m_codec, and opj_codec_private::opj_get_codec_index.

## ◆ opj_get_cstr_info()

opj_codestream_info_v2_t *OPJ_CALLCONV opj_get_cstr_info | ( | opj_codec_t * | p_codec | ) |

Get the codestream information from the codec.

Parameters

  p_codec | the jpeg2000 codec.

Returns
  a pointer to a codestream information structure.

References opj_codec_private::m_codec, and opj_codec_private::opj_get_codec_info.

## ◆ opj_get_data_length_from_file()

static OPJ_UINT64 opj_get_data_length_from_file | ( | void * | p_user_data | ) |
| static

References OPJ_FSEEK, and OPJ_FTELL.

Referenced by opj_stream_create_file_stream().

## ◆ opj_get_decoded_tile()

OPJ_BOOL OPJ_CALLCONV opj_get_decoded_tile | ( | opj_codec_t * | p_codec,
|  | opj_stream_t * | p_stream,
|  | opj_image_t * | p_image,
|  | OPJ_UINT32 | tile_index
| ) |  |

Get the decoded tile from the codec.

Parameters

  p_codec | the jpeg2000 codec.
  p_stream | input stream
  p_image | output image
  tile_index | index of the tile which will be decode

Returns
  true if success, otherwise false

References opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_decompression, opj_codec_private::m_event_mgr, and OPJ_FALSE.

## ◆ opj_image_data_alloc()

void *OPJ_CALLCONV opj_image_data_alloc | ( | OPJ_SIZE_T | size | ) |

Allocator for opj_image_t->comps[].data To be paired with opj_image_data_free.

Parameters

  size | number of bytes to allocate

Returns
  a new pointer if successful, NULL otherwise.

Since
  2.2.0

References opj_aligned_malloc().

Referenced by opj_alloc_tile_component_data(), opj_image_create(), opj_j2k_update_image_data(), opj_jp2_apply_pclr(), and opj_tcd_decode_tile().

## ◆ opj_image_data_free()

void OPJ_CALLCONV opj_image_data_free | ( | void * | ptr | ) |

Destructor for opj_image_t->comps[].data To be paired with opj_image_data_alloc.

Parameters

  ptr | Pointer to free

Since
  2.2.0

References opj_aligned_free().

Referenced by opj_alloc_tile_component_data(), opj_copy_image_header(), opj_image_destroy(), opj_j2k_decode_tiles(), opj_j2k_get_tile(), opj_j2k_move_data_from_codec_to_output_image(), opj_jp2_apply_pclr(), opj_tcd_decode_tile(), opj_tcd_free_tile(), and opj_tcd_init_tile().

## ◆ opj_read_from_file()

static OPJ_SIZE_T opj_read_from_file | ( | void * | p_buffer,
|  | OPJ_SIZE_T | p_nb_bytes,
|  | void * | p_user_data
| ) |  |
| static

Referenced by opj_stream_create_file_stream().

## ◆ opj_read_header()

OPJ_BOOL OPJ_CALLCONV opj_read_header | ( | opj_stream_t * | p_stream,
|  | opj_codec_t * | p_codec,
|  | opj_image_t ** | p_image
| ) |  |

Decodes an image header.

Parameters

  p_stream | the jpeg2000 stream.
  p_codec | the jpeg2000 codec to read.
  p_image | the image structure initialized with the characteristics of encoded image.

Returns
  true if the main header of the codestream and the JP2 header is correctly read.

References EVT_ERROR, opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_decompression, opj_codec_private::m_event_mgr, opj_event_msg(), and OPJ_FALSE.

Referenced by j2k_to_pnm().

## ◆ opj_read_tile_header()

OPJ_BOOL OPJ_CALLCONV opj_read_tile_header | ( | opj_codec_t * | p_codec,
|  | opj_stream_t * | p_stream,
|  | OPJ_UINT32 * | p_tile_index,
|  | OPJ_UINT32 * | p_data_size,
|  | OPJ_INT32 * | p_tile_x0,
|  | OPJ_INT32 * | p_tile_y0,
|  | OPJ_INT32 * | p_tile_x1,
|  | OPJ_INT32 * | p_tile_y1,
|  | OPJ_UINT32 * | p_nb_comps,
|  | OPJ_BOOL * | p_should_go_on
| ) |  |

Reads a tile header.

This function is compulsory and allows one to know the size of the tile that will be decoded. The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.

Parameters

  p_codec | the jpeg2000 codec.
  p_tile_index | pointer to a value that will hold the index of the tile being decoded, in case of success.
  p_data_size | pointer to a value that will hold the maximum size of the decoded data, in case of success. In case of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same as depicted in opj_write_tile.
  p_tile_x0 | pointer to a value that will hold the x0 pos of the tile (in the image).
  p_tile_y0 | pointer to a value that will hold the y0 pos of the tile (in the image).
  p_tile_x1 | pointer to a value that will hold the x1 pos of the tile (in the image).
  p_tile_y1 | pointer to a value that will hold the y1 pos of the tile (in the image).
  p_nb_comps | pointer to a value that will hold the number of components in the tile.
  p_should_go_on | pointer to a boolean that will hold the fact that the decoding should go on. In case the codestream is over at the time of the call, the value will be set to false. The user should then stop the decoding.
  p_stream | the stream to decode.

Returns
  true if the tile header could be decoded. In case the decoding should end, the returned value is still true. returning false may be the result of a shortage of memory or an internal error.

References opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_decompression, opj_codec_private::m_event_mgr, and OPJ_FALSE.

## ◆ opj_seek_from_file()

static OPJ_BOOL opj_seek_from_file | ( | OPJ_OFF_T | p_nb_bytes,
|  | void * | p_user_data
| ) |  |
| static

References OPJ_FALSE, OPJ_FSEEK, and OPJ_TRUE.

Referenced by opj_stream_create_file_stream().

## ◆ opj_set_decode_area()

OPJ_BOOL OPJ_CALLCONV opj_set_decode_area | ( | opj_codec_t * | p_codec,
|  | opj_image_t * | p_image,
|  | OPJ_INT32 | p_start_x,
|  | OPJ_INT32 | p_start_y,
|  | OPJ_INT32 | p_end_x,
|  | OPJ_INT32 | p_end_y
| ) |  |

Sets the given area to be decoded.

This function should be called right after opj_read_header and before any tile header reading.

The coordinates passed to this function should be expressed in the reference grid, that is to say at the highest resolution level, even if requesting the image at lower resolution levels.

Generally opj_set_decode_area() should be followed by opj_decode(), and the codec cannot be re-used. In the particular case of an image made of a single tile, several sequences of calls to opoj_set_decode_area() and opj_decode() are allowed, and will bring performance improvements when reading an image by chunks.

Parameters

  p_codec | the jpeg2000 codec.
  p_image | the decoded image previously set by opj_read_header
  p_start_x | the left position of the rectangle to decode (in image coordinates).
  p_end_x | the right position of the rectangle to decode (in image coordinates).
  p_start_y | the up position of the rectangle to decode (in image coordinates).
  p_end_y | the bottom position of the rectangle to decode (in image coordinates).

Returns
  true if the area could be set.

References opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_decompression, opj_codec_private::m_event_mgr, and OPJ_FALSE.

Referenced by j2k_to_pnm().

## ◆ opj_set_decoded_components()

OPJ_BOOL OPJ_CALLCONV opj_set_decoded_components | ( | opj_codec_t * | p_codec,
|  | OPJ_UINT32 | numcomps,
|  | const OPJ_UINT32 * | comps_indices,
|  | OPJ_BOOL | apply_color_transforms
| ) |  |

Restrict the number of components to decode.

This function should be called after opj_read_header().

This function enables to restrict the set of decoded components to the specified indices. Note that the current implementation (apply_color_transforms == OPJ_FALSE) is such that neither the multi-component transform at codestream level, nor JP2 channel transformations will be applied. Consequently the indices are relative to the codestream.

Note: opj_decode_tile_data() should not be used together with opj_set_decoded_components().

Parameters

  p_codec | the jpeg2000 codec to read.
  numcomps | Size of the comps_indices array.
  comps_indices | Array of numcomps values representing the indices of the components to decode (relative to the codestream, starting at 0)
  apply_color_transforms | Whether multi-component transform at codestream level or JP2 channel transformations should be applied. Currently this parameter should be set to OPJ_FALSE. Setting it to OPJ_TRUE will result in an error.

Returns
  OPJ_TRUE in case of success.

References EVT_ERROR, opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_decompression, opj_codec_private::m_event_mgr, opj_event_msg(), and OPJ_FALSE.

## ◆ opj_set_decoded_resolution_factor()

OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor | ( | opj_codec_t * | p_codec,
|  | OPJ_UINT32 | res_factor
| ) |  |

Set the resolution factor of the decoded image.

Parameters

  p_codec | the jpeg2000 codec.
  res_factor | resolution factor to set

Returns
  true if success, otherwise false

References opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_decompression, opj_codec_private::m_event_mgr, and OPJ_FALSE.

## ◆ opj_set_default_decoder_parameters()

void OPJ_CALLCONV opj_set_default_decoder_parameters | ( | opj_dparameters_t * | parameters | ) |

Set decoding parameters to default values.

Parameters

  parameters | Decompression parameters

References opj_dparameters::cod_format, opj_dparameters::cp_layer, opj_dparameters::cp_reduce, opj_dparameters::decod_format, opj_dparameters::flags, opj_dparameters::jpwl_correct, opj_dparameters::jpwl_exp_comps, JPWL_EXPECTED_COMPONENTS, opj_dparameters::jpwl_max_tiles, JPWL_MAXIMUM_TILES, and OPJ_FALSE.

Referenced by j2k_to_pnm().

## ◆ opj_set_default_encoder_parameters()

void OPJ_CALLCONV opj_set_default_encoder_parameters | ( | opj_cparameters_t * | parameters | ) |

Set encoding parameters to default values, that means :

- Lossless
- 1 tile
- Size of precinct : 2^15 x 2^15 (means 1 precinct)
- Size of code-block : 64 x 64
- Number of resolutions: 6
- No SOP marker in the codestream
- No EPH marker in the codestream
- No sub-sampling in x or y direction
- No mode switch activated
- Progression order: LRCP
- No index file
- No ROI upshifted
- No offset of the origin of the image
- No offset of the origin of the tiles
- Reversible DWT 5-3

Parameters

  parameters | Compression parameters

References opj_cparameters::cblockh_init, opj_cparameters::cblockw_init, opj_cparameters::cod_format, opj_cparameters::cp_cinema, opj_cparameters::cp_disto_alloc, opj_cparameters::cp_fixed_alloc, opj_cparameters::cp_fixed_quality, opj_cparameters::cp_rsiz, opj_cparameters::decod_format, opj_cparameters::jpip_on, opj_cparameters::jpwl_epc_on, opj_cparameters::jpwl_hprot_MH, opj_cparameters::jpwl_hprot_TPH, opj_cparameters::jpwl_hprot_TPH_tileno, JPWL_MAX_NO_PACKSPECS, JPWL_MAX_NO_TILESPECS, opj_cparameters::jpwl_pprot, opj_cparameters::jpwl_pprot_packno, opj_cparameters::jpwl_pprot_tileno, opj_cparameters::jpwl_sens_addr, opj_cparameters::jpwl_sens_MH, opj_cparameters::jpwl_sens_range, opj_cparameters::jpwl_sens_size, opj_cparameters::jpwl_sens_TPH, opj_cparameters::jpwl_sens_TPH_tileno, opj_cparameters::max_comp_size, opj_cparameters::numresolution, OPJ_COMP_PARAM_DEFAULT_CBLOCKH, OPJ_COMP_PARAM_DEFAULT_CBLOCKW, OPJ_COMP_PARAM_DEFAULT_NUMRESOLUTION, OPJ_COMP_PARAM_DEFAULT_PROG_ORDER, OPJ_FALSE, OPJ_OFF, OPJ_PROFILE_NONE, OPJ_STD_RSIZ, opj_cparameters::prog_order, opj_cparameters::roi_compno, opj_cparameters::rsiz, opj_cparameters::subsampling_dx, opj_cparameters::subsampling_dy, opj_cparameters::tcp_numlayers, opj_cparameters::tcp_rates, and opj_cparameters::tp_on.

## ◆ opj_set_error_handler()

OPJ_BOOL OPJ_CALLCONV opj_set_error_handler | ( | opj_codec_t * | p_codec,
|  | opj_msg_callback | p_callback,
|  | void * | p_user_data
| ) |  |

Set the error handler use by openjpeg.

Parameters

  p_codec | the codec previously initialise
  p_callback | the callback function which will be used
  p_user_data | client object where will be returned the message

References opj_event_mgr::error_handler, opj_event_mgr::m_error_data, opj_codec_private::m_event_mgr, OPJ_FALSE, and OPJ_TRUE.

Referenced by j2k_to_pnm().

## ◆ opj_set_info_handler()

OPJ_BOOL OPJ_CALLCONV opj_set_info_handler | ( | opj_codec_t * | p_codec,
|  | opj_msg_callback | p_callback,
|  | void * | p_user_data
| ) |  |

Set the info handler use by openjpeg.

Parameters

  p_codec | the codec previously initialise
  p_callback | the callback function which will be used
  p_user_data | client object where will be returned the message

References opj_event_mgr::info_handler, opj_codec_private::m_event_mgr, opj_event_mgr::m_info_data, OPJ_FALSE, and OPJ_TRUE.

Referenced by j2k_to_pnm().

## ◆ opj_set_MCT()

OPJ_BOOL OPJ_CALLCONV opj_set_MCT | ( | opj_cparameters_t * | parameters,
|  | OPJ_FLOAT32 * | pEncodingMatrix,
|  | OPJ_INT32 * | p_dc_shift,
|  | OPJ_UINT32 | pNbComp
| ) |  |

Sets the MCT matrix to use.

Parameters

  parameters | the parameters to change.
  pEncodingMatrix | the encoding matrix.
  p_dc_shift | the dc shift coefficients to use.
  pNbComp | the number of components of the image.

Returns
  true if the parameters could be set.

References opj_cparameters::irreversible, opj_cparameters::mct_data, OPJ_EXTENSION_MCT, OPJ_FALSE, OPJ_IS_PART2, opj_malloc(), OPJ_PROFILE_PART2, OPJ_TRUE, opj_cparameters::rsiz, and opj_cparameters::tcp_mct.

## ◆ opj_set_warning_handler()

OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler | ( | opj_codec_t * | p_codec,
|  | opj_msg_callback | p_callback,
|  | void * | p_user_data
| ) |  |

Set the warning handler use by openjpeg.

Parameters

  p_codec | the codec previously initialise
  p_callback | the callback function which will be used
  p_user_data | client object where will be returned the message

References opj_codec_private::m_event_mgr, opj_event_mgr::m_warning_data, OPJ_FALSE, OPJ_TRUE, and opj_event_mgr::warning_handler.

Referenced by j2k_to_pnm().

## ◆ opj_setup_decoder()

OPJ_BOOL OPJ_CALLCONV opj_setup_decoder | ( | opj_codec_t * | p_codec,
|  | opj_dparameters_t * | parameters
| ) |  |

Setup the decoder with decompression parameters provided by the user and with the message handler provided by the user.

Parameters

  p_codec | decompressor handler
  parameters | decompression parameters

Returns
  true if the decoder is correctly set

References EVT_ERROR, opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_decompression, opj_codec_private::m_event_mgr, opj_event_msg(), OPJ_FALSE, and OPJ_TRUE.

Referenced by j2k_to_pnm().

## ◆ opj_setup_encoder()

OPJ_BOOL OPJ_CALLCONV opj_setup_encoder | ( | opj_codec_t * | p_codec,
|  | opj_cparameters_t * | parameters,
|  | opj_image_t * | image
| ) |  |

Setup the encoder parameters using the current image and using user parameters.

Parameters

  p_codec | Compressor handle
  parameters | Compression parameters
  image | Input filled image

References opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_compression, opj_codec_private::m_event_mgr, and OPJ_FALSE.

## ◆ opj_skip_from_file()

static OPJ_OFF_T opj_skip_from_file | ( | OPJ_OFF_T | p_nb_bytes,
|  | void * | p_user_data
| ) |  |
| static

References OPJ_FSEEK.

Referenced by opj_stream_create_file_stream().

## ◆ opj_start_compress()

OPJ_BOOL OPJ_CALLCONV opj_start_compress | ( | opj_codec_t * | p_codec,
|  | opj_image_t * | p_image,
|  | opj_stream_t * | p_stream
| ) |  |

Start to compress the current image.

Parameters

  p_codec | Compressor handle
  p_image | Input filled image
  p_stream | Input stgream

References opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_compression, opj_codec_private::m_event_mgr, and OPJ_FALSE.

## ◆ opj_stream_create_default_file_stream()

opj_stream_t *OPJ_CALLCONV opj_stream_create_default_file_stream | ( | const char * | fname,
|  | OPJ_BOOL | p_is_read_stream
| ) |  |

Create a stream from a file identified with its filename with default parameters (helper function)

Parameters

  fname | the filename of the file to stream
  p_is_read_stream | whether the stream is a read stream (true) or not (false)

References OPJ_J2K_STREAM_CHUNK_SIZE, and opj_stream_create_file_stream().

Referenced by j2k_to_pnm().

## ◆ opj_stream_create_file_stream()

opj_stream_t *OPJ_CALLCONV opj_stream_create_file_stream | ( | const char * | fname,
|  | OPJ_SIZE_T | p_buffer_size,
|  | OPJ_BOOL | p_is_read_stream
| ) |  |

Create a stream from a file identified with its filename with a specific buffer size.

Parameters

  fname | the filename of the file to stream
  p_buffer_size | size of the chunk used to stream
  p_is_read_stream | whether the stream is a read stream (true) or not (false)

References opj_close_from_file(), opj_get_data_length_from_file(), opj_read_from_file(), opj_seek_from_file(), opj_skip_from_file(), opj_stream_create(), opj_stream_set_read_function(), opj_stream_set_seek_function(), opj_stream_set_skip_function(), opj_stream_set_user_data(), opj_stream_set_user_data_length(), opj_stream_set_write_function(), and opj_write_from_file().

Referenced by opj_stream_create_default_file_stream().

## ◆ opj_version()

const char *OPJ_CALLCONV opj_version | ( | void |  | ) |

Referenced by opj_j2k_setup_encoder().

## ◆ opj_write_from_file()

static OPJ_SIZE_T opj_write_from_file | ( | void * | p_buffer,
|  | OPJ_SIZE_T | p_nb_bytes,
|  | void * | p_user_data
| ) |  |
| static

Referenced by opj_stream_create_file_stream().

## ◆ opj_write_tile()

OPJ_BOOL OPJ_CALLCONV opj_write_tile | ( | opj_codec_t * | p_codec,
|  | OPJ_UINT32 | p_tile_index,
|  | OPJ_BYTE * | p_data,
|  | OPJ_UINT32 | p_data_size,
|  | opj_stream_t * | p_stream
| ) |  |

Writes a tile with the given data.

Parameters

  p_codec | the jpeg2000 codec.
  p_tile_index | the index of the tile to write. At the moment, the tiles must be written from 0 to n-1 in sequence.
  p_data | pointer to the data to write. Data is arranged in sequence, data_comp0, then data_comp1, then ... NO INTERLEAVING should be set.
  p_data_size | this value os used to make sure the data being written is correct. The size must be equal to the sum for each component of tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes, depending on the precision of the given component.
  p_stream | the stream to write data to.

Returns
  true if the data could be written.

References opj_codec_private::is_decompressor, opj_codec_private::m_codec, opj_codec_private::m_codec_data, opj_codec_private::m_compression, opj_codec_private::m_event_mgr, and OPJ_FALSE.