JeVois  1.20
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
jevois::GPUimage Class Reference

#include <jevois/GPU/GPUimage.H>

Class to hold a GPUtexture, GPUprogram, and other data associated with rendering an image in OpenGL.

OpenGL should have been properly setup before this class is used.

Definition at line 38 of file GPUimage.H.

Collaboration diagram for jevois::GPUimage:

Public Member Functions

 GPUimage ()
 Constructor. More...
 
 ~GPUimage ()
 Destructor. More...
 
void set (RawImage const &img)
 Set pixel data from a vanilla RawImage, pixel data will be copied to texture. More...
 
void set (cv::Mat const &img, bool rgb)
 Set pixel data from a vanilla OpenCV Mat, pixel data will be copied to texture. More...
 
void set (InputFrame const &frame, EGLDisplay display)
 Set pixel data from camera input frame, sharing data with camera kernel driver using zero-copy. More...
 
void set2 (InputFrame const &frame, EGLDisplay display)
 Set pixel data from camera input second (scaled) frame, sharing data with camera kernel driver using zero-copy. More...
 
void draw (int &x, int &y, unsigned short &w, unsigned short &h, bool noalias, glm::mat4 const &pvm)
 Draw to OpenGL. More...
 
ImVec2 i2d (ImVec2 const &p)
 Convert coordinates of a point from within a rendered image to on-screen. More...
 
ImVec2 i2ds (ImVec2 const &p)
 Convert a 2D size from within a rendered image to on-screen. More...
 
ImVec2 d2i (ImVec2 const &p)
 Convert coordinates of a point from on-screen to within a rendered image. More...
 
ImVec2 d2is (ImVec2 const &p)
 Convert a 2D size from on-screen to within a rendered image. More...
 
void twirl (float t, float alpha=1.0F)
 Optional twirl and alpha fading effect to the image, useful mostly for demos/transitions. More...
 

Protected Member Functions

void setInternal (unsigned int width, unsigned int height, unsigned int fmt, unsigned char const *data)
 
void setWithDmaBuf (jevois::RawImage const &img, int dmafd, EGLDisplay display)
 

Protected Attributes

EGLDisplay itsDisplay
 
std::shared_ptr< GPUtextureitsTexture
 
std::shared_ptr< GPUprogramitsProgram
 
std::shared_ptr< GPUtextureDmaBufitsTextureDmaBuf
 
GLuint itsLocation = 0
 
GLuint itsVertexArray = 0
 
GLuint itsVertexBuffers [2] = { }
 
int itsDrawX = -1234567
 
int itsDrawY = -6712345
 
unsigned int itsDrawWidth = 0
 
unsigned int itsDrawHeight = 0
 
unsigned int itsTextureWidth = 0
 
unsigned int itsTextureHeight = 0
 
unsigned int itsFormat = 0
 
int itsGLtextureWidth = 0
 
GLenum itsGLtextureFmt = 0
 
GLfloat itsTwirl = 0
 
GLfloat itsAlpha = 0
 

Constructor & Destructor Documentation

◆ GPUimage()

jevois::GPUimage::GPUimage ( )

Constructor.

Definition at line 50 of file GPUimage.C.

◆ ~GPUimage()

jevois::GPUimage::~GPUimage ( )

Destructor.

Definition at line 54 of file GPUimage.C.

Member Function Documentation

◆ d2i()

ImVec2 jevois::GPUimage::d2i ( ImVec2 const &  p)

Convert coordinates of a point from on-screen to within a rendered image.

Throws if draw() has not been previously called.

Definition at line 400 of file GPUimage.C.

Referenced by jevois::GUIhelper::d2i().

◆ d2is()

ImVec2 jevois::GPUimage::d2is ( ImVec2 const &  p)

Convert a 2D size from on-screen to within a rendered image.

Throws if draw() has not been previously called.

Definition at line 407 of file GPUimage.C.

Referenced by jevois::GUIhelper::d2is().

◆ draw()

void jevois::GPUimage::draw ( int &  x,
int &  y,
unsigned short &  w,
unsigned short &  h,
bool  noalias,
glm::mat4 const &  pvm 
)

Draw to OpenGL.

If w=0 or h=0 then the image will be rescaled to fill the display as much as possible without changing the aspect ratio, and the actually used x,y,w,h will be returned. Otherwise, x,y,w,h are not modified. Throws if set() has not been previously called. If noalias is specified, the scaling factor will be rounded down to the nearest integer to prevent aliasing in the display. This may reduce the displayed image size. For example, with a 1920x1080 window, a 640x480 image would be letterboxed to 1440x1080 when noalias is false. But that is a scaling factor of 2.25 which may create rendering aliasing. When noalias is true, the letterboxed image size will be 1280x960 (scale factor of 2.0). The matrix pvm is the projection-view-model matrix to use for rendering.

Definition at line 262 of file GPUimage.C.

References jevois::applyLetterBox(), GL_CHECK, and h.

◆ i2d()

ImVec2 jevois::GPUimage::i2d ( ImVec2 const &  p)

Convert coordinates of a point from within a rendered image to on-screen.

Throws if draw() has not been previously called.

Definition at line 386 of file GPUimage.C.

Referenced by jevois::GUIhelper::i2d().

◆ i2ds()

ImVec2 jevois::GPUimage::i2ds ( ImVec2 const &  p)

Convert a 2D size from within a rendered image to on-screen.

Throws if draw() has not been previously called.

Definition at line 393 of file GPUimage.C.

Referenced by jevois::GUIhelper::i2ds().

◆ set() [1/3]

void jevois::GPUimage::set ( cv::Mat const &  img,
bool  rgb 
)

Set pixel data from a vanilla OpenCV Mat, pixel data will be copied to texture.

If image had three or four 8-bit channels, interpret as RGB[A] if rgb is true, otherwise BGR[A]. If two 8-bit channels, interpret at YUYV. If one, interpret at GRAY. The caller must guarantee that the pixel data will not be de-allocated until after draw() is called.

Definition at line 142 of file GPUimage.C.

References LFATAL.

◆ set() [2/3]

void jevois::GPUimage::set ( jevois::InputFrame const &  frame,
EGLDisplay  display 
)

Set pixel data from camera input frame, sharing data with camera kernel driver using zero-copy.

The caller must guarantee that the pixel data will not be de-allocated (e.g., by calling done() on the InputFrame) until after draw() is called. Zero-copy requires DMABUF sharing between V4L2 and OpenGL-ES and is only available on JeVois-Pro platform. On other hardware configs, this falls back to set(RawImage) using the RawImage from the InputFrame.

Definition at line 160 of file GPUimage.C.

References jevois::RawImage::buf, jevois::RawImage::fmt, jevois::InputFrame::get(), and jevois::RawImage::width.

◆ set() [3/3]

void jevois::GPUimage::set ( jevois::RawImage const &  img)

Set pixel data from a vanilla RawImage, pixel data will be copied to texture.

The caller must guarantee that the pixel data will not be de-allocated until after draw() is called.

Definition at line 136 of file GPUimage.C.

References jevois::RawImage::buf, jevois::RawImage::fmt, jevois::RawImage::height, and jevois::RawImage::width.

◆ set2()

void jevois::GPUimage::set2 ( jevois::InputFrame const &  frame,
EGLDisplay  display 
)

Set pixel data from camera input second (scaled) frame, sharing data with camera kernel driver using zero-copy.

The caller must guarantee that the pixel data will not be de-allocated (e.g., by calling done() on the InputFrame) until after draw() is called. Zero-copy requires DMABUF sharing between V4L2 and OpenGL-ES and is only available on JeVois-Pro platform. On other hardware configs, this falls back to set(RawImage) using the RawImage from the InputFrame. Throws unless we are JeVois-Pro Platform and the camera is set to CropScale mode.

Definition at line 186 of file GPUimage.C.

References jevois::RawImage::buf, jevois::RawImage::fmt, jevois::InputFrame::get2(), and jevois::RawImage::width.

◆ setInternal()

void jevois::GPUimage::setInternal ( unsigned int  width,
unsigned int  height,
unsigned int  fmt,
unsigned char const *  data 
)
protected

◆ setWithDmaBuf()

void jevois::GPUimage::setWithDmaBuf ( jevois::RawImage const &  img,
int  dmafd,
EGLDisplay  display 
)
protected

◆ twirl()

void jevois::GPUimage::twirl ( float  t,
float  alpha = 1.0F 
)

Optional twirl and alpha fading effect to the image, useful mostly for demos/transitions.

Definition at line 414 of file GPUimage.C.

Member Data Documentation

◆ itsAlpha

GLfloat jevois::GPUimage::itsAlpha = 0
protected

Definition at line 123 of file GPUimage.H.

◆ itsDisplay

EGLDisplay jevois::GPUimage::itsDisplay
protected

Definition at line 105 of file GPUimage.H.

◆ itsDrawHeight

unsigned int jevois::GPUimage::itsDrawHeight = 0
protected

Definition at line 117 of file GPUimage.H.

◆ itsDrawWidth

unsigned int jevois::GPUimage::itsDrawWidth = 0
protected

Definition at line 117 of file GPUimage.H.

◆ itsDrawX

int jevois::GPUimage::itsDrawX = -1234567
protected

Definition at line 116 of file GPUimage.H.

◆ itsDrawY

int jevois::GPUimage::itsDrawY = -6712345
protected

Definition at line 116 of file GPUimage.H.

◆ itsFormat

unsigned int jevois::GPUimage::itsFormat = 0
protected

Definition at line 119 of file GPUimage.H.

◆ itsGLtextureFmt

GLenum jevois::GPUimage::itsGLtextureFmt = 0
protected

Definition at line 121 of file GPUimage.H.

◆ itsGLtextureWidth

int jevois::GPUimage::itsGLtextureWidth = 0
protected

Definition at line 120 of file GPUimage.H.

◆ itsLocation

GLuint jevois::GPUimage::itsLocation = 0
protected

Definition at line 112 of file GPUimage.H.

◆ itsProgram

std::shared_ptr<GPUprogram> jevois::GPUimage::itsProgram
protected

Definition at line 107 of file GPUimage.H.

◆ itsTexture

std::shared_ptr<GPUtexture> jevois::GPUimage::itsTexture
protected

Definition at line 106 of file GPUimage.H.

◆ itsTextureDmaBuf

std::shared_ptr<GPUtextureDmaBuf> jevois::GPUimage::itsTextureDmaBuf
protected

Definition at line 110 of file GPUimage.H.

◆ itsTextureHeight

unsigned int jevois::GPUimage::itsTextureHeight = 0
protected

Definition at line 118 of file GPUimage.H.

◆ itsTextureWidth

unsigned int jevois::GPUimage::itsTextureWidth = 0
protected

Definition at line 118 of file GPUimage.H.

◆ itsTwirl

GLfloat jevois::GPUimage::itsTwirl = 0
protected

Definition at line 122 of file GPUimage.H.

◆ itsVertexArray

GLuint jevois::GPUimage::itsVertexArray = 0
protected

Definition at line 113 of file GPUimage.H.

◆ itsVertexBuffers

GLuint jevois::GPUimage::itsVertexBuffers[2] = { }
protected

Definition at line 114 of file GPUimage.H.


The documentation for this class was generated from the following files: