JeVois  1.20
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Jpeg.H
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 #pragma once
19 
20 #include <jevois/Types/Singleton.H>
21 #include <jevois/Image/RawImage.H>
22 #include <opencv2/core/core.hpp>
23 
24 namespace jevois
25 {
26  /*! \defgroup jpeg Jpeg-related classes and functions
27 
28  Jpeg classes and functions, mainly used to support sending MJPEG video output over USB from raw uncompressed
29  images captured by a camera.
30 
31  \ingroup image */
32 
33  /*! @{ */ // **********************************************************************
34 
35  //! Helper to convert from packed YUYV to planar YUV422
36  /*! Memory must have been allocated by caller. */
37  void convertYUYVtoYUV422(unsigned char const * src, int width, int height, unsigned char * dst);
38 
39  //! Simple singleton wrapper over a turbojpeg compressor
40  /*! Most users should not need to use this class, compressBRGtoJpeg() uses it internally to avoid re-creating the
41  turbojpeg compressor object on each video frame. */
42  class JpegCompressor : public Singleton<JpegCompressor>
43  {
44  public:
45  //! Constructor, create the turbojpeg object
47 
48  //! Destructor, frees the turbojpeg object
49  virtual ~JpegCompressor();
50 
51  //! Access the compressor handle
52  void * compressor();
53 
54  private:
55  void * itsCompressor;
56  };
57 
58  //! Compress raw pixel buffer to jpeg
59  /*! The compressed size is returned. The dst buffer should have been allocated by caller, with size at least width *
60  height * 2 bytes. quality should be between 1 (worst) and 100 (best). */
61  unsigned long compressBGRtoJpeg(unsigned char const * src, int width, int height, unsigned char * dst,
62  int quality = 75);
63 
64  //! Compress a BGR cv::Mat into an output JPEG jevois::RawImage
65  /*! The dst RawImage should have an allocated buffer, typically this is intended for use with a RawImage that was
66  obtained from the UVC gadget. */
67  void compressBGRtoJpeg(cv::Mat const & src, RawImage & dst, int quality = 75);
68 
69  //! Compress raw pixel buffer to jpeg
70  /*! The compressed size is returned. The dst buffer should have been allocated by caller, with size at least width *
71  height * 2 bytes. quality should be between 1 (worst) and 100 (best). */
72  unsigned long compressRGBtoJpeg(unsigned char const * src, int width, int height, unsigned char * dst,
73  int quality = 75);
74 
75  //! Compress a RGB cv::Mat into an output JPEG jevois::RawImage
76  /*! The dst RawImage should have an allocated buffer, typically this is intended for use with a RawImage that was
77  obtained from the UVC gadget. */
78  void compressRGBtoJpeg(cv::Mat const & src, RawImage & dst, int quality = 75);
79 
80  //! Compress raw pixel buffer to jpeg
81  /*! The compressed size is returned. The dst buffer should have been allocated by caller, with size at least width *
82  height * 2 bytes. quality should be between 1 (worst) and 100 (best). */
83  unsigned long compressRGBAtoJpeg(unsigned char const * src, int width, int height, unsigned char * dst,
84  int quality = 75);
85 
86  //! Compress an RGBA cv::Mat into an output JPEG jevois::RawImage
87  /*! The dst RawImage should have an allocated buffer, typically this is intended for use with a RawImage that was
88  obtained from the UVC gadget. */
89  void compressRGBAtoJpeg(cv::Mat const & src, RawImage & dst, int quality = 75);
90 
91  //! Compress raw pixel buffer to jpeg
92  /*! The compressed size is returned. The dst buffer should have been allocated by caller, with size at least width *
93  height * 2 bytes. quality should be between 1 (worst) and 100 (best). */
94  unsigned long compressGRAYtoJpeg(unsigned char const * src, int width, int height, unsigned char * dst,
95  int quality = 75);
96  //! Compress a Gray cv::Mat into an output JPEG jevois::RawImage
97  /*! The dst RawImage should have an allocated buffer, typically this is intended for use with a RawImage that was
98  obtained from the UVC gadget. */
99  void compressGRAYtoJpeg(cv::Mat const & src, RawImage & dst, int quality = 75);
100 
101  /*! @} */ // **********************************************************************
102 
103 } // namespace jevois
jevois::JpegCompressor::~JpegCompressor
virtual ~JpegCompressor()
Destructor, frees the turbojpeg object.
Definition: Jpeg.C:27
RawImage.H
jevois::RawImage
A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget.
Definition: RawImage.H:110
jevois::compressBGRtoJpeg
unsigned long compressBGRtoJpeg(unsigned char const *src, int width, int height, unsigned char *dst, int quality=75)
Compress raw pixel buffer to jpeg.
Definition: Jpeg.C:52
jevois::compressRGBtoJpeg
unsigned long compressRGBtoJpeg(unsigned char const *src, int width, int height, unsigned char *dst, int quality=75)
Compress raw pixel buffer to jpeg.
Definition: Jpeg.C:66
jevois::JpegCompressor::JpegCompressor
JpegCompressor()
Constructor, create the turbojpeg object.
Definition: Jpeg.C:23
jevois::JpegCompressor::compressor
void * compressor()
Access the compressor handle.
Definition: Jpeg.C:31
jevois::convertYUYVtoYUV422
void convertYUYVtoYUV422(unsigned char const *src, int width, int height, unsigned char *dst)
Helper to convert from packed YUYV to planar YUV422.
Definition: Jpeg.C:35
jevois::JpegCompressor
Simple singleton wrapper over a turbojpeg compressor.
Definition: Jpeg.H:42
jevois
Definition: Concepts.dox:1
jevois::compressRGBAtoJpeg
unsigned long compressRGBAtoJpeg(unsigned char const *src, int width, int height, unsigned char *dst, int quality=75)
Compress raw pixel buffer to jpeg.
Definition: Jpeg.C:80
jevois::compressGRAYtoJpeg
unsigned long compressGRAYtoJpeg(unsigned char const *src, int width, int height, unsigned char *dst, int quality=75)
Compress raw pixel buffer to jpeg.
Definition: Jpeg.C:94
Singleton.H
jevois::Singleton
A generic singleton class to enforce a single instance of an object.
Definition: Singleton.H:91