### Install nvJPEG2000 for CUDA 12.x via pip Source: https://docs.nvidia.com/cuda/nvjpeg2000/installation.html Use this command to install nvJPEG2000 for CUDA 12.x from PyPi. ```bash python3 -m pip install nvidia-nvjpeg2k-cu12 ``` -------------------------------- ### Install nvJPEG2000 for CUDA 13.x via pip Source: https://docs.nvidia.com/cuda/nvjpeg2000/installation.html Use this command to install nvJPEG2000 for CUDA 13.x from PyPi. ```bash python3 -m pip install nvidia-nvjpeg2k-cu13 ``` -------------------------------- ### Install nvJPEG2000 for CUDA 12.x on Tegra via pip Source: https://docs.nvidia.com/cuda/nvjpeg2000/installation.html Use this command to install nvJPEG2000 for CUDA 12.x on Tegra platforms from PyPi. ```bash python3 -m pip install nvidia-nvjpeg2k-tegra-cu12 ``` -------------------------------- ### nvjpeg2kEncodeParamsSetInputFormat() with interleaved buffer setup Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/encodeparamsapi.html Shows how to allocate the encode input buffer for NVJPEG2K_FORMAT_INTERLEAVED and the signature for nvjpeg2kEncodearamsSetInputFormat. The format parameter defaults to NVJPEG2K_FORMAT_PLANAR. Interleaved format is supported only when all component dimensions are the same. ```c nvjpeg2kImage_t encode_input; ``` ```c encode_input.pitch_in_bytes[0] = image_width * num_components * bytes_per_sample; encode_input.pixel_data[0] = encode_input.pitch_in_bytes[0] * info.image_height; encode_input.num_components = num_components; ``` ```c nvjpeg2kStatus_t nvjpeg2kEncodearamsSetInputFormat(nvjpeg2kEncodeParams_t encode_params, nvjpeg2kImageFormat_t format); ``` -------------------------------- ### Retrieve compressed JPEG2000 bitstream Source: https://docs.nvidia.com/cuda/nvjpeg2000/quickstartguide.html Retrieves the compressed bitstream to host memory. First calls with NULL to get the size, then allocates the buffer and calls again. cudaDeviceSynchronize() is required because the APIs are asynchronous with respect to the host. ```cpp // set the compressed_data buffer to NULL to retrieve the bitstream size size_t compressed_size; status = nvjpeg2kEncodeRetrieveBitstream(enc_handle, enc_state, NULL, &compressed_size); // allocate output buffer unsigned char *compressed_data = new unsigned char [compressed_size] status = nvjpeg2kEncodeRetrieveBitstream(enc_handle, enc_state, compressed_data, &compressed_size, params.stream)); cudaDeviceSynchronize(); ``` -------------------------------- ### Set up input image buffers for encoding Source: https://docs.nvidia.com/cuda/nvjpeg2000/quickstartguide.html Initializes nvjpeg2kImage_t and nvjpeg2kImageComponentInfo_t for an 8-bit 3-channel RGB image. Uses cudaMallocPitch to allocate device memory with pitch, and sets the pixel data, type, and pitch in the input image structure. ```cpp #define NUM_COMPONENTS 3 unsigned char *pixel_data[NUM_COMPONENTS]; size_t pitch_in_bytes[NUM_COMPONENTS]; nvjpeg2kImageComponentInfo_t image_comp_info[NUM_COMPONENTS]; uint32_t image_width = // assign image width uint32_t image_height = // assign image height for (int c = 0; c < image_info.num_components; c++) { image_comp_info[c].component_width = image_width; image_comp_info[c].component_height = image_height; image_comp_info[c].precision = 8; image_comp_info[c].sgn = 0; } nvjpeg2kImage_t input_image; for (int c = 0; c < NUM_COMPONENTS; c++) { cudaMallocPitch(&pixel_data[c], &pitch_in_bytes[c], image_comp_info[c].comp_width, image_comp_info[c].comp_height); // cudaMallocPitch is used to let cuda deterimine the pitch. cudaMalloc can be used if required. } // Copy the image to the device buffers. input_image.pixel_data = pixel_data; input_image.pixel_type = NVJPEG2K_UINT8; input_image.pitch_in_bytes = pitch_in_bytes; ``` -------------------------------- ### nvjpeg2kCreateSimple() Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Creates an instance of the library handle with default backend and memory allocators. ```APIDOC ## nvjpeg2kCreateSimple() ### Description Creates an instance of the library handle with default backend and memory allocators. ### Signature ``` nvjpeg2kStatus_t nvjpeg2kCreateSimple(nvjpeg2kHandle_t *handle); ``` ### Parameters - **handle** (nvjpeg2kHandle_t*) - Input/Output - Host - nvjpeg2k library handle ### Returns `nvjpeg2kStatus_t` - An error code as specified in API Return Status Codes ``` -------------------------------- ### Initialize nvJPEG2000 encoder handles Source: https://docs.nvidia.com/cuda/nvjpeg2000/quickstartguide.html Creates the encoder handle, encode state, and encode parameters using the corresponding create APIs. All nvJPEG2000 APIs should return NVJPEG2K_STATUS_SUCCESS. ```cpp nvjpeg2kEncoder_t enc_handle; nvjpeg2kEncodeState_t enc_state; nvjpeg2kEncodeParams_t enc_params; nvjpeg2kEncoderCreateSimple(&enc_handle); nvjpeg2kEncodeStateCreate(&enc_state); nvjpeg2kEncodeParamsCreate(&enc_params); ``` -------------------------------- ### nvjpeg2kGetProperty() Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Gets the numeric value for the major or minor version, or the patch level, of the nvJPEG2000 library. ```APIDOC ## nvjpeg2kGetProperty() ### Description Gets the numeric value for the major or minor version, or the patch level, of the nvJPEG2000 library. ### Signature ``` nvjpeg2kStatus_t nvjpeg2kGetProperty(libraryPropertyType type, int *value); ``` ### Parameters - **type** (libraryPropertyType) - Input - Host - One of the supported libraryPropertyType values, that is, MAJOR_VERSION, MINOR_VERSION or PATCH_LEVEL - **value** (int*) - Output - Host - The numeric value corresponding to the specific libraryPropertyType requested. ### Returns `nvjpeg2kStatus_t` - An error code as specified in API Return Status Codes ``` -------------------------------- ### nvjpeg2kCreate Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Creates an instance of the nvjpeg2k library with configurable backend and allocators. Users can choose the backend implementation and provide device and pinned memory allocators. ```APIDOC ## nvjpeg2kCreate ### Description Creates an instance of the nvjpeg2k library using the input arguments. User has flexibility to choose the backend implementation and provide allocators. ### Signature ```c nvjpeg2kStatus_t nvjpeg2kCreate( nvjpeg2kBackend_t backend, nvjpeg2kDeviceAllocator_t *device_allocator, nvjpeg2kPinnedAllocator_t *pinned_allocator, nvjpeg2kHandle_t *handle); ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Parameters - **backend** (nvjpeg2kBackend_t) - Input - Host - Backend parameter - **device_allocator** (nvjpeg2kDeviceAllocator_t *) - Input - Host - Device allocator. cudaMalloc and cudaFree are used if set to NULL. See Device Allocator Interface - **pinned_allocator** (nvjpeg2kPinnedAllocator_t *) - Input - Host - Pinned allocator. cudaHostAlloc and cudaHost are used if set to NULL. See Pinned Allocator Interface - **handle** (nvjpeg2kHandle_t *) - Input/Output - Host - nvjpeg2k library handle ### Request Example ```c nvjpeg2kHandle_t handle; nvjpeg2kStatus_t status = nvjpeg2kCreate(NVJPEG2K_BACKEND_DEFAULT, NULL, NULL, &handle); ``` ### Response #### Success Response (200) - **status** (nvjpeg2kStatus_t) - An error code as specified in API Return Status Codes #### Response Example ```c NVJPEG2K_STATUS_SUCCESS ``` ``` -------------------------------- ### nvjpeg2kGetCudartProperty() Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Gets the numeric value for the major version, minor version, or patch level of the CUDA toolkit used to build the nvJPEG2000 library. ```APIDOC ## nvjpeg2kGetCudartProperty() ### Description Gets the numeric value for the major version, minor version, or the patch level of the CUDA toolkit that was used to build nvJPEG2000 library. ### Signature ``` nvjpeg2kStatus_t nvjpeg2kGetCudartProperty(libraryPropertyType type, int *value); ``` ### Parameters - **type** (libraryPropertyType) - Input - Host - One of the supported libraryPropertyType values, that is, MAJOR_VERSION, MINOR_VERSION or PATCH_LEVEL - **value** (int*) - Output - Host - The numeric value corresponding to the specific libraryPropertyType requested. ### Returns `nvjpeg2kStatus_t` - An error code as specified in API Return Status Codes ``` -------------------------------- ### nvjpeg2kGetProperty signature Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Gets the numeric value for the major or minor version, or the patch level, of the nvJPEG2000 library. The type parameter must be one of MAJOR_VERSION, MINOR_VERSION, or PATCH_LEVEL. ```c nvjpeg2kStatus_t nvjpeg2kGetProperty(libraryPropertyType type, int *value); ``` -------------------------------- ### nvjpeg2kBackend_t Source: https://docs.nvidia.com/cuda/nvjpeg2000/userguide.html Enumeration of available library backends. ```APIDOC ## nvjpeg2kBackend_t ### Description Enumeration to select a different internal implementation. Currently only the default backend is supported. ### Type Enum ### Definition ```c typedef enum { NVJPEG2K_BACKEND_DEFAULT = 0 } nvjpeg2kBackend_t; ``` ### Values - **NVJPEG2K_BACKEND_DEFAULT** (0) - Default backend. ``` -------------------------------- ### Initialize nvJPEG2000 library handles Source: https://docs.nvidia.com/cuda/nvjpeg2000/quickstartguide.html Initializes the nvJPEG2000 library handles required for decoding: nvjpeg2kHandle_t, nvjpeg2kStream_t, and nvjpeg2kDecodeState_t. Call these before any decoding operations. ```c nvjpeg2kHandle_t nvjpeg2k_handle; nvjpeg2kStream_t nvjpeg2k_stream; nvjpeg2kDecodeState_t decode_state; nvjpeg2kCreateSimple(&nvjpeg2k_handle); nvjpeg2kDecodeStateCreate(&decode_state); nvjpeg2kStreamCreate(&nvjpeg2k_stream); ``` -------------------------------- ### nvjpeg2kGetCudartProperty signature Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Gets the numeric value for the major version, minor version, or patch level of the CUDA toolkit used to build the nvJPEG2000 library. The type parameter must be one of MAJOR_VERSION, MINOR_VERSION, or PATCH_LEVEL. ```c nvjpeg2kStatus_t nvjpeg2kGetCudartProperty(libraryPropertyType type, int *value); ``` -------------------------------- ### nvjpeg2kStreamGetResolutionsInTile() signature Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/parserapi.html Retrieves the number of resolutions in a tile. The number of resolutions is defined as numResolutions = numWaveletDecompositionLevels + 1. Tiles are indexed in raster scan order; use nvjpeg2kStreamGetImageInfo to get the number of tiles along x and y. For tile coordinates (tile_x, tile_y), tile_id = tile_y * num_tiles_x + tile_x. ```c nvjpeg2kStatus_t nvjpeg2kStreamGetResolutionsInTile( nvjpeg2kStream_t stream_handle, uint32_t tile_id, uint32_t* num_res); ``` -------------------------------- ### nvjpeg2kDecodeStateCreate() Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Creates an instance of the Decode State. ```APIDOC ## nvjpeg2kDecodeStateCreate() ### Description Creates an instance of the Decode State. ### Signature ``` nvjpeg2kStatus_t nvjpeg2kDecodeStateCreate( nvjpeg2kHandle_t handle, nvjpeg2kDecodeState_t *decode_state); ``` ### Parameters - **handle** (nvjpeg2kHandle_t) - Input - Host - nvjpeg2k library handle - **decode_state** (nvjpeg2kDecodeState_t*) - Input/Output - Host - decode state handle ### Returns `nvjpeg2kStatus_t` - An error code as specified in API Return Status Codes ``` -------------------------------- ### nvjpeg2kCreateV2 Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Creates an instance of the nvjpeg2k library using extended allocators. This variant requires non-NULL extended allocator interfaces. ```APIDOC ## nvjpeg2kCreateV2 ### Description Creates an instance of the nvjpeg2k library using extended allocators. ### Signature ```c nvjpeg2kStatus_t nvjpeg2kCreateV2( nvjpeg2kBackend_t backend, nvjpeg2kDeviceAllocatorV2_t *device_allocator, nvjpeg2kPinnedAllocatorV2_t *pinned_allocator, nvjpeg2kHandle_t *handle); ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Parameters - **backend** (nvjpeg2kBackend_t) - Input - Host - Backend parameter - **device_allocator** (nvjpeg2kDeviceAllocatorV2_t *) - Input - Host - Extended Device allocator. Cannot be NULL. See Extended Device Allocator Interface - **pinned_allocator** (nvjpeg2kPinnedAllocatorV2_t *) - Input - Host - Extended Pinned allocator. Cannot be NULL. See Extended Pinned Allocator Interface - **handle** (nvjpeg2kHandle_t *) - Input/Output - Host - nvjpeg2k library handle ### Request Example ```c nvjpeg2kHandle_t handle; nvjpeg2kStatus_t status = nvjpeg2kCreateV2(NVJPEG2K_BACKEND_DEFAULT, &dev_alloc, &pin_alloc, &handle); ``` ### Response #### Success Response (200) - **status** (nvjpeg2kStatus_t) - An error code as specified in API Return Status Codes #### Response Example ```c NVJPEG2K_STATUS_SUCCESS ``` ``` -------------------------------- ### nvjpeg2kEncode() Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/encodeapi.html Compresses the input image in JPEG2000 format and stores it within encode_state. All GPU tasks will be submitted to the provided stream. The function is asynchronous with respect to the host. ```APIDOC ## nvjpeg2kEncode() ### Description Compresses the input image in JPEG2000 format and stores it within encode_state. All GPU tasks will be submitted to the provided stream. The function is asynchronous with respect to the host. ### Signature ```c nvjpeg2kStatus_t nvjpeg2kEncode(nvjpeg2kEncoder_t enc_handle, nvjpeg2kEncodeState_t encode_state, const nvjpeg2kEncodeParams_t encode_params, const nvjpeg2kImage_t *input_image, cudaStream_t stream); ``` ### Parameters | Parameter | Input/Output | Memory | Description | |---|---|---|---| | nvjpeg2kEncoder_t enc_handle | Input | Host | Encoder handle | | nvjpeg2kEncodeState_t encode_state | Input | Host | Encode State, contains intermediate buffers used for encode | | const nvjpeg2kEncodeParams_t encode_params | Input | Host | Stores parameters that control the encode process | | const nvjpeg2kImage_t *input_image | Input | Host/Device | Input Image. The struct should be on host memory. The image component pointers should point to device memory. See Image Data | | cudaStream_t stream | Input | Host | CUDA stream - used for all device operations | ### Returns `nvjpeg2kStatus_t` - An error code as specified in API Return Status Codes ``` -------------------------------- ### nvjpeg2kCreateSimple signature Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Creates an instance of the library handle with default backend and memory allocators. The handle is an input/output parameter of type nvjpeg2kHandle_t*. ```c nvjpeg2kStatus_t nvjpeg2kCreateSimple(nvjpeg2kHandle_t *handle); ``` -------------------------------- ### nvjpeg2kCreateV2 Source: https://docs.nvidia.com/cuda/nvjpeg2000/apireference.html Creates an nvJPEG2000 library handle with extended custom allocators that accept CUDA streams and user context. ```APIDOC ## nvjpeg2kCreateV2 ### Description Create an nvJPEG2000 library handle with extended custom allocators. Creates an instance of the library using extended allocators that accept CUDA streams and user context. ### Method Function ### Endpoint nvjpeg2kStatus_t nvjpeg2kCreateV2( _nvjpeg2kBackend_t backend_, _nvjpeg2kDeviceAllocatorV2_t *dev_allocator_, _nvjpeg2kPinnedAllocatorV2_t *pinned_allocator_, _nvjpeg2kHandle_t *handle_ ) ### Parameters #### Parameters - **backend** (nvjpeg2kBackend_t) - [in] Backend to use. Currently `NVJPEG2K_BACKEND_DEFAULT` is supported. - **dev_allocator** (nvjpeg2kDeviceAllocatorV2_t*) - [in] See `nvjpeg2kDeviceAllocatorV2_t`. Cannot be `NULL`. - **pinned_allocator** (nvjpeg2kPinnedAllocatorV2_t*) - [in] See `nvjpeg2kPinnedAllocatorV2_t`. Cannot be `NULL`. - **handle** (nvjpeg2kHandle_t*) - [in/out] Pointer to the library handle to initialize. ### Returns An error code as specified in API Return Status Codes. ``` -------------------------------- ### nvjpeg2kDecodeStateCreate() signature Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Creates an instance of the Decode State. The function takes the library handle and a pointer to the decode state handle to be created. ```c nvjpeg2kStatus_t nvjpeg2kDecodeStateCreate( nvjpeg2kHandle_t handle, nvjpeg2kDecodeState_t *decode_state); ``` -------------------------------- ### nvjpeg2kCreate() function signature Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Declares the nvjpeg2kCreate() function, which initializes the nvjpeg2k library with a specified backend and optional device/pinned allocators. The device_allocator and pinned_allocator parameters may be NULL to use default cudaMalloc/cudaFree and cudaHostAlloc/cudaHost functions respectively. Returns an nvjpeg2kStatus_t error code. ```c nvjpeg2kStatus_t nvjpeg2kCreate( nvjpeg2kBackend_t backend, nvjpeg2kDeviceAllocator_t *device_allocator, nvjpeg2kPinnedAllocator_t *pinned_allocator, nvjpeg2kHandle_t *handle); ``` -------------------------------- ### nvjpeg2kEncodeParamsCreate() signature Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Creates an instance of the encode parameters handle. Takes a pointer to nvjpeg2kEncodeParams_t and returns an nvjpeg2kStatus_t error code. ```c nvjpeg2kStatus_t nvjpeg2kEncodeParamsCreate(nvjpeg2kEncodeParams_t *encode_params); ``` -------------------------------- ### nvjpeg2kEncoderCreateSimple() Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Creates an instance of the nvJPEG2000 encoder handle. This function initializes the encoder handle for subsequent encoding operations. ```APIDOC ## nvjpeg2kEncoderCreateSimple() ### Description Creates an instance of the nvJPEG2000 encoder handle. ### Signature ```c nvjpeg2kStatus_t nvjpeg2kEncoderCreateSimple(nvjpeg2kEncoder_t *enc_handle); ``` ### Parameters - **enc_handle** (nvjpeg2kEncoder_t *) - Input/Output - Host - nvJPEG2000 encoder handle ### Returns `nvjpeg2kStatus_t` - An error code as specified in API Return Status Codes ``` -------------------------------- ### nvjpeg2kEncodeStateCreate() Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Creates an instance of the encode state. This function initializes the encode state for use with the specified encoder handle. ```APIDOC ## nvjpeg2kEncodeStateCreate() ### Description Creates an instance of the encode state. ### Signature ```c nvjpeg2kStatus_t nvjpeg2kEncodeStateCreate( nvjpeg2kEncoder_t enc_handle, nvjpeg2kEncodeState_t *encode_state); ``` ### Parameters - **enc_handle** (nvjpeg2kEncoder_t) - Input - Host - nvJPEG2000 encoder handle - **encode_state** (nvjpeg2kEncodeState_t *) - Input/Output - Host - nvJPEG2000 encode state ### Returns `nvjpeg2kStatus_t` - An error code as specified in API Return Status Codes ``` -------------------------------- ### Encode Configuration Struct (nvjpeg2kEncodeConfig_t) Source: https://docs.nvidia.com/cuda/nvjpeg2000/userguide.html Defines the encode configuration structure with parameters from SIZ and COD JPEG2000 headers. Includes fields for stream type, color space, tiling, progression order, and more. ```c typedef struct { nvjpeg2kBitstreamType stream_type; nvjpeg2kColorSpace_t color_space; uint16_t rsiz; uint32_t image_width; uint32_t image_height; uint32_t enable_tiling; uint32_t tile_width; uint32_t tile_height; uint32_t num_components; nvjpeg2kImageComponentInfo_t *image_comp_info; uint32_t enable_SOP_marker; uint32_t enable_EPH_marker; nvjpeg2kProgOrder prog_order; uint32_t num_layers; uint32_t mct_mode; uint32_t num_resolutions; uint32_t code_block_w; uint32_t code_block_h; uint32_t encode_modes; uint32_t irreversible; uint32_t enable_custom_precincts; uint32_t precint_width[NVJPEG2K_MAXRES]; uint32_t precint_height[NVJPEG2K_MAXRES]; } nvjpeg2kEncodeConfig_t; ``` -------------------------------- ### nvjpeg2kStreamCreate() Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Creates an instance of the bitstream handle. This function initializes a new bitstream handle for use in decoding operations. ```APIDOC ## nvjpeg2kStreamCreate() ### Description Creates an instance of the bitstream handle. ### Signature ``` nvjpeg2kStatus_t nvjpeg2kStreamCreate(nvjpeg2kStream_t *stream_handle); ``` ### Parameters - **stream_handle** (nvjpeg2kStream_t *) - Input/Output - Host - nvjpeg2k bitstream handle ### Returns `nvjpeg2kStatus_t` - An error code as specified in API Return Status Codes ``` -------------------------------- ### nvjpeg2kDeviceMallocV2 Source: https://docs.nvidia.com/cuda/nvjpeg2000/userguide.html User-defined callback for allocating device memory with stream and context support. ```APIDOC ## nvjpeg2kDeviceMallocV2 ### Description User-defined callback for allocating device memory, accepting a CUDA stream and user context. Returns 0 on success, non-zero otherwise. ### Type Function pointer typedef ### Signature ```c typedef int (*nvjpeg2kDeviceMallocV2)(void* ctx, void **ptr, size_t size, cudaStream_t stream); ``` ### Parameters - **ctx** (void*) - User context. - **ptr** (void**) - Output pointer to allocated memory. - **size** (size_t) - Size in bytes to allocate. - **stream** (cudaStream_t) - CUDA stream. ### Return Value - **int** - 0 on success, non-zero on failure. ``` -------------------------------- ### nvjpeg2kCreateV2() function signature Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Declares the nvjpeg2kCreateV2() function, which initializes the nvjpeg2k library with extended allocators. Unlike nvjpeg2kCreate(), the device_allocator and pinned_allocator parameters cannot be NULL. Returns an nvjpeg2kStatus_t error code. ```c nvjpeg2kStatus_t nvjpeg2kCreateV2( nvjpeg2kBackend_t backend, nvjpeg2kDeviceAllocatorV2_t*device_allocator, nvjpeg2kPinnedAllocatorV2_t*pinned_allocator, nvjpeg2kHandle_t *handle); ``` -------------------------------- ### nvjpeg2kDeviceAllocatorV2_t Source: https://docs.nvidia.com/cuda/nvjpeg2000/userguide.html Structure for user-provided device allocator callbacks with stream and context support. ```APIDOC ## nvjpeg2kDeviceAllocatorV2_t ### Description Structure that holds user-defined device memory allocation and free callbacks, along with a user context. Can be passed to nvjpeg2kCreateV2(). ### Type Struct ### Definition ```c typedef struct nvjpeg2kDeviceAllocatorV2 { nvjpeg2kDeviceMallocV2 device_malloc; nvjpeg2kDeviceFreeV2 device_free; void *device_ctx; } nvjpeg2kDeviceAllocatorV2_t; ``` ### Fields - **device_malloc** (nvjpeg2kDeviceMallocV2) - Callback for allocating device memory. - **device_free** (nvjpeg2kDeviceFreeV2) - Callback for freeing device memory. - **device_ctx** (void*) - User context passed to callbacks. ``` -------------------------------- ### nvjpeg2kEncoderCreateSimple signature Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Creates an instance of the nvJPEG2000 encoder handle. Takes a pointer to the encoder handle as input/output and returns an nvjpeg2kStatus_t error code. ```c nvjpeg2kStatus_t nvjpeg2kEncoderCreateSimple(nvjpeg2kEncoder_t *enc_handle); ``` -------------------------------- ### nvjpeg2kEncode() signature Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/encodeapi.html Compresses the input image in JPEG2000 format and stores it within encode_state. All GPU tasks are submitted to the provided stream. The function is asynchronous with respect to the host. ```c nvjpeg2kStatus_t nvjpeg2kEncode(nvjpeg2kEncoder_t enc_handle, nvjpeg2kEncodeState_t encode_state, const nvjpeg2kEncodeParams_t encode_params, const nvjpeg2kImage_t *input_image, cudaStream_t stream); ``` -------------------------------- ### nvjpeg2kDeviceFreeV2 Source: https://docs.nvidia.com/cuda/nvjpeg2000/userguide.html User-defined callback for freeing device memory with stream and context support. ```APIDOC ## nvjpeg2kDeviceFreeV2 ### Description User-defined callback for freeing device memory, accepting a CUDA stream and user context. Returns 0 on success, non-zero otherwise. ### Type Function pointer typedef ### Signature ```c typedef int (*nvjpeg2kDeviceFreeV2)(void* ctx, void *ptr, size_t size, cudaStream_t stream); ``` ### Parameters - **ctx** (void*) - User context. - **ptr** (void*) - Pointer to memory to free. - **size** (size_t) - Size in bytes. - **stream** (cudaStream_t) - CUDA stream. ### Return Value - **int** - 0 on success, non-zero on failure. ``` -------------------------------- ### nvjpeg2kDestroy() Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Releases the nvjpeg2k library handle. ```APIDOC ## nvjpeg2kDestroy() ### Description Releases the nvjpeg2k library handle. ### Signature ``` nvjpeg2kStatus_t nvjpeg2kDestroy(nvjpeg2kHandle_t handle); ``` ### Parameters - **nvjpeg2kHandle_t handle** (Input, Host) - nvjpeg2k library handle ### Returns `nvjpeg2kStatus_t` - An error code as specified in API Return Status Codes ``` -------------------------------- ### NVJPEG2K_RSIZ_HT macro Source: https://docs.nvidia.com/cuda/nvjpeg2000/nvjpeg2ktypes.html Set rsiz in nvjpeg2kEncodeConfig_t to NVJPEG2K_RSIZ_HT to enable High throughput JPEG 2000 Encode. ```c #define NVJPEG2K_RSIZ_HT 0x4000 ``` -------------------------------- ### nvjpeg2kDecodeParamsCreate() Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Creates an instance of the decode output parameters handle. This function initializes a new decode parameters handle for configuring decode operations. ```APIDOC ## nvjpeg2kDecodeParamsCreate() ### Description Creates an instance of the decode output parameters handle. ### Signature ``` nvjpeg2kStatus_t nvjpeg2kDecodeParamsCreate(nvjpeg2kDecodeParams_t *decode_params); ``` ### Parameters - **decode_params** (nvjpeg2kDecodeParams_t *) - Input/Output - Host - Decode output parameters handle ### Returns `nvjpeg2kStatus_t` - An error code as specified in API Return Status Codes ``` -------------------------------- ### Allocate device memory and initialize nvjpeg2kImage_t Source: https://docs.nvidia.com/cuda/nvjpeg2000/quickstartguide.html Extracts image component info and allocates device memory for decoded output. Assumes 8-bit precision and 3 components. Initializes nvjpeg2kImage_t with pixel data, type NVJPEG2K_UINT8, and pitch. ```c #define NUM_COMPONENTS 3 // extract image info nvjpeg2kImageInfo_t image_info; nvjpeg2kStreamGetImageInfo(nvjpeg2k_stream, &image_info); // assuming the decoding of images with 8 bit precision, and 3 components nvjpeg2kImageComponentInfo_t image_comp_info[NUM_COMPONENTS]; for (int c = 0; c < image_info.num_components; c++) { nvjpeg2kStreamGetImageComponentInfo(nvjpeg2k_stream, &image_comp_info[c], c); } unsigned char *decode_output[NUM_COMPONENTS]; size_t pitch_in_bytes[NUM_COMPONENTS]; nvjpeg2kImage_t output_image; for (int c = 0; c < NUM_COMPONENTS; c++) { cudaMallocPitch(&decode_output[c], &pitch_in_bytes[c], image_comp_info[c].comp_width, image_comp_info[c].comp_height ); } output_image.pixel_data = decode_output; output_image.pixel_type = NVJPEG2K_UINT8; output_image.pitch_in_bytes = pitch_in_bytes; ``` -------------------------------- ### nvjpeg2kBackend_t enum Source: https://docs.nvidia.com/cuda/nvjpeg2000/nvjpeg2ktypes.html Selects the internal implementation. Currently only NVJPEG2K_BACKEND_DEFAULT is supported. ```c typedef enum { NVJPEG2K_BACKEND_DEFAULT = 0 } nvjpeg2kBackend_t; ``` -------------------------------- ### nvjpeg2kDeviceAllocator_t Source: https://docs.nvidia.com/cuda/nvjpeg2000/nvjpeg2ktypes.html Documentation for the nvjpeg2kDeviceAllocator_t structure, which allows users to provide custom device memory allocation and deallocation functions. ```APIDOC ## nvjpeg2kDeviceAllocator_t ### Description Structure that defines custom device memory allocation and deallocation functions for the NVJPEG2000 library. When passed to nvjpeg2kCreate(), it overrides the default cudaMalloc() and cudaFree() functions. ### Members - **device_malloc** (nvjpeg2kDeviceMalloc) - Required - Function pointer for device memory allocation. Signature: `int (*nvjpeg2kDeviceMalloc)(void**, size_t)`. Should return 0 on success, non-zero otherwise. - **device_free** (nvjpeg2kDeviceFree) - Required - Function pointer for device memory deallocation. Signature: `int (*nvjpeg2kDeviceFree)(void*)`. Should return 0 on success, non-zero otherwise. ### Usage - Pass a pointer to this structure as the `allocator` parameter in `nvjpeg2kCreate()`. If set to NULL, the default `cudaMalloc()` and `cudaFree()` functions are used. - When using `nvjpeg2kCreateSimple()`, the default device memory allocator is used. ### Example ```c typedef int (*nvjpeg2kDeviceMalloc)(void**, size_t); typedef int (*nvjpeg2kDeviceFree)(void*); typedef struct { nvjpeg2kDeviceMalloc device_malloc; nvjpeg2kDeviceFree device_free; } nvjpeg2kDeviceAllocator_t; ``` ``` -------------------------------- ### nvjpeg2kEncodeStateCreate signature Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Creates an instance of the encode state. Takes the encoder handle and a pointer to the encode state as input/output and returns an nvjpeg2kStatus_t error code. ```c nvjpeg2kStatus_t nvjpeg2kEncodeStateCreate( nvjpeg2kEncoder_t enc_handle, nvjpeg2kEncodeState_t *encode_state); ``` -------------------------------- ### nvjpeg2kImageComponentInfo_t struct Source: https://docs.nvidia.com/cuda/nvjpeg2000/nvjpeg2ktypes.html Retrieves component-level information for allocating output buffers. ```c typedef struct { uint32_t component_width; uint32_t component_height; uint8_t precision; uint8_t sgn; } nvjpeg2kImageComponentInfo_t; ``` -------------------------------- ### nvjpeg2kGetDeviceMemoryPadding() Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Retrieves padding for device memory allocations. ```APIDOC ## nvjpeg2kGetDeviceMemoryPadding() ### Description Retrieves padding for device memory allocations. ### Signature ``` nvjpeg2kStatus_t nvjpeg2kGetDeviceMemoryPadding(size_t *padding, nvjpeg2kHandle_t handle); ``` ### Parameters - **size_t *padding** (Input, Host) - Device memory padding currently in use - **nvjpeg2kHandle_t *handle** (Input/Output, Host) - nvjpeg2k library handle ### Returns `nvjpeg2kStatus_t` - An error code as specified in API Return Status Codes ``` -------------------------------- ### nvjpeg2kPinnedMallocV2 Source: https://docs.nvidia.com/cuda/nvjpeg2000/userguide.html User-defined callback for allocating host pinned memory with stream and context support. ```APIDOC ## nvjpeg2kPinnedMallocV2 ### Description User-defined callback for allocating host pinned memory, accepting a CUDA stream and user context. Returns 0 on success, non-zero otherwise. ### Type Function pointer typedef ### Signature ```c typedef int (*nvjpeg2kPinnedMallocV2)(void* ctx, void **ptr, size_t size, cudaStream_t stream); ``` ### Parameters - **ctx** (void*) - User context. - **ptr** (void**) - Output pointer to allocated memory. - **size** (size_t) - Size in bytes to allocate. - **stream** (cudaStream_t) - CUDA stream. ### Return Value - **int** - 0 on success, non-zero on failure. ``` -------------------------------- ### Extended Device Allocator Interface (nvjpeg2kDeviceAllocatorV2) Source: https://docs.nvidia.com/cuda/nvjpeg2000/nvjpeg2ktypes.html Defines the device allocator function pointer types and the nvjpeg2kDeviceAllocatorV2_t struct. Allocators must return 0 on success and non-zero on failure. Pass an instance to the library via nvjpeg2kCreateV2(). ```c typedef int (*nvjpeg2kDeviceMallocV2)(void* ctx, void **ptr, size_t size, cudaStream_t stream); typedef int (*nvjpeg2kDeviceFreeV2)(void* ctx, void *ptr, size_t size, cudaStream_t stream); typedef struct nvjpeg2kDeviceAllocatorV2 { nvjpeg2kDeviceMallocV2 device_malloc; nvjpeg2kDeviceFreeV2 device_free; void *device_ctx; } nvjpeg2kDeviceAllocatorV2_t; ``` -------------------------------- ### nvjpeg2kEncodeParamsCreate Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/helperapi.html Creates an instance of the encode parameters handle. ```APIDOC ## nvjpeg2kEncodeParamsCreate ### Description Creates an instance of the encode parameters handle. ### Signature ``` nvjpeg2kStatus_t nvjpeg2kEncodeParamsCreate(nvjpeg2kEncodeParams_t *encode_params); ``` ### Parameters - **encode_params** (nvjpeg2kEncodeParams_t *) - Input - Host - encode params handle ### Returns `nvjpeg2kStatus_t` - An error code as specified in API Return Status Codes ``` -------------------------------- ### Configure encode parameters for JPEG2000 bitstream Source: https://docs.nvidia.com/cuda/nvjpeg2000/quickstartguide.html Populates nvjpeg2kEncodeConfig_t and calls nvjpeg2kEncodeParamsSetEncodeConfig to generate a JPEG2000 bitstream with reversible wavelet transform and 64x64 code block size. The valid values for each field are documented in the nvjpeg2kEncodeConfig_t reference. ```cpp nvjpeg2kEncodeConfig_t enc_config; memset(&enc_config, 0, sizeof(enc_config)); enc_config.stream_type = NVJPEG2K_STREAM_JP2; // the bitstream will be in JP2 container format enc_config.color_space = NVJPEG2K_COLORSPACE_SRGB; // input image is in RGB format enc_config.image_width = image_width; enc_config.image_height = image_height; enc_config.num_components = NUM_COMPONENTS; enc_config.image_comp_info = &image_comp_info; enc_config.code_block_w = 64; enc_config.code_block_h = 64; enc_config.irreversible = 1; // set to 0 for lossless encode. enc_config.mct_mode = 1; enc_config.prog_order = NVJPEG2K_LRCP; enc_config.num_resolutions = 6; nvjpeg2kStatus_t status = nvjpeg2kEncodeParamsSetEncodeConfig(enc_params, &enc_config); ``` -------------------------------- ### nvjpeg2kEncodeParamsSetEncodeConfig() Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/encodeparamsapi.html Sets the JPEG2000 header parameters defined in nvjpeg2kEncodeConfig_t. Should always be called during the encode process. ```APIDOC ## nvjpeg2kEncodeParamsSetEncodeConfig() ### Description Sets the JPEG2000 header parameters that are defined in nvjpeg2kEncodeConfig_t. This function should always be called during the encode process. ### Signature ```c nvjpeg2kStatus_t nvjpeg2kEncodeParamsSetEncodeConfig( nvjpeg2kEncodeParams_t encode_params, nvjpeg2kEncodeConfig_t* encode_config); ``` ### Parameters - **encode_params** (nvjpeg2kEncodeParams_t) - Input/Output - Host - encode parameters handle - **encode_config** (nvjpeg2kEncodeConfig_t*) - Input - Host - pointer to nvjpeg2kEncodeConfig_t ### Returns `nvjpeg2kStatus_t` - An error code as specified in API Return Status Codes ``` -------------------------------- ### Decode with nvjpeg2kDecode and synchronize Source: https://docs.nvidia.com/cuda/nvjpeg2000/quickstartguide.html Calls nvjpeg2kDecode asynchronously with respect to the host. Pass a cudaStream_t (0 for default stream) to issue asynchronous CUDA calls. Must call cudaDeviceSynchronize() to complete decoding. ```c nvjpeg2kStatus_t status = nvjpeg2kDecode(nvjpeg2k_handle, decode_state, nvjpeg2k_stream, &output_image, 0); // 0 corresponds to cudaStream_t cudaDeviceSynchronize() ``` -------------------------------- ### nvjpeg2kEncodeParamsSpecifyQuality() Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/encodeparamsapi.html Sets the quality type (algorithm) and quality value for encoding. Overwrites any existing quality setting. ```APIDOC ## nvjpeg2kEncodeParamsSpecifyQuality() ### Description This function allows the application to set quality type (algorithm) and quality value, which controls how good encoded image should look. Refer to the Quality Type for the allowed values for each quality type. Will overwrite any existing quality setting. ### Signature ```c nvjpeg2kStatus_t nvjpeg2kEncodeParamsSpecifyQuality( nvjpeg2kEncodeParams_t encode_params, nvjpeg2kQualityType quality_type, double quality_value); ``` ### Parameters - **encode_params** (nvjpeg2kEncodeParams_t) - Input/Output - Host - encode parameters handle - **quality_type** (nvjpeg2kQualityType) - Input - Host - quality type (algorithm) to use - **quality_value** (double) - Input - Host - controls how good image should look. Refer to the Quality Type for allowed values for each quality type. ### Returns `nvjpeg2kStatus_t` - An error code as specified in API Return Status Codes. Will return `NVJPEG2K_STATUS_INVALID_PARAMETER` if: - reversible encode mode is used, - requirements are not met (refer to Quality Type), - `nvjpeg2kEncodeParamsSetEncodeConfig` was not yet called. ``` -------------------------------- ### nvjpeg2kDecode() Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/decodeapi.html Decodes a single image and writes it to the output device buffers. The function is asynchronous with respect to the host, and all GPU tasks are submitted to the provided stream. ```APIDOC ## nvjpeg2kDecode() ### Description Decodes a single image, and writes it to the output device buffers. The function is asynchronous with respect to the host. All GPU tasks will be submitted to the provided `stream`. Prior to calling this function user must parse the bitstream using nvjpeg2kStreamParse() such that the bitstream information is stored in `jpeg2k_stream`. ### Signature ``` nvjpeg2kStatus_t nvjpeg2kDecode(nvjpeg2kHandle_t handle, nvjpeg2kDecodeState_t decode_state, nvjpeg2kStream_t jpeg2k_stream, nvjpeg2kImage_t* decode_output, cudaStream_t stream); ``` ### Parameters | Parameter | Input/Output | Memory | Description | |---|---|---|---| | nvjpeg2kHandle_t handle | Input | Host | library handle | | nvjpeg2kDecodeState_t decode_state | Input | Host | decode state handle | | nvjpeg2kStream_t jpeg2k_stream | Input | Host | nvjpeg2k bitstream handle | | nvjpeg2kImage_t* decode_output | Input/Output | Host | Decode output struct. The struct should be on host memory. The image component pointers should point to device memory. See Image Data | | cudaStream_t stream | Input | Host | Instance of cudaStream_t. Can be set to 0. | ### Returns `nvjpeg2kStatus_t` - An error code as specified in API Return Status Codes ``` -------------------------------- ### nvjpeg2kDeviceAllocatorV2 Source: https://docs.nvidia.com/cuda/nvjpeg2000/nvjpeg2ktypes.html Defines the extended device allocator interface that accepts CUDA streams and user context. Users can pass this allocator to the library via nvjpeg2kCreateV2(). ```APIDOC ## nvjpeg2kDeviceAllocatorV2 ### Description Allows the user to provide device allocators which accept CUDA streams and user context. They will return 0 in case of success, and non-zero otherwise. Extended device allocators can be passed as input to the library using `nvjpeg2kCreateV2()`. ### Type Definitions #### nvjpeg2kDeviceMallocV2 ```c typedef int (*nvjpeg2kDeviceMallocV2)(void* ctx, void **ptr, size_t size, cudaStream_t stream); ``` #### nvjpeg2kDeviceFreeV2 ```c typedef int (*nvjpeg2kDeviceFreeV2)(void* ctx, void *ptr, size_t size, cudaStream_t stream); ``` ### Structure ```c typedef struct nvjpeg2kDeviceAllocatorV2 { nvjpeg2kDeviceMallocV2 device_malloc; nvjpeg2kDeviceFreeV2 device_free; void *device_ctx; } nvjpeg2kDeviceAllocatorV2_t; ``` ### Usage Pass the allocator to the library using `nvjpeg2kCreateV2()`. ``` -------------------------------- ### nvjpeg2kEncodeParamsSetEncodeConfig() signature Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/encodeparamsapi.html Sets the JPEG2000 header parameters defined in nvjpeg2kEncodeConfig_t. Should always be called during the encode process. Takes the encode parameters handle and a pointer to the encode config structure. ```c nvjpeg2kStatus_t nvjpeg2kEncodeParamsSetEncodeConfig( nvjpeg2kEncodeParams_t encode_params, nvjpeg2kEncodeConfig_t* encode_config); ``` -------------------------------- ### Allocating decode buffer for NVJPEG2K_FORMAT_INTERLEAVED Source: https://docs.nvidia.com/cuda/nvjpeg2000/api/decodeparamsapi.html Allocates the decode output buffer for NVJPEG2K_FORMAT_INTERLEAVED. When pixel_type is NVJPEG2K_UINT8, bytes_per_sample=1; for NVJPEG2K_UINT16 or NVJPEG2K_INT16, bytes_per_sample=2. Requires RGB Output to be enabled for 420/422 subsampling. ```c decode_output.pitch_in_bytes[0] = image_width * num_components * bytes_per_sample; decode_output.pixel_data[0] = decode_output.decode_out.pitch_in_bytes[0] * info.image_height; decode_output.num_components = num_components; ``` -------------------------------- ### nvjpeg2kPinnedFreeV2 Source: https://docs.nvidia.com/cuda/nvjpeg2000/userguide.html User-defined callback for freeing host pinned memory with stream and context support. ```APIDOC ## nvjpeg2kPinnedFreeV2 ### Description User-defined callback for freeing host pinned memory, accepting a CUDA stream and user context. Returns 0 on success, non-zero otherwise. ### Type Function pointer typedef ### Signature ```c typedef int (*nvjpeg2kPinnedFreeV2)(void* ctx, void *ptr, size_t size, cudaStream_t stream); ``` ### Parameters - **ctx** (void*) - User context. - **ptr** (void*) - Pointer to memory to free. - **size** (size_t) - Size in bytes. - **stream** (cudaStream_t) - CUDA stream. ### Return Value - **int** - 0 on success, non-zero on failure. ```