- Main Page
- Modules
- Namespaces
- Classes
- Files

- Search for |

- File List
- File Members

# include/NvJpegDecoder.h

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
    00003  *
    00004  * Redistribution and use in source and binary forms, with or without
    00005  * modification, are permitted provided that the following conditions
    00006  * are met:
    00007  *  * Redistributions of source code must retain the above copyright
    00008  *    notice, this list of conditions and the following disclaimer.
    00009  *  * Redistributions in binary form must reproduce the above copyright
    00010  *    notice, this list of conditions and the following disclaimer in the
    00011  *    documentation and/or other materials provided with the distribution.
    00012  *  * Neither the name of NVIDIA CORPORATION nor the names of its
    00013  *    contributors may be used to endorse or promote products derived
    00014  *    from this software without specific prior written permission.
    00015  *
    00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
    00017  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    00019  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    00020  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    00021  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    00022  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    00023  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
    00024  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    00026  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00027  */
    00028
    00029 /**
    00030  * @file
    00031  * <b>NVIDIA Eagle Eye API: Image Decode API</b>
    00032  *
    00033  * @b Description: This file declares the NvJpegDecoder APIs.
    00034  */
    00035
    00036 #ifndef __NV_JPEG_DECODER_H__
    00037 #define __NV_JPEG_DECODER_H__
    00038
    00039 /**
    00040  *
    00041  * @defgroup ee_nvjpegdecoder_group Image Decode
    00042  * @ingroup ee_nvimage_group
    00043  *
    00044  * The NvJPEGDecoder API provides functionality for decoding JPEG
    00045  * images using libjpeg APIs.
    00046  *
    00047  * @{
    00048  */
    00049
    00050 #ifndef TEGRA_ACCELERATE
    00051 /**
    00052  * @c TEGRA_ACCELERATE must be defined to enable hardware-accelerated
    00053  * JPEG decoding.
    00054  */
    00055 #define TEGRA_ACCELERATE
    00056 #endif
    00057
    00058 #include <stdio.h>
    00059 #include "jpeglib.h"
    00060 #include "NvElement.h"
    00061 #include "NvBuffer.h"
    00062
    00063 #ifndef MAX_CHANNELS
    00064 /**
    00065  * Specifies the maximum number of channels to be used with the
    00066  * decoder.
    00067  */
    00068 #define MAX_CHANNELS 3
    00069 #endif
    00070
    00071 /**
    00072  * @brief Helper class for decoding JPEG images using libjpeg APIs.
    00073  *
    00074  * @c %NvJPEGDecoder uses the @c libjpeg APIs for decoding JPEG images. It
    00075  * supports two methods for decoding:
    00076  *
    00077  * - Decode to a @c DMABUF and return its file descriptor (FD).
    00078  * - Decode and write data to a NvBuffer object, i.e., software allocated
    00079  *    memory (@c malloc).
    00080  *
    00081  * The jpeg decoder is capable of decoding YUV420, YUV422 and YUV444 jpeg images.
    00082  *
    00083  * @note Only the @c JCS_YCbCr (YUV420) color space is currently
    00084  * supported.
    00085  */
    00086 class NvJPEGDecoder:public NvElement
    00087 {
    00088 public:
    00089     /**
    00090      * Creates a new JPEG Decoder named @a comp_name.
    00091      *
    00092      * @return Reference to the newly created decoder object, or NULL
    00093      *          in case of failure during initialization.
    00094      */
    00095     static NvJPEGDecoder *createJPEGDecoder(const char *comp_name);
    00096      ~NvJPEGDecoder();
    00097
    00098     /**
    00099      * Decodes a JPEG image to hardware buffer memory.
    00100      *
    00101      * This method decodes JPEG images in hardware memory to a
    00102      * specified width and size.
    00103      *
    00104      * @param[out] fd Indicates the file descriptor (FD) of the hardware buffer.
    00105      * @param[in] in_buf Specifies a pointer to the memory containing
    00106      *                   the JPEG image.
    00107      * @param[in] in_buf_size Specifies the size of the input buffer in bytes.
    00108      * @param[out] pixfmt Indicates a reference to the v4l2 pixel format
    00109      *                    of the decoded image.
    00110      * @param[out] width Indicates a reference to the width of the
    00111      *                   decoded image in pixels.
    00112      * @param[out] height Indicates a reference to the height of the
    00113      *             decoded image in pixels.
    00114
    00115      * @return 0 for success, -1 otherwise.
    00116      */
    00117     int decodeToFd(int &fd,
    00118                      unsigned char *in_buf, unsigned long in_buf_size,
    00119                      uint32_t &pixfmt, uint32_t &width, uint32_t &height);
    00120     /**
    00121      * Decodes a JPEG image to software buffer memory.
    00122      *
    00123      * This method decodes JPEG images in software memory to a
    00124      * specified width and size.
    00125      *
    00126      * @note The @c decodeToBuffer method is slower than the
    00127      * NvJPEGDecoder::decodeToFd method because it involves conversion
    00128      * from hardware buffer memory to software buffer memory.
    00129      *
    00130      * @attention The application must free the NvBuffer object.
    00131      *
    00132      * @param[out] buffer Indicates @c %NvBuffer object to contain the
    00133      *                    decoded image. The object is allocated by
    00134      *                    the method and the buffer memory is
    00135      *                    allocated using NvBuffer::allocateMemory.
    00136      * @param[in] in_buf Specfies a pointer to the memory containing the JPEG.
    00137      * @param[in] in_buf_size Specifies the size of the input buffer in bytes.
    00138      * @param[out] pixfmt Indicates a pointer to the v4l2 pixel format
    00139      *                    of the decoded image.
    00140      * @param[out] width Indicates a pointer to the width of the decoded image
    00141      *                   in pixels.
    00142      * @param[out] height Indicates a pointer to the height of the decoded image
    00143      *                    in pixels.
    00144      * @return 0 for success, -1 otherwise.
    00145      */
    00146     int decodeToBuffer(NvBuffer ** buffer,
    00147                          unsigned char *in_buf, unsigned long in_buf_size,
    00148                          uint32_t *pixfmt, uint32_t *width, uint32_t *height);
    00149
    00150 private:
    00151
    00152     NvJPEGDecoder(const char *comp_name);
    00153     struct jpeg_decompress_struct cinfo;
    00154     struct jpeg_error_mgr jerr;
    00155
    00156     static const NvElementProfiler::ProfilerField valid_fields =
    00157             NvElementProfiler::PROFILER_FIELD_TOTAL_UNITS |
    00158             NvElementProfiler::PROFILER_FIELD_LATENCIES;
    00159 };
    00160 #endif
    00161 /** @} */