JeVois  1.0
JeVois Smart Embedded Machine Vision Toolkit
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 
18 #include <jevois/Image/RawImage.H>
19 #include <jevois/Util/Utils.H>
20 
21 // ####################################################################################################
23 { }
24 
25 // ####################################################################################################
26 jevois::RawImage::RawImage(unsigned int w, unsigned int h, unsigned int f, std::shared_ptr<VideoBuf> b, size_t bindex) :
27  width(w), height(h), fmt(f), buf(b), bufindex(bindex)
28 { }
29 
30 // ####################################################################################################
31 unsigned int jevois::RawImage::bytesperpix() const
32 { return jevois::v4l2BytesPerPix(fmt); }
33 
34 // ####################################################################################################
35 unsigned int jevois::RawImage::bytesize() const
36 { return width * height * jevois::v4l2BytesPerPix(fmt); }
37 
38 // ####################################################################################################
40 { buf.reset(); width = 0; height = 0; fmt = 0; }
41 
42 // ####################################################################################################
44 { return (buf.get() != nullptr); }
45 
46 // ####################################################################################################
47 void jevois::RawImage::require(char const * info, unsigned int w, unsigned int h, unsigned int f) const
48 {
49  if (w != width || h != height || f != fmt)
50  LFATAL("Incorrect format for RawImage " << info << ": want " << w << 'x' << h << ' ' << jevois::fccstr(f)
51  << " but image is " << width << 'x' << height << ' ' << jevois::fccstr(fmt));
52 }
53 
54 // ####################################################################################################
55 bool jevois::RawImage::coordsOk(int x, int y) const
56 {
57  if (x >= 0 && x < int(width) && y >= 0 && y < int(height)) return true;
58  else return false;
59 }
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:47
void invalidate()
Invalidate the image by zero'ing out the pointer to pixel buffer and the dims and format...
Definition: RawImage.C:39
unsigned int v4l2BytesPerPix(unsigned int fcc)
Return the number of bytes per pixel for a given V4L2_PIX_FMT_...
Definition: Utils.C:43
bool valid() const
Check whether the image has a valid pixel buffer.
Definition: RawImage.C:43
std::string fccstr(unsigned int fcc)
Convert a V4L2 four-cc code (V4L2_PIX_FMT_...) to a 4-char string.
Definition: Utils.C:30
unsigned int bytesize() const
Helper function to get the total number of bytes in the RawImage, i.e., width * height * bytesperpix(...
Definition: RawImage.C:35
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level. ...
Definition: Log.H:205
unsigned int bytesperpix() const
Helper function to get the number of bytes/pixel given the RawImage pixel format. ...
Definition: RawImage.C:31
bool coordsOk(int x, int y) const
Helper function to check that coords are within image bounds.
Definition: RawImage.C:55
RawImage()
Default constructor, uninitialized.
Definition: RawImage.C:22