JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
RawImage.C
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
19#include <jevois/Util/Utils.H>
20
21#include <algorithm> // for std::fill
22
23// ####################################################################################################
26
27// ####################################################################################################
28jevois::RawImage::RawImage(unsigned int w, unsigned int h, unsigned int f, float fs,
29 std::shared_ptr<VideoBuf> b, size_t bindex) :
30 width(w), height(h), fmt(f), fps(fs), buf(b), bufindex(bindex)
31{ }
32
33// ####################################################################################################
35{ return jevois::v4l2BytesPerPix(fmt); }
36
37// ####################################################################################################
38unsigned int jevois::RawImage::bytesize() const
39{ return width * height * jevois::v4l2BytesPerPix(fmt); }
40
41// ####################################################################################################
43{ buf.reset(); width = 0; height = 0; fmt = 0; fps = 0.0F; }
44
45// ####################################################################################################
47{ return (buf.get() != nullptr); }
48
49// ####################################################################################################
51{
52 if (valid() == false) LFATAL("Cannot clear because not valid()");
53
54 switch (fmt)
55 {
56 case V4L2_PIX_FMT_YUYV:
57 std::fill(pixelsw<unsigned short>(), pixelsw<unsigned short>() + width * height, jevois::yuyv::Black);
58 break;
59
60 case V4L2_PIX_FMT_MJPEG:
61 break;
62
63 case V4L2_PIX_FMT_GREY:
64 case V4L2_PIX_FMT_SRGGB8:
65#ifdef JEVOIS_PRO
66 case V4L2_PIX_FMT_SBGGR16:
67 case V4L2_PIX_FMT_SGRBG16:
68#endif
69 case V4L2_PIX_FMT_RGB565:
70 case V4L2_PIX_FMT_BGR24:
71 case V4L2_PIX_FMT_RGB24:
72 case V4L2_PIX_FMT_RGB32:
73 memset(pixelsw<void>(), 0, bytesize());
74 break;
75 default: LFATAL("Unsupported pixel format " << jevois::fccstr(fmt));
76 }
77}
78
79// ####################################################################################################
80void jevois::RawImage::require(char const * info, unsigned int w, unsigned int h, unsigned int f) const
81{
82 if (w != width || h != height || f != fmt)
83 LFATAL("Incorrect format for RawImage " << info << ": want " << w << 'x' << h << ' ' << jevois::fccstr(f)
84 << " but image is " << width << 'x' << height << ' ' << jevois::fccstr(fmt));
85}
86
87// ####################################################################################################
88bool jevois::RawImage::coordsOk(int x, int y) const
89{
90 if (x >= 0 && x < int(width) && y >= 0 && y < int(height)) return true;
91 else return false;
92}
int h
Definition GUIhelper.C:2520
bool coordsOk(int x, int y) const
Helper function to check that coords are within image bounds.
Definition RawImage.C:88
RawImage()
Default constructor, uninitialized.
Definition RawImage.C:24
unsigned int bytesize() const
Helper function to get the total number of bytes in the RawImage, i.e., width * height * bytesperpix(...
Definition RawImage.C:38
void invalidate()
Invalidate the image by zero'ing out the pointer to pixel buffer and the dims and format.
Definition RawImage.C:42
unsigned int bytesperpix() const
Helper function to get the number of bytes/pixel given the RawImage pixel format.
Definition RawImage.C:34
void require(char const *info, unsigned int w, unsigned int h, unsigned int f) const
Require a particular image size and format, issue a fatal error message and throw if no match.
Definition RawImage.C:80
void clear()
Clear the pixels to all black.
Definition RawImage.C:50
bool valid() const
Check whether the image has a valid pixel buffer.
Definition RawImage.C:46
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
Definition Log.H:230
unsigned int v4l2BytesPerPix(unsigned int fcc)
Return the number of bytes per pixel for a given V4L2_PIX_FMT_...
Definition Utils.C:141
std::string fccstr(unsigned int fcc)
Convert a V4L2 four-cc code (V4L2_PIX_FMT_...) to a 4-char string.
Definition Utils.C:45
unsigned short constexpr Black
YUYV color value.
Definition RawImage.H:55