Jetson Linux API Reference

38.2 Release
NvJpegEncoder.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_ENCODER_H__
39 #define __NV_JPEG_ENCODER_H__
40 
53 #ifndef TEGRA_ACCELERATE
54 
58 #define TEGRA_ACCELERATE
59 #endif
60 
61 #include <stdio.h>
62 #include "jpeglib.h"
63 #include "NvElement.h"
64 #include "NvBuffer.h"
65 
66 #ifndef MAX_CHANNELS
67 
71 #define MAX_CHANNELS 3
72 #endif
73 
88 {
89 public:
96  static NvJPEGEncoder *createJPEGEncoder(const char *comp_name);
98 
120  int encodeFromFd(int fd, J_COLOR_SPACE color_space,
121  unsigned char **out_buf, unsigned long &out_buf_size,
122  int quality = 75);
123 
149  int encodeFromBuffer(NvBuffer & buffer, J_COLOR_SPACE color_space,
150  unsigned char **out_buf, unsigned long &out_buf_size,
151  int quality = 75);
152 
167  void setCropRect(uint32_t left, uint32_t top, uint32_t width,
168  uint32_t height);
169 
170 
179  void setScaledEncodeParams(uint32_t scale_width, uint32_t scale_height);
180 
185  bool isGPUEnabled() { return gpu_enabled; }
186 
194  void setGPUId(uint32_t gpu_id);
195 
203  void setMemType(uint32_t mem_type);
204 
205 private:
206 
207  NvJPEGEncoder(const char *comp_name);
208  struct jpeg_compress_struct cinfo;
209  struct jpeg_error_mgr jerr;
210  bool gpu_enabled;
211 
212  static const NvElementProfiler::ProfilerField valid_fields =
215 };
216 #endif
217 
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
NvJPEGEncoder::isGPUEnabled
bool isGPUEnabled()
Checks if the GPU node is present returns true for success, false otherwise.
Definition: NvJpegEncoder.h:185
NvJPEGEncoder::setMemType
void setMemType(uint32_t mem_type)
Set memory type to be used by encoder.
NvJPEGEncoder::setGPUId
void setGPUId(uint32_t gpu_id)
Set GPU ID to be used by encoder.
NvJPEGEncoder::setScaledEncodeParams
void setScaledEncodeParams(uint32_t scale_width, uint32_t scale_height)
Sets scaling parameters by which image needs to be scaled and encoded.
NvJPEGEncoder
NvJpegEncoder uses the libjpeg APIs for decoding JPEG images.
Definition: NvJpegEncoder.h:87
NvJPEGEncoder::~NvJPEGEncoder
~NvJPEGEncoder()
NvElementProfiler::PROFILER_FIELD_LATENCIES
static const ProfilerField PROFILER_FIELD_LATENCIES
Definition: NvElementProfiler.h:83
NvJPEGEncoder::encodeFromBuffer
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.
NvJPEGEncoder::setCropRect
void setCropRect(uint32_t left, uint32_t top, uint32_t width, uint32_t height)
Sets the cropping rectangle used by the JPEG encoder.
NvJPEGEncoder::encodeFromFd
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.
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
NvElement.h
NvJPEGEncoder::createJPEGEncoder
static NvJPEGEncoder * createJPEGEncoder(const char *comp_name)
Creates a new JPEG encoder named comp_name.
NvBuffer
Class representing a buffer.
Definition: NvBuffer.h:88