# NvJPEGDecoder Class Reference
[Image Decode]

Helper class for decoding JPEG images using libjpeg APIs. More...

`#include <NvJpegDecoder.h>`

Inheritance diagram for NvJPEGDecoder:

List of all members.

## Public Member Functions

| ~NvJPEGDecoder ()
int | decodeToFd (int &fd, unsigned char *in_buf, unsigned long in_buf_size, uint32_t &pixfmt, uint32_t &width, uint32_t &height)
| Decodes a JPEG image to hardware buffer memory.
int | decodeToBuffer (NvBuffer **buffer, unsigned char *in_buf, unsigned long in_buf_size, uint32_t *pixfmt, uint32_t *width, uint32_t *height)
| Decodes a JPEG image to software buffer memory.

## Static Public Member Functions

static NvJPEGDecoder * | createJPEGDecoder (const char *comp_name)
| Creates a new JPEG Decoder named comp_name.

## Private Member Functions

| NvJPEGDecoder (const char *comp_name)

## Private Attributes

struct jpeg_decompress_struct | cinfo
struct jpeg_error_mgr | jerr

## Static Private Attributes

static const NvElementProfiler::ProfilerField | valid_fields

## Detailed Description

Helper class for decoding JPEG images using libjpeg APIs.

`NvJPEGDecoder` uses the `libjpeg` APIs for decoding JPEG images. It supports two methods for decoding:

- Decode to a `DMABUF` and return its file descriptor (FD).
- Decode and write data to a NvBuffer object, i.e., software allocated memory (`malloc`).

The jpeg decoder is capable of decoding YUV420, YUV422 and YUV444 jpeg images.

Note:
  Only the `JCS_YCbCr` (YUV420) color space is currently supported.

Definition at line 86 of file NvJpegDecoder.h.

## Constructor & Destructor Documentation

NvJPEGDecoder::~NvJPEGDecoder | ( |  | ) |

Definition at line 63 of file NvJpegDecoder.cpp.

NvJPEGDecoder::NvJPEGDecoder | ( | const char * | comp_name | ) | `[private]`

Definition at line 41 of file NvJpegDecoder.cpp.

## Member Function Documentation

NvJPEGDecoder * NvJPEGDecoder::createJPEGDecoder | ( | const char * | comp_name | ) | `[static]`

Creates a new JPEG Decoder named comp_name.

Returns:
  Reference to the newly created decoder object, or NULL in case of failure during initialization.

Definition at line 52 of file NvJpegDecoder.cpp.

int NvJPEGDecoder::decodeToBuffer | ( | NvBuffer ** | buffer,
|  | unsigned char * | in_buf,
|  | unsigned long | in_buf_size,
|  | uint32_t * | pixfmt,
|  | uint32_t * | width,
|  | uint32_t * | height |
| ) |  |  |

Decodes a JPEG image to software buffer memory.

This method decodes JPEG images in software memory to a specified width and size.

Note:
  The `decodeToBuffer` method is slower than the NvJPEGDecoder::decodeToFd method because it involves conversion from hardware buffer memory to software buffer memory.

Attention:
  The application must free the NvBuffer object.

Parameters:

  `[out]` | buffer | Indicates `NvBuffer` object to contain the decoded image. The object is allocated by the method and the buffer memory is allocated using NvBuffer::allocateMemory.
  `[in]` | in_buf | Specfies a pointer to the memory containing the JPEG.
  `[in]` | in_buf_size | Specifies the size of the input buffer in bytes.
  `[out]` | pixfmt | Indicates a pointer to the v4l2 pixel format of the decoded image.
  `[out]` | width | Indicates a pointer to the width of the decoded image in pixels.
  `[out]` | height | Indicates a pointer to the height of the decoded image in pixels.

Returns:
  0 for success, -1 otherwise.

Definition at line 136 of file NvJpegDecoder.cpp.

int NvJPEGDecoder::decodeToFd | ( | int & | fd,
|  | unsigned char * | in_buf,
|  | unsigned long | in_buf_size,
|  | uint32_t & | pixfmt,
|  | uint32_t & | width,
|  | uint32_t & | height |
| ) |  |  |

Decodes a JPEG image to hardware buffer memory.

This method decodes JPEG images in hardware memory to a specified width and size.

Parameters:

  `[out]` | fd | Indicates the file descriptor (FD) of the hardware buffer.
  `[in]` | in_buf | Specifies a pointer to the memory containing the JPEG image.
  `[in]` | in_buf_size | Specifies the size of the input buffer in bytes.
  `[out]` | pixfmt | Indicates a reference to the v4l2 pixel format of the decoded image.
  `[out]` | width | Indicates a reference to the width of the decoded image in pixels.
  `[out]` | height | Indicates a reference to the height of the decoded image in pixels.

Returns:
  0 for success, -1 otherwise.

Definition at line 70 of file NvJpegDecoder.cpp.

## Member Data Documentation

struct jpeg_decompress_struct NvJPEGDecoder::cinfo `[read, private]`

Definition at line 153 of file NvJpegDecoder.h.

struct jpeg_error_mgr NvJPEGDecoder::jerr `[read, private]`

Definition at line 154 of file NvJpegDecoder.h.

const NvElementProfiler::ProfilerField NvJPEGDecoder::valid_fields `[static, private]`

Initial value:

                NvElementProfiler::PROFILER_FIELD_TOTAL_UNITS |
                NvElementProfiler::PROFILER_FIELD_LATENCIES

Definition at line 156 of file NvJpegDecoder.h.

The documentation for this class was generated from the following files:

- include/NvJpegDecoder.h
- samples/common/classes/NvJpegDecoder.cpp