nvJPEG (PDF) - v10.0.130 (older) - Last updated August 25, 2018 - Send Feedback

## nvJPEG Type Declarations

### nvJPEG Memory Allocator Interface

    typedef int (*tDevMalloc)(void**, size_t);
    typedef int (*tDevFree)(void*);
    typedef struct
      {
        tDevMalloc dev_malloc;
        tDevFree dev_free;
      } nvjpegDevAllocator_t;

Users can tell the library to use their own device memory allocator. 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. A pointer to the `nvjpegDevAllocator_t` structure, with properly filled fields, should be provided to the `nvjpegCreate()` function. NULL is accepted, in which case the default memory allocation functions `cudaMalloc()` and `cudaFree()` is used.

When the `nvjpegDevAllocator_t *allocator` parameter in the `nvjpegCreate()` function is set as a pointer to the above `nvjpegDevAllocator_t` structure, then this structure is used for allocating and releasing 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 `nvjpegDevAllocator_t *allocator` parameter in the `nvjpegCreate()` function is set to NULL, then the default memory allocation functions `cudaMalloc()` and `cudaFree()` will be used.

### nvJPEG Opaque Library Handle Struct

    struct nvjpegHandle;
    typedef struct nvjpegHandle* nvjpegHandle_t;

The library handle is used in any consecutive nvJPEG library calls, and should be initialized first.

The library handle is thread safe, and can be used by multiple threads simultaneously.

### nvJPEG Opaque JPEG Decoding State Handle

    struct nvjpegJpegState;
    typedef struct nvjpegJpegState* nvjpegJpegState_t;

The `nvjpegJpegState` structure stores the temporary JPEG information. It should be initialized before any usage. This JPEG state handle can be reused after being used in another decoding. The same JPEG handle should be used across the decoding phases for the same image or batch. Multiple threads are allowed to share the JPEG state handle only when processing same batch during first phase (`nvjpegDecodePhaseOne`) .

### nvJPEG Output Pointer Struct

    typedef struct
      {
        unsigned char * channel[NVJPEG_MAX_COMPONENT];
        unsigned int pitch[NVJPEG_MAX_COMPONENT];
      } nvjpegImage_t;

The `nvjpegImage_t` struct holds the pointers to the output buffers, and holds the corresponding strides of those buffers for the image decoding.

See Single Image Decoding on how to set up the `nvjpegImage_t` struct.