Jetson Linux API Reference

32.7.5 Release
NvJPEGEncoder Class Reference

Detailed Description

NvJpegEncoder uses the libjpeg APIs for decoding JPEG images.

It supports two methods for encoding:

  • Encode using a file descriptor (FD) of the MMAP buffer created by a V4L2 element (supports YUV420 and NV12 color formats).
  • Encode using data pointers in NvBuffer object, i.e., software allocated memory (malloc); supports YUV420 color format.
Note
Only the JCS_YCbCr (YUV420) color space is currently supported.

Definition at line 85 of file NvJpegEncoder.h.

Inheritance diagram for NvJPEGEncoder:
Collaboration diagram for NvJPEGEncoder:

Public Member Functions

 ~NvJPEGEncoder ()
 
int encodeFromFd (int fd, J_COLOR_SPACE color_space, unsigned char **out_buf, unsigned long &out_buf_size, int quality=75)
 Encodes a JPEG image from a file descriptor (FD) of hardware buffer memory. More...
 
int encodeFromBuffer (NvBuffer &buffer, J_COLOR_SPACE color_space, unsigned char **out_buf, unsigned long &out_buf_size, int quality=75)
 Encodes a JPEG image from software buffer memory. More...
 
void setCropRect (uint32_t left, uint32_t top, uint32_t width, uint32_t height)
 Sets the cropping rectangle used by the JPEG encoder. More...
 
void setScaledEncodeParams (uint32_t scale_width, uint32_t scale_height)
 Sets scaling parameters by which image needs to be scaled and encoded. More...
 
virtual int isInError ()
 Indicates whether the element encountered an error during its operation. More...
 
void getProfilingData (NvElementProfiler::NvElementProfilerData &data)
 Gets profiling data for the element. More...
 
void printProfilingStats (std::ostream &out_stream=std::cout)
 Prints profiling data for the element to an output stream. More...
 
virtual void enableProfiling ()
 Enables profiling for the element. More...
 
bool isProfilingEnabled ()
 Checks whether profiling is enabled for the element. More...
 

Static Public Member Functions

static NvJPEGEncodercreateJPEGEncoder (const char *comp_name)
 Creates a new JPEG encoder named comp_name. More...
 

Protected Attributes

int is_in_error
 Indicates if an error was encountered during the operation of the element. More...
 
const char * comp_name
 Specifies the name of the component, for debugging. More...
 
NvElementProfiler profiler
 Profiler for the element. More...
 

Constructor & Destructor Documentation

◆ ~NvJPEGEncoder()

NvJPEGEncoder::~NvJPEGEncoder ( )

Member Function Documentation

◆ createJPEGEncoder()

static NvJPEGEncoder* NvJPEGEncoder::createJPEGEncoder ( const char *  comp_name)
static

Creates a new JPEG encoder named comp_name.

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

◆ enableProfiling()

virtual void NvElement::enableProfiling ( )
virtualinherited

Enables profiling for the element.

Reimplemented in NvV4l2Element.

◆ encodeFromBuffer()

int NvJPEGEncoder::encodeFromBuffer ( NvBuffer buffer,
J_COLOR_SPACE  color_space,
unsigned char **  out_buf,
unsigned long &  out_buf_size,
int  quality = 75 
)

Encodes a JPEG image from software buffer memory.

The application may allocate the memory for storing the JPEG image. If the allocation is less than what is required, libjpeg allocates more memory. The out_buf pointer and out_buf_size are updated accordingly.

The encodeFromBuffer method is slower than NvJPEGEncoder::encodeFromFd because encodeFromBuffer involves conversion from software buffer memory to hardware buffer memory.

Supports the YUV420 format only.

Attention
The application must free the out_buf memory.
Parameters
[out]bufferIndicates the NvBuffer object to contain the encoded image.
[out]color_spaceIndicates the color_space to use for encoding.
[in]out_bufSpecifies a pointer to the memory for the JPEG image.
[in]out_buf_sizeSpecifies the size of the output buffer in bytes.
[in]qualitySets the image quality.
Returns
0 for success, -1 otherwise.

◆ encodeFromFd()

int NvJPEGEncoder::encodeFromFd ( int  fd,
J_COLOR_SPACE  color_space,
unsigned char **  out_buf,
unsigned long &  out_buf_size,
int  quality = 75 
)

Encodes a JPEG image from a file descriptor (FD) of hardware buffer memory.

The application may allocate the memory for storing the JPEG image. If the allocation is less than what is required, libjpeg allocates more memory. The out_buf pointer and out_buf_size are updated accordingly.

Supports YUV420 and NV12 formats.

Attention
The application must free the out_buf memory.
Parameters
[out]fdIndicates the file descriptor (FD) of the hardware buffer.
[out]color_spaceIndicates the color_space to use for encoding.
[in]out_bufSpecifies a pointer to the memory for the JPEG image.
[in]out_buf_sizeSpecifies the size of the output buffer in bytes.
[in]qualitySets the image quality.
Returns
0 for success, -1 otherwise.

◆ getProfilingData()

void NvElement::getProfilingData ( NvElementProfiler::NvElementProfilerData data)
inherited

Gets profiling data for the element.

Returns
A constant reference to the element's profiling data.

◆ isInError()

virtual int NvElement::isInError ( )
inlinevirtualinherited

Indicates whether the element encountered an error during its operation.

Returns
0 if no error was encountered, a non-zero value if an error was encountered.

Reimplemented in NvV4l2Element.

Definition at line 72 of file NvElement.h.

References NvElement::is_in_error.

◆ isProfilingEnabled()

bool NvElement::isProfilingEnabled ( )
inherited

Checks whether profiling is enabled for the element.

Returns
Boolean value indicating if profiling is enabled.

◆ printProfilingStats()

void NvElement::printProfilingStats ( std::ostream &  out_stream = std::cout)
inherited

Prints profiling data for the element to an output stream.

Parameters
[in]out_streamOutput stream of type std::ostream to print the data to. It takes the default value std::cout if not specified.

◆ setCropRect()

void NvJPEGEncoder::setCropRect ( uint32_t  left,
uint32_t  top,
uint32_t  width,
uint32_t  height 
)

Sets the cropping rectangle used by the JPEG encoder.

This method must be called before encodeFromFd or encodeFromBuffer for the cropping to take effect.

Attention
The JPEG encoder resets the crop paramaters after each call to jpeg_finish_compress. Therefore, this method must be called before every call to encodeFromFd or encodeFromBuffer.
Parameters
[in]leftHorizontal offset of the cropping rectangle, in pixels.
[in]topVertical offset of the cropping rectangle, in pixels.
[in]widthWidth of the cropping rectangle, in pixels.
[in]heightHeight of the cropping rectangle, in pixels.

◆ setScaledEncodeParams()

void NvJPEGEncoder::setScaledEncodeParams ( uint32_t  scale_width,
uint32_t  scale_height 
)

Sets scaling parameters by which image needs to be scaled and encoded.

This method must be called before encodeFromFd or encodeFromBuffer for scaled encoding to take effect.

Parameters
[in]scale_widthSpecifies width of the scaled image.
[in]scale_heightSpecifies height of the scaled image.

Field Documentation

◆ comp_name

const char* NvElement::comp_name
protectedinherited

Specifies the name of the component, for debugging.

Definition at line 122 of file NvElement.h.

◆ is_in_error

int NvElement::is_in_error
protectedinherited

Indicates if an error was encountered during the operation of the element.

Definition at line 120 of file NvElement.h.

Referenced by NvElement::isInError().

◆ profiler

NvElementProfiler NvElement::profiler
protectedinherited

Profiler for the element.

Definition at line 124 of file NvElement.h.


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