PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
PlusOutputVideoFrame.cxx
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2 Program: Plus
3 Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4 See License.txt for details.
5 =========================================================Plus=header=end*/
6 
7 // Local includes
8 #include "PlusOutputVideoFrame.h"
9 
10 //----------------------------------------------------------------------------
11 PlusOutputVideoFrame::PlusOutputVideoFrame(long width, long height, BMDPixelFormat pixelFormat, BMDFrameFlags frameFlags)
12  : Width(width)
13  , Height(height)
14  , PixelFormat(pixelFormat)
15  , FrameFlags(frameFlags)
16 {
17  this->Pixels = new unsigned char[this->Height * this->GetRowBytes()];
18 }
19 
20 //----------------------------------------------------------------------------
22 {
23  delete [] this->Pixels;
24  this->Pixels = nullptr;
25 }
26 
27 //----------------------------------------------------------------------------
28 long STDMETHODCALLTYPE PlusOutputVideoFrame::GetWidth()
29 {
30  return this->Width;
31 }
32 
33 //----------------------------------------------------------------------------
34 long STDMETHODCALLTYPE PlusOutputVideoFrame::GetHeight()
35 {
36  return this->Height;
37 }
38 
39 //----------------------------------------------------------------------------
40 long STDMETHODCALLTYPE PlusOutputVideoFrame::GetRowBytes()
41 {
42  switch (this->PixelFormat)
43  {
44  case bmdFormat8BitYUV:
45  {
46  return sizeof(char) * 2 * this->Width;
47  }
48  case bmdFormat10BitYUV:
49  {
50  // TBImplemented
51  break;
52  }
53  case bmdFormat8BitARGB:
54  {
55  return sizeof(char) * 4 * this->Width;
56  }
57  case bmdFormat8BitBGRA:
58  {
59  return sizeof(char) * 4 * this->Width;
60  }
61  case bmdFormat10BitRGB:
62  {
63  // TBImplemented
64  break;
65  }
66  case bmdFormat12BitRGB:
67  {
68  // TBImplemented
69  break;
70  }
71  case bmdFormat12BitRGBLE:
72  {
73  // TBImplemented
74  break;
75  }
76  case bmdFormat10BitRGBXLE:
77  {
78  // TBImplemented
79  break;
80  }
81  case bmdFormat10BitRGBX:
82  {
83  // TBImplemented
84  break;
85  }
86  case bmdFormatH265:
87  {
88  // TBImplemented
89  break;
90  }
91  case bmdFormatDNxHR:
92  {
93  // TBImplemented
94  break;
95  }
96  case bmdFormat12BitRAWGRBG:
97  {
98  // TBImplemented
99  break;
100  }
101  case bmdFormat12BitRAWJPEG:
102  {
103  // TBImplemented
104  break;
105  }
106  }
107 
108  return -1;
109 }
110 
111 //----------------------------------------------------------------------------
112 BMDPixelFormat STDMETHODCALLTYPE PlusOutputVideoFrame::GetPixelFormat()
113 {
114  return this->PixelFormat;
115 }
116 
117 //----------------------------------------------------------------------------
118 BMDFrameFlags STDMETHODCALLTYPE PlusOutputVideoFrame::GetFlags()
119 {
120  return this->FrameFlags;
121 }
122 
123 //----------------------------------------------------------------------------
124 void STDMETHODCALLTYPE PlusOutputVideoFrame::SetFlags(BMDFrameFlags flags)
125 {
126  this->FrameFlags = flags;
127 }
128 
129 //----------------------------------------------------------------------------
130 HRESULT STDMETHODCALLTYPE PlusOutputVideoFrame::GetBytes(void** buffer)
131 {
132  this->Mutex.lock();
133  *buffer = Pixels;
134  this->Mutex.unlock();
135 
136  return S_OK;
137 }
138 
139 //----------------------------------------------------------------------------
140 HRESULT STDMETHODCALLTYPE PlusOutputVideoFrame::QueryInterface(REFIID iid, LPVOID* ppv)
141 {
142  HRESULT result = E_NOINTERFACE;
143 
144  if (ppv == NULL)
145  {
146  return E_INVALIDARG;
147  }
148 
149  // Initialize the return result
150  *ppv = NULL;
151 
152  // Obtain the IUnknown interface and compare it the provided REFIID
153  if (iid == IID_IUnknown)
154  {
155  *ppv = this;
156  AddRef();
157  result = S_OK;
158  }
159  else if (iid == IID_IDeckLinkVideoFrame)
160  {
161  *ppv = (IDeckLinkVideoFrame*)this;
162  AddRef();
163  result = S_OK;
164  }
165 
166  return result;
167 }
168 
169 //----------------------------------------------------------------------------
171 {
172  return ++ReferenceCount;
173 }
174 
175 //----------------------------------------------------------------------------
177 {
178  ULONG newRefValue;
179 
180  ReferenceCount--;
181  newRefValue = ReferenceCount;
182  if (newRefValue == 0)
183  {
184  delete this;
185  return 0;
186  }
187 
188  return newRefValue;
189 }
virtual void STDMETHODCALLTYPE SetFlags(BMDFrameFlags flags)
virtual long STDMETHODCALLTYPE GetWidth()
virtual ULONG STDMETHODCALLTYPE AddRef()
PlusOutputVideoFrame(long width, long height, BMDPixelFormat pixelFormat, BMDFrameFlags frameFlags)
virtual HRESULT STDMETHODCALLTYPE GetBytes(void **buffer)
PhidgetLCD_Font int * width
Definition: phidget22.h:4275
virtual long STDMETHODCALLTYPE GetRowBytes()
const char int const char int flags
Definition: phidget22.h:2552
unsigned long ULONG
Definition: ATC3DGm.h:432
PhidgetLCD_Font int int * height
Definition: phidget22.h:4275
virtual long STDMETHODCALLTYPE GetHeight()
virtual BMDFrameFlags STDMETHODCALLTYPE GetFlags()
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv)
virtual BMDPixelFormat STDMETHODCALLTYPE GetPixelFormat()
std::atomic< ULONG > ReferenceCount
virtual ULONG STDMETHODCALLTYPE Release()