Type Declarations¶
API Return Status Codes¶
The return codes of the nvJPEG2000 APIs are listed below:
typedef enum
{
NVJPEG2K_STATUS_SUCCESS = 0,
NVJPEG2K_STATUS_NOT_INITIALIZED = 1,
NVJPEG2K_STATUS_INVALID_PARAMETER = 2,
NVJPEG2K_STATUS_BAD_JPEG = 3,
NVJPEG2K_STATUS_JPEG_NOT_SUPPORTED = 4,
NVJPEG2K_STATUS_ALLOCATOR_FAILURE = 5,
NVJPEG2K_STATUS_EXECUTION_FAILED = 6,
NVJPEG2K_STATUS_ARCH_MISMATCH = 7,
NVJPEG2K_STATUS_INTERNAL_ERROR = 8,
NVJPEG2K_STATUS_IMPLEMENTATION_NOT_SUPPORTED = 9,
} nvjpeg2kStatus_t;
Description the Return Codes
Return Code |
Description |
|---|---|
NVJPEG2K_STATUS_SUCCESS (0) |
The API call has finished successfully. Note that many of the calls are asynchronous and some of the errors may be seen only after synchronization. |
NVJPEG2K_STATUS_NOT_INITIALIZED (1) |
The library handle was not initialized. |
NVJPEG2K_STATUS_INVALID_PARAMETER (2) |
Wrong parameter was passed. For example, a null pointer as input data, or an invalid enum value |
NVJPEG2K_STATUS_BAD_JPEG (3) |
Cannot parse the JPEG2000 stream. Likely due to a corruption that cannot be handled |
NVJPEG2K_STATUS_JPEG_NOT_SUPPORTED (4) |
Attempting to decode a JPEG2000 stream that is not supported by the nvJPEG2000 library. |
NVJPEG2K_STATUS_ALLOCATOR_FAILURE (5) |
The user-provided allocator functions, for either memory allocation or for releasing the memory, returned a non-zero code. |
NVJPEG2K_STATUS_EXECUTION_FAILED (6) |
Error during the execution of the device tasks. |
NVJPEG2K_STATUS_ARCH_MISMATCH (7) |
The device capabilities are not enough for the set of input parameters provided. |
NVJPEG2K_STATUS_INTERNAL_ERROR (8) |
Unknown error occured in the library. |
NVJPEG2K_STATUS_IMPLEMENTATION_NOT_SUPPORTED (9) |
API is not supported by the backend. |
Device Allocator Interface¶
typedef int (*nvjpeg2kDeviceMalloc)(void**, size_t);
typedef int (*nvjpeg2kDeviceFree)(void*);
typedef struct
{
nvjpeg2kDeviceMalloc device_malloc;
nvjpeg2kDeviceFree device_free;
} nvjpeg2kDeviceAllocator_t;
When the nvjpeg2kDeviceAllocator_t *allocator parameter in the nvjpeg2kCreate() function is set as a pointer to the above nvjpeg2kDeviceAllocator_t structure, then this structure is used for allocating and releasing the device memory. The function prototypes for the memory allocation and memory freeing functions are similar to the cudaMalloc() and cudaFree() functions. They should return 0 in case of success, and non-zero otherwise.
However, if the nvjpeg2kDeviceAllocator_t *allocator parameter in the nvjpeg2kCreate() function is set to NULL, then the default memory allocation functions cudaMalloc() and cudaFree() will be used. When using nvjpeg2kCreateSimple() function to create library handle the default device memory allocator will be used.
Pinned Allocator Interface¶
typedef int (*nvjpeg2kPinnedMalloc)(void**, size_t, unsigned int flags);
typedef int (*nvjpeg2kPinnedFree)(void*)
typedef struct
{
nvjpeg2kPinnedMalloc pinned_malloc;
nvjpeg2kPinnedFree pinned_free;
} nvjpeg2kPinnedAllocator_t;
When the nvjpegPinnedAllocator_t *allocator parameter in the nvjpeg2kCreate() function is set as a pointer to the above nvjpegPinnedAllocator_t structure, then this structure will be used for allocating and releasing host pinned memory for copying data to/from device. The function prototypes for the memory allocation and memory freeing functions are similar to cudaHostAlloc() and cudaFreeHost() functions. They will return 0 in case of success, and non-zero otherwise.
However, if the nvjpeg2kPinnedAllocator_t *allocator parameter in the nvjpeg2kCreate() function is set to NULL, then the default memory allocation functions cudaHostAlloc() and cudaFreeHost() will be used. When using nvjpegCreateSimple() function to create library handle, the default host pinned memory allocator will be used.
Color Space¶
typedef enum
{
NVJPEG2K_COLORSPACE_NOT_SUPPORTED = -1,
NVJPEG2K_COLORSPACE_UNKNOWN = 0,
NVJPEG2K_COLORSPACE_SRGB = 1,
NVJPEG2K_COLORSPACE_GRAY = 2,
NVJPEG2K_COLORSPACE_SYCC = 3
} nvjpeg2kColorSpace_t;
The nvjpeg2kColorSpace_t enum corresponds to the colorspace values which are part of the JP2 file format specification.
Library Backend¶
typedef enum
{
NVJPEG2K_BACKEND_DEFAULT = 0
} nvjpeg2kBackend_t;
The nvjpeg2kBackend_t enum allows the user the option to select a different internal implementation. A single implementation is currently supported. Additional implementations may be added in the future.
Component Information¶
typedef struct
{
uint32_t component_width;
uint32_t component_height;
uint8_t precision;
uint8_t sgn;
} nvjpeg2kImageComponentInfo_t;
nvjpeg2kImageComponentInfo_t is used to retrieve component level information. This information can be used for allocating output buffers.
Image Information¶
typedef struct
{
uint32_t image_width;
uint32_t image_height;
uint32_t tile_width;
uint32_t tile_height;
uint32_t num_tiles_x;
uint32_t num_tiles_y;
uint32_t num_components;
} nvjpeg2kImageInfo_t;
nvjpeg2kImageInfo_t is used to retrieve image information which can be used to allocate output buffers.
Image Type¶
typedef enum
{
NVJPEG2K_UINT8 = 0,
NVJPEG2K_UINT16 = 1
} nvjpeg2kImageType_t;
nvjpeg2kImageType_t describes the pixel data types supported by nvJPEG2000.
Image Data¶
typedef struct
{
void **pixel_data;
size_t *pitch_in_bytes;
nvjpeg2kImageType_t pixel_type;
uint32_t num_components;
} nvjpeg2kImage_t;
nvjpeg2kImage_t serves as an image container. It contains an array of void pointers. Each pointer corresponds to a component in the nvjpeg2k bitstream
There is another corresponding array which defines the pitch of each component. pixel_type determines the data type of
pixel_data. See Image Type for supported types.
Library Handle¶
struct nvjpeg2kHandle;
typedef struct nvjpeg2kHandle* nvjpeg2kHandle_t;
This handle should be instantiated prior to using the any of the APIs. It is thread safe, and can be used by multiple threads simultaneously.
Decoder State¶
struct nvjpeg2kDecodeState;
typedef struct nvjpeg2kDecodeState* nvjpeg2kDecodeState_t;
The nvjpeg2kDecodeState_t handle stores intermediate decode information. This handle can be reused when decoding multiple images. User has to ensure that a stream or device synchronize CUDA call is made between the decoding of two images.
Bitstream Handle¶
struct nvjpeg2kStream;
typedef struct nvjpeg2kStream* nvjpeg2kStream_t;
This handle is used for parsing the bitstream. Bitstream metadata can be extracted by using the APIs defined in Parser API Reference.
Decode Parameter Handle¶
struct nvjpeg2kDecodeParams;
typedef struct nvjpeg2kDecodeParams* nvjpeg2kDecodeParams_t;
This handle is used to store the decode output parameters like the decode area of interest.