Jetson Linux API Reference

38.2 Release
NvJpegDecoder.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2016-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: BSD-3-Clause
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
38 #ifndef __NV_JPEG_DECODER_H__
39 #define __NV_JPEG_DECODER_H__
40 
52 #ifndef TEGRA_ACCELERATE
53 
57 #define TEGRA_ACCELERATE
58 #endif
59 
60 #include <stdio.h>
61 #include "jpeglib.h"
62 #include "NvElement.h"
63 #include "NvBuffer.h"
64 
65 #ifndef MAX_CHANNELS
66 
70 #define MAX_CHANNELS 3
71 #endif
72 
89 {
90 public:
97  static NvJPEGDecoder *createJPEGDecoder(const char *comp_name);
99 
119  int decodeToFd(int &fd,
120  unsigned char *in_buf, unsigned long in_buf_size,
121  uint32_t &pixfmt, uint32_t &width, uint32_t &height);
148  int decodeToBuffer(NvBuffer ** buffer,
149  unsigned char *in_buf, unsigned long in_buf_size,
150  uint32_t *pixfmt, uint32_t *width, uint32_t *height);
151 
158  void disableMjpegDecode();
159 
164  bool isGPUEnabled() { return gpu_enabled; }
165 
173  void setGPUId(uint32_t gpu_id);
174 
182  void setMemType(uint32_t mem_type);
183 
189  void setUseExternalBuffer(bool use_external_buffer);
190 
191 private:
192 
193  NvJPEGDecoder(const char *comp_name);
194  void decodeIndirect(NvBuffer *out_buf, uint32_t pixel_format);
195  void decodeDirect(NvBuffer *out_buf, uint32_t pixel_format);
196  struct jpeg_decompress_struct cinfo;
197  struct jpeg_error_mgr jerr;
198  bool gpu_enabled;
199  int out_fd;
200 
201  static const NvElementProfiler::ProfilerField valid_fields =
204 };
206 #endif
NvJPEGDecoder::createJPEGDecoder
static NvJPEGDecoder * createJPEGDecoder(const char *comp_name)
Creates a new JPEG Decoder named comp_name.
NvJPEGDecoder::setGPUId
void setGPUId(uint32_t gpu_id)
Set GPU ID to be used by decoder.
NvJPEGDecoder
Helper class for decoding JPEG images using libjpeg APIs.
Definition: NvJpegDecoder.h:88
NvElement::comp_name
const char * comp_name
Specifies the name of the component, for debugging.
Definition: NvElement.h:122
NvElementProfiler::ProfilerField
int ProfilerField
Definition: NvElementProfiler.h:79
NvJPEGDecoder::decodeToFd
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.
NvJPEGDecoder::isGPUEnabled
bool isGPUEnabled()
Checks if the GPU node is present returns true for success, false otherwise.
Definition: NvJpegDecoder.h:164
NvJPEGDecoder::disableMjpegDecode
void disableMjpegDecode()
Disable MJPEG decode.
NvElementProfiler::PROFILER_FIELD_LATENCIES
static const ProfilerField PROFILER_FIELD_LATENCIES
Definition: NvElementProfiler.h:83
NvJPEGDecoder::setMemType
void setMemType(uint32_t mem_type)
Set memory type to be used by decoder.
NvJPEGDecoder::decodeToBuffer
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.
NvElement
Every element has a unique name that can be used for identifying the element in debug logs.
Definition: NvElement.h:63
NvElementProfiler::PROFILER_FIELD_TOTAL_UNITS
static const ProfilerField PROFILER_FIELD_TOTAL_UNITS
Definition: NvElementProfiler.h:81
NvBuffer.h
NvJPEGDecoder::setUseExternalBuffer
void setUseExternalBuffer(bool use_external_buffer)
Set use external buffer for decoder output.
NvJPEGDecoder::~NvJPEGDecoder
~NvJPEGDecoder()
NvElement.h
NvBuffer
Class representing a buffer.
Definition: NvBuffer.h:88