Scope
ScopeOverlay.cpp
1 #include "StdAfx.h"
2 #include "ScopeOverlay.h"
3 #include "ScopeImage.h"
4 #include "ScopeMultiImage.h"
5 #include "helpers.h"
6 #include "pixel.h"
7 #include "lut.h"
8 
9 namespace scope {
10 
11 ScopeOverlay::ScopeOverlay(const uint32_t& _lines, const uint32_t& _linewidth)
12  : lines(_lines)
13  , linewidth(_linewidth)
14  , overlay(_lines*_linewidth, 0) {
15  assert( _lines!=0 && _linewidth!=0 );
16 }
17 
18 void ScopeOverlay::Create(ScopeMultiImageCPtr const _multi, const std::vector<ColorProps>& _color_props) {
19  std::lock_guard<std::mutex> lock(mutex);
20  assert( (_color_props.size() == _multi->Channels()) && (lines==_multi->Lines()) && (linewidth==_multi->Linewidth()) );
21 
22  std::fill(std::begin(overlay), std::end(overlay), BGRA8BLACK); // Clear the overlay
23 
24  for ( size_t ch = 0 ; ch < _multi->Channels() ; ch++ ) {
25  ScopeImageU16CPtr chimage = _multi->GetChannel(ch);
26  if ( _color_props.at(ch).Color() != None ) { // save some time...
27  ColorEnum col = _color_props.at(ch).Color();
28  uint16_t ll = _color_props.at(ch).LowerLimit();
29  uint16_t ul = _color_props.at(ch).UpperLimit();
30 
31  ScopeImageConstAccessU16 imagedata(*chimage);
32  auto it = imagedata.GetConstData()->begin();
33 
34  // ~ 185 ms for 1024x1024 (~ 180 without histogram!)
35  std::transform(std::begin(overlay), std::end(overlay), it, std::begin(overlay), [&](BGRA8Pixel& pix, const uint16_t& gray) {
36  return pix + U16ToBGRA8Histo(gray, col, ll, ul);
37  } );
38 
54  }
55  }
56 }
57 
58 void ScopeOverlay::ToD2Bitmap(ID2D1Bitmap* const _d2bitmap) const {
59  std::lock_guard<std::mutex> lock(mutex);
60  FLOAT h = _d2bitmap->GetSize().height;
61  FLOAT w = _d2bitmap->GetSize().width;
62  assert( (_d2bitmap->GetSize().height == lines) && (_d2bitmap->GetSize().width == linewidth) );
63  _d2bitmap->CopyFromMemory(&D2D1::RectU(0,0,linewidth,lines), overlay.data(), linewidth*4); // stride is *4 because 4 bytes per pixel (BGRA)
64 }
65 
66 void ScopeOverlay::Resize(const uint32_t& _lines, const uint32_t& _linewidth) {
67  assert( _lines!=0 && _linewidth!=0 );
68  std::lock_guard<std::mutex> lock(mutex);
69  lines = _lines;
70  linewidth = _linewidth;
72 }
73 
74 uint32_t ScopeOverlay::Lines() const {
75  std::lock_guard<std::mutex> lock(mutex);
76  return lines;
77 }
78 
79 uint32_t ScopeOverlay::Linewidth() const {
80  std::lock_guard<std::mutex> lock(mutex);
81  return linewidth;
82 }
83 
84 }
void ToD2Bitmap(ID2D1Bitmap *const _d2bitmap) const
uint32_t Linewidth() const
virtual void Create(ScopeMultiImageCPtr const _multi, const std::vector< ColorProps > &_color_props)
Creates an overlay from a multi image with the specified color properties per channel.
uint32_t Lines() const
Encapsulated a 4-byte pixel in BGRA format for use with Direct2D.
Definition: pixel.h:38
#define BGRA8BLACK
An opaque black.
Definition: lut.h:108
std::vector< BGRA8Pixel > overlay
vector with pixeldata
Definition: ScopeOverlay.h:27
uint32_t lines
number of lines, y resolution
Definition: ScopeOverlay.h:21
uint32_t linewidth
width of a line, x resolution
Definition: ScopeOverlay.h:24
The BGRA8Pixel struct and various related helpers for color conversions.
This is the include file for standard system include files, or project specific include files that ar...
ScopeOverlay(const uint32_t &_lines=0, const uint32_t &_linewidth=0)
overlay will be initialized with 0s
void Resize(const uint32_t &_lines, const uint32_t &_linewidth)
const std::vector< T > * GetConstData() const
Definition: ScopeImage.h:247
following http://www.mochima.com/articles/LUT/lut_h.html
Various helper functions and classes for Scope.
std::mutex mutex
mutex for protection
Definition: ScopeOverlay.h:30
Gives RAII safe const access (read-only) to the pixeldata of a ScopeImage.
Definition: ScopeImage.h:14