AJA NTV2 SDK  18.0.0.2122
NTV2 SDK 18.0.0.2122
ntv2enhancedcsc.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 #include "ntv2publicinterface.h"
9 #include "ntv2enhancedcsc.h"
10 #include "ntv2devicefeatures.h"
11 #include "ntv2utils.h"
12 
13 
16 
17 static const double kTwo24th (double(1 << 24));
18 
19 
20 static ULWord ConvertCoeffDoubleToULWord (const double inCoefficient)
21 {
22  return (ULWord)LWord(inCoefficient * kTwo24th);
23 }
24 
25 
26 static double ConvertCoeffULWordToDouble (const ULWord inCoefficient)
27 {
28  return double(inCoefficient) / kTwo24th;
29 }
30 
31 
33 {
34  switch (inPixelFormat)
35  {
39  mInputPixelFormat = inPixelFormat;
40  break;
41  default:
42  return false;
43  }
44  return true;
45 } // SetInputPixelFormat
46 
47 
49 {
50  switch (inPixelFormat)
51  {
55  mOutputPixelFormat = inPixelFormat;
56  break;
57  default:
58  return false;
59  }
60  return true;
61 } // SetOutputPixelFormat
62 
63 
65 {
66  switch (inChromaFilterSelect)
67  {
71  mChromaFilterSelect = inChromaFilterSelect;
72  break;
73  default:
74  return false;
75  }
76  return true;
77 } // SetChromaFilterSelect
78 
79 
81 {
82  switch (inChromaEdgeControl)
83  {
86  mChromaEdgeControl = inChromaEdgeControl;
87  break;
88  default:
89  return false;
90  }
91  return true;
92 } // SetChromaEdgeControl
93 
94 
96 {
97  switch (inKeySource)
98  {
101  mKeySource = inKeySource;
102  break;
103  default:
104  return false;
105  }
106  return true;
107 } // SetKeySource
108 
109 
111 {
112  switch (inKeyOutputRange)
113  {
116  mKeyOutputRange = inKeyOutputRange;
117  break;
118  default:
119  return false;
120  }
121  return true;
122 } // SetKeyOutputRange
123 
124 
125 bool CNTV2EnhancedCSC::SetKeyInputOffset (const int16_t inKeyInputOffset)
126 {
127  // To do: add some parameter checking
128  mKeyInputOffset = inKeyInputOffset;
129  return true;
130 } // SetKeyInputOffset
131 
132 
133 bool CNTV2EnhancedCSC::SetKeyOutputOffset (const uint16_t inKeyOutputOffset)
134 {
135  // To do: add some parameter checking
136  mKeyOutputOffset = inKeyOutputOffset;
137  return true;
138 } // SetKeyOutputOffset
139 
140 
141 bool CNTV2EnhancedCSC::SetKeyGain (const double inKeyGain)
142 {
143  // To do: add some parameter checking
144  mKeyGain = inKeyGain;
145  return true;
146 } // SetKeyGain
147 
148 
149 bool CNTV2EnhancedCSC::SendToHardware (CNTV2Card & inDevice, const NTV2Channel inChannel) const
150 {
151  if (!::NTV2DeviceCanDoEnhancedCSC(inDevice.GetDeviceID()))
152  return false; // No Enhanced CSCs
153  if (!inDevice.IsOpen ())
154  return false; // Device not open
155  if (UWord(inChannel) >= ::NTV2DeviceGetNumCSCs(inDevice.GetDeviceID()))
156  return false; // Bad CSC index
157 
158  const ULWord cscBaseRegNum(gChannelToEnhancedCSCRegNum[inChannel]);
160 
161  // Read-modify-write only the relevent control bits
162  if (!inDevice.ReadRegister (cscBaseRegNum, cscRegs[0]))
163  return false;
164 
165  cscRegs [0] = (cscRegs[0] & ~kK2RegMaskEnhancedCSCInputPixelFormat) | ULWord(mInputPixelFormat << kK2RegShiftEnhancedCSCInputPixelFormat);
166  cscRegs [0] = (cscRegs[0] & ~kK2RegMaskEnhancedCSCOutputPixelFormat) | ULWord(mOutputPixelFormat << kK2RegShiftEnhancedCSCOutputPixelFormat);
167  cscRegs [0] = (cscRegs[0] & ~kK2RegMaskEnhancedCSCChromaFilterSelect) | ULWord(mChromaFilterSelect << kK2RegShiftEnhancedCSCChromaFilterSelect);
168  cscRegs [0] = (cscRegs[0] & ~kK2RegMaskEnhancedCSCChromaEdgeControl) | ULWord(mChromaEdgeControl << kK2RegShiftEnhancedCSCChromaEdgeControl);
169 
170  cscRegs [1] = (ULWord(Matrix().GetOffset(NTV2CSCOffsetIndex_Pre1)) << 16) | (ULWord(Matrix().GetOffset(NTV2CSCOffsetIndex_Pre0)&0xFFFF));
171 
172  cscRegs [2] = ULWord(Matrix().GetOffset(NTV2CSCOffsetIndex_Pre2));
173 
174  cscRegs [3] = ConvertCoeffDoubleToULWord (Matrix().GetCoefficient (NTV2CSCCoeffIndex_A0));
175  cscRegs [4] = ConvertCoeffDoubleToULWord (Matrix().GetCoefficient (NTV2CSCCoeffIndex_A1));
176  cscRegs [5] = ConvertCoeffDoubleToULWord (Matrix().GetCoefficient (NTV2CSCCoeffIndex_A2));
177  cscRegs [6] = ConvertCoeffDoubleToULWord (Matrix().GetCoefficient (NTV2CSCCoeffIndex_B0));
178  cscRegs [7] = ConvertCoeffDoubleToULWord (Matrix().GetCoefficient (NTV2CSCCoeffIndex_B1));
179  cscRegs [8] = ConvertCoeffDoubleToULWord (Matrix().GetCoefficient (NTV2CSCCoeffIndex_B2));
180  cscRegs [9] = ConvertCoeffDoubleToULWord (Matrix().GetCoefficient (NTV2CSCCoeffIndex_C0));
181  cscRegs [10] = ConvertCoeffDoubleToULWord (Matrix().GetCoefficient (NTV2CSCCoeffIndex_C1));
182  cscRegs [11] = ConvertCoeffDoubleToULWord (Matrix().GetCoefficient (NTV2CSCCoeffIndex_C2));
183  cscRegs [12] = (ULWord(Matrix().GetOffset (NTV2CSCOffsetIndex_PostB)) << 16) | (ULWord(Matrix().GetOffset (NTV2CSCOffsetIndex_PostA)&0xFFFF));
184  cscRegs [13] = ULWord(Matrix().GetOffset (NTV2CSCOffsetIndex_PostC));
187  cscRegs [15] = (ULWord(mKeyOutputOffset) << 16) | ULWord(mKeyInputOffset);
188  cscRegs [16] = (ULWord(mKeyGain * 4096.0));
189 
190  NTV2RegInfo regInfo;
191  NTV2RegWrites regs;
192  regs.reserve(size_t(kRegNumEnhancedCSCRegisters));
193  for (ULWord num(0); num < kRegNumEnhancedCSCRegisters; num++)
194  regs.push_back(NTV2RegInfo(cscBaseRegNum+num, cscRegs[num]));
195 
196  return inDevice.WriteRegisters(regs);
197 
198 } // SendToHardware
199 
200 
201 bool CNTV2EnhancedCSC::GetFromHardware (CNTV2Card & inDevice, const NTV2Channel inChannel)
202 {
203  if (!::NTV2DeviceCanDoEnhancedCSC(inDevice.GetDeviceID()))
204  return false; // No Enhanced CSCs
205  if (!inDevice.IsOpen ())
206  return false; // Device not open
207  if (UWord(inChannel) >= ::NTV2DeviceGetNumCSCs(inDevice.GetDeviceID()))
208  return false; // Bad CSC index
209 
210  const ULWord cscBaseRegNum(gChannelToEnhancedCSCRegNum[inChannel]);
211  NTV2RegReads regs;
212  regs.reserve(size_t(kRegNumEnhancedCSCRegisters));
213  for (ULWord ndx(0); ndx < kRegNumEnhancedCSCRegisters; ndx++)
214  regs.push_back(NTV2RegInfo(cscBaseRegNum + ndx));
215 
216  if (!inDevice.ReadRegisters(regs))
217  return false; // Read failure
218 
219  // Check that all registers were read successfully
220  if (regs.size() != size_t(kRegNumEnhancedCSCRegisters))
221  return false; // Read failure
222 
227 
228  Matrix().SetOffset (NTV2CSCOffsetIndex_Pre0, int16_t(regs[1].registerValue & 0xFFFF));
229  Matrix().SetOffset (NTV2CSCOffsetIndex_Pre1, int16_t(regs[1].registerValue >> 16));
230  Matrix().SetOffset (NTV2CSCOffsetIndex_Pre2, int16_t(regs[2].registerValue & 0xFFFF));
231 
235 
239 
243 
244  Matrix().SetOffset (NTV2CSCOffsetIndex_PostA, int16_t(regs[12].registerValue & 0xFFFF));
245  Matrix().SetOffset (NTV2CSCOffsetIndex_PostB, int16_t(regs[12].registerValue >> 16));
246  Matrix().SetOffset (NTV2CSCOffsetIndex_PostC, int16_t(regs[13].registerValue & 0xFFFF));
247 
250 
251  mKeyInputOffset = int16_t(regs[15].registerValue & 0xFFFF);
252  mKeyOutputOffset= uint16_t(regs[15].registerValue >> 16);
253  mKeyGain = (double(regs[16].registerValue) / 4096.0);
254  return true;
255 
256 } // GetFromaHardware
Everything needed to call CNTV2Card::ReadRegister or CNTV2Card::WriteRegister functions.
bool SetKeyGain(const double inKeyGain)
virtual void SetOffset(const NTV2CSCOffsetIndex inOffsetIndex, const int16_t inOffset)
Changes the specified offset to the given value.
I interrogate and control an AJA video/audio capture/playout device.
Definition: ntv2card.h:28
Proportion of input component 1 applied to C output.
Definition: ntv2cscmatrix.h:34
bool NTV2DeviceCanDoEnhancedCSC(const NTV2DeviceID inDeviceID)
int32_t LWord
Definition: ajatypes.h:222
bool GetFromHardware(CNTV2Card &inDevice, const NTV2Channel inChannel)
UWord NTV2DeviceGetNumCSCs(const NTV2DeviceID inDeviceID)
bool SetKeyOutputRange(const NTV2EnhancedCSCKeyOutputRange inKeyOutputRange)
Proportion of input component 1 applied to A output.
Definition: ntv2cscmatrix.h:26
uint32_t ULWord
Definition: ajatypes.h:223
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They&#39;re also commonly use...
Definition: ntv2enums.h:1357
std::vector< NTV2RegInfo > NTV2RegWrites
An ordered sequence of zero or more NTV2RegInfo structs intended for WriteRegister.
Proportion of input component 1 applied to B output.
Definition: ntv2cscmatrix.h:30
virtual bool WriteRegisters(const NTV2RegisterWrites &inRegWrites)
Writes the given sequence of NTV2RegInfo&#39;s.
virtual bool IsOpen(void) const
virtual bool ReadRegisters(NTV2RegisterReads &inOutValues)
Reads the register(s) specified by the given NTV2RegInfo sequence.
bool SetOutputPixelFormat(const NTV2EnhancedCSCPixelFormat inPixelFormat)
static const double kTwo24th(double(1<< 24))
virtual NTV2DeviceID GetDeviceID(void)
static ULWord ConvertCoeffDoubleToULWord(const double inCoefficient)
virtual bool ReadRegister(const ULWord inRegNum, ULWord &outValue, const ULWord inMask=0xFFFFFFFF, const ULWord inShift=0)
Reads all or part of the 32-bit contents of a specific register (real or virtual) on the AJA device...
NTV2EnhancedCSCKeyOutputRange
NTV2EnhancedCSCChromaFilterSelect
bool SetChromaEdgeControl(const NTV2EnhancedCSCChromaEdgeControl inChromaEdgeControl)
NTV2EnhancedCSCChromaEdgeControl
Proportion of input component 0 applied to C output.
Definition: ntv2cscmatrix.h:33
Declares numerous NTV2 utility functions.
bool SetKeySource(const NTV2EnhancedCSCKeySource inKeySource)
Proportion of input component 0 applied to B output.
Definition: ntv2cscmatrix.h:29
NTV2EnhancedCSCKeySource
uint16_t UWord
Definition: ajatypes.h:221
static double ConvertCoeffULWordToDouble(const ULWord inCoefficient)
Proportion of input component 0 applied to A output.
Definition: ntv2cscmatrix.h:25
NTV2EnhancedCSCPixelFormat
static const ULWord gChannelToEnhancedCSCRegNum[]
bool SetKeyInputOffset(const int16_t inKeyInputOffset)
CNTV2CSCMatrix & Matrix(void)
Proportion of input component 2 applied to C output.
Definition: ntv2cscmatrix.h:35
virtual void SetCoefficient(const NTV2CSCCoeffIndex inCoeffIndex, const double inCoefficient)
Changes the specified matrix coefficient to the given value.
bool SendToHardware(CNTV2Card &inDevice, const NTV2Channel inChannel) const
Proportion of input component 2 applied to A output.
Definition: ntv2cscmatrix.h:27
Declares the CNTV2EnhancedCSC class.
NTV2RegWrites NTV2RegReads
An ordered sequence of zero or more NTV2RegInfo structs intended for ReadRegister.
Declares enums and structs used by all platform drivers and the SDK.
bool SetKeyOutputOffset(const uint16_t inKeyOutputOffset)
Declares device capability functions.
Proportion of input component 2 applied to B output.
Definition: ntv2cscmatrix.h:31
bool SetChromaFilterSelect(const NTV2EnhancedCSCChromaFilterSelect inChromaFilterSelect)
bool SetInputPixelFormat(const NTV2EnhancedCSCPixelFormat inPixelFormat)