AJA NTV2 SDK  17.1.1.1245
NTV2 SDK 17.1.1.1245
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
NTV2EnhancedCSCKeyOutputRange
NTV2EnhancedCSCKeyOutputRange
Definition: ntv2enhancedcsc.h:53
kRegEnhancedCSC8Mode
@ kRegEnhancedCSC8Mode
Definition: ntv2publicinterface.h:982
LWord
int32_t LWord
Definition: ajatypes.h:252
NTV2_Enhanced_CSC_Pixel_Format_YCbCr444
@ NTV2_Enhanced_CSC_Pixel_Format_YCbCr444
Definition: ntv2enhancedcsc.h:18
CNTV2EnhancedCSC::SetKeyInputOffset
bool SetKeyInputOffset(const int16_t inKeyInputOffset)
Definition: ntv2enhancedcsc.cpp:125
CNTV2DriverInterface::ReadRegisters
virtual bool ReadRegisters(NTV2RegisterReads &inOutValues)
Reads the register(s) specified by the given NTV2RegInfo sequence.
Definition: ntv2driverinterface.cpp:414
ConvertCoeffULWordToDouble
static double ConvertCoeffULWordToDouble(const ULWord inCoefficient)
Definition: ntv2enhancedcsc.cpp:26
CNTV2EnhancedCSC::SendToHardware
bool SendToHardware(CNTV2Card &inDevice, const NTV2Channel inChannel) const
Definition: ntv2enhancedcsc.cpp:149
NTV2CSCCoeffIndex_A0
@ NTV2CSCCoeffIndex_A0
Proportion of input component 0 applied to A output.
Definition: ntv2cscmatrix.h:25
NTV2_Enhanced_CSC_Key_Output_Range_Full
@ NTV2_Enhanced_CSC_Key_Output_Range_Full
Definition: ntv2enhancedcsc.h:55
NTV2CSCOffsetIndex_Pre1
@ NTV2CSCOffsetIndex_Pre1
Definition: ntv2cscmatrix.h:42
ntv2devicefeatures.h
Declares device capability functions.
CNTV2MacDriverInterface::ReadRegister
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....
Definition: ntv2macdriverinterface.cpp:389
kK2RegShiftEnhancedCSCKeyOutputRange
@ kK2RegShiftEnhancedCSCKeyOutputRange
Definition: ntv2publicinterface.h:2931
NTV2DeviceCanDoEnhancedCSC
bool NTV2DeviceCanDoEnhancedCSC(const NTV2DeviceID inDeviceID)
Definition: ntv2devicefeatures.hpp:2537
NTV2Channel
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They're also commonly use...
Definition: ntv2enums.h:1305
NTV2CSCOffsetIndex_PostC
@ NTV2CSCOffsetIndex_PostC
Definition: ntv2cscmatrix.h:47
NTV2_Enhanced_CSC_Chroma_Filter_Select_Full
@ NTV2_Enhanced_CSC_Chroma_Filter_Select_Full
Definition: ntv2enhancedcsc.h:27
kK2RegShiftEnhancedCSCChromaFilterSelect
@ kK2RegShiftEnhancedCSCChromaFilterSelect
Definition: ntv2publicinterface.h:2926
NTV2EnhancedCSCChromaEdgeControl
NTV2EnhancedCSCChromaEdgeControl
Definition: ntv2enhancedcsc.h:35
CNTV2EnhancedCSC::SetChromaFilterSelect
bool SetChromaFilterSelect(const NTV2EnhancedCSCChromaFilterSelect inChromaFilterSelect)
Definition: ntv2enhancedcsc.cpp:64
CNTV2EnhancedCSC::SetInputPixelFormat
bool SetInputPixelFormat(const NTV2EnhancedCSCPixelFormat inPixelFormat)
Definition: ntv2enhancedcsc.cpp:32
kK2RegMaskEnhancedCSCKeyOutputRange
@ kK2RegMaskEnhancedCSCKeyOutputRange
Definition: ntv2publicinterface.h:1869
kRegEnhancedCSC1Mode
@ kRegEnhancedCSC1Mode
Definition: ntv2publicinterface.h:854
NTV2DeviceGetNumCSCs
UWord NTV2DeviceGetNumCSCs(const NTV2DeviceID inDeviceID)
Definition: ntv2devicefeatures.hpp:10042
NTV2CSCCoeffIndex_C0
@ NTV2CSCCoeffIndex_C0
Proportion of input component 0 applied to C output.
Definition: ntv2cscmatrix.h:33
kK2RegMaskEnhancedCSCChromaFilterSelect
@ kK2RegMaskEnhancedCSCChromaFilterSelect
Definition: ntv2publicinterface.h:1864
kK2RegShiftEnhancedCSCOutputPixelFormat
@ kK2RegShiftEnhancedCSCOutputPixelFormat
Definition: ntv2publicinterface.h:2924
NTV2RegWrites
std::vector< NTV2RegInfo > NTV2RegWrites
An ordered sequence of zero or more NTV2RegInfo structs intended for WriteRegister.
Definition: ntv2publicinterface.h:4011
CNTV2Card::WriteRegisters
virtual bool WriteRegisters(const NTV2RegisterWrites &inRegWrites)
Writes the given sequence of NTV2RegInfo's.
Definition: ntv2register.cpp:4583
NTV2CSCOffsetIndex_PostA
@ NTV2CSCOffsetIndex_PostA
Definition: ntv2cscmatrix.h:45
CNTV2CSCMatrix::SetOffset
virtual void SetOffset(const NTV2CSCOffsetIndex inOffsetIndex, const int16_t inOffset)
Changes the specified offset to the given value.
Definition: ntv2cscmatrix.cpp:468
kRegEnhancedCSC6Mode
@ kRegEnhancedCSC6Mode
Definition: ntv2publicinterface.h:946
CNTV2EnhancedCSC::SetKeyOutputRange
bool SetKeyOutputRange(const NTV2EnhancedCSCKeyOutputRange inKeyOutputRange)
Definition: ntv2enhancedcsc.cpp:110
CNTV2EnhancedCSC::SetChromaEdgeControl
bool SetChromaEdgeControl(const NTV2EnhancedCSCChromaEdgeControl inChromaEdgeControl)
Definition: ntv2enhancedcsc.cpp:80
gChannelToEnhancedCSCRegNum
static const ULWord gChannelToEnhancedCSCRegNum[]
Definition: ntv2enhancedcsc.cpp:14
CNTV2EnhancedCSC::GetFromHardware
bool GetFromHardware(CNTV2Card &inDevice, const NTV2Channel inChannel)
Definition: ntv2enhancedcsc.cpp:201
NTV2_Enhanced_CSC_Chroma_Edge_Control_Extended
@ NTV2_Enhanced_CSC_Chroma_Edge_Control_Extended
Definition: ntv2enhancedcsc.h:38
ULWord
uint32_t ULWord
Definition: ajatypes.h:253
NTV2_Enhanced_CSC_Chroma_Filter_Select_None
@ NTV2_Enhanced_CSC_Chroma_Filter_Select_None
Definition: ntv2enhancedcsc.h:29
ntv2enhancedcsc.h
Declares the CNTV2EnhancedCSC class.
NTV2_Enhanced_CSC_Pixel_Format_YCbCr422
@ NTV2_Enhanced_CSC_Pixel_Format_YCbCr422
Definition: ntv2enhancedcsc.h:19
NTV2_Enhanced_CSC_Chroma_Edge_Control_Black
@ NTV2_Enhanced_CSC_Chroma_Edge_Control_Black
Definition: ntv2enhancedcsc.h:37
NTV2CSCCoeffIndex_B0
@ NTV2CSCCoeffIndex_B0
Proportion of input component 0 applied to B output.
Definition: ntv2cscmatrix.h:29
NTV2_Enhanced_CSC_Key_Output_Range_SMPTE
@ NTV2_Enhanced_CSC_Key_Output_Range_SMPTE
Definition: ntv2enhancedcsc.h:56
kTwo24th
static const double kTwo24th(double(1<< 24))
UWord
uint16_t UWord
Definition: ajatypes.h:251
NTV2EnhancedCSCPixelFormat
NTV2EnhancedCSCPixelFormat
Definition: ntv2enhancedcsc.h:15
NTV2_Enhanced_CSC_Pixel_Format_RGB444
@ NTV2_Enhanced_CSC_Pixel_Format_RGB444
Definition: ntv2enhancedcsc.h:17
ntv2utils.h
Declares numerous NTV2 utility functions.
kRegEnhancedCSC2Mode
@ kRegEnhancedCSC2Mode
Definition: ntv2publicinterface.h:874
NTV2CSCCoeffIndex_C2
@ NTV2CSCCoeffIndex_C2
Proportion of input component 2 applied to C output.
Definition: ntv2cscmatrix.h:35
CNTV2Card
I interrogate and control an AJA video/audio capture/playout device.
Definition: ntv2card.h:28
kRegEnhancedCSC3Mode
@ kRegEnhancedCSC3Mode
Definition: ntv2publicinterface.h:892
CNTV2CSCMatrix::SetCoefficient
virtual void SetCoefficient(const NTV2CSCCoeffIndex inCoeffIndex, const double inCoefficient)
Changes the specified matrix coefficient to the given value.
Definition: ntv2cscmatrix.cpp:433
kK2RegShiftEnhancedCSCInputPixelFormat
@ kK2RegShiftEnhancedCSCInputPixelFormat
Definition: ntv2publicinterface.h:2923
NTV2CSCCoeffIndex_C1
@ NTV2CSCCoeffIndex_C1
Proportion of input component 1 applied to C output.
Definition: ntv2cscmatrix.h:34
NTV2_Enhanced_CSC_Key_Source_Key_Input
@ NTV2_Enhanced_CSC_Key_Source_Key_Input
Definition: ntv2enhancedcsc.h:46
CNTV2EnhancedCSC::SetOutputPixelFormat
bool SetOutputPixelFormat(const NTV2EnhancedCSCPixelFormat inPixelFormat)
Definition: ntv2enhancedcsc.cpp:48
NTV2_Enhanced_CSC_Key_Spurce_A0_Input
@ NTV2_Enhanced_CSC_Key_Spurce_A0_Input
Definition: ntv2enhancedcsc.h:47
NTV2CSCOffsetIndex_Pre0
@ NTV2CSCOffsetIndex_Pre0
Definition: ntv2cscmatrix.h:41
kK2RegMaskEnhancedCSCKeySource
@ kK2RegMaskEnhancedCSCKeySource
Definition: ntv2publicinterface.h:1868
kRegEnhancedCSC7Mode
@ kRegEnhancedCSC7Mode
Definition: ntv2publicinterface.h:964
CNTV2EnhancedCSC::Matrix
CNTV2CSCMatrix & Matrix(void)
Definition: ntv2enhancedcsc.h:76
NTV2CSCOffsetIndex_Pre2
@ NTV2CSCOffsetIndex_Pre2
Definition: ntv2cscmatrix.h:43
NTV2_Enhanced_CSC_Chroma_Filter_Select_Simple
@ NTV2_Enhanced_CSC_Chroma_Filter_Select_Simple
Definition: ntv2enhancedcsc.h:28
CNTV2EnhancedCSC::SetKeyOutputOffset
bool SetKeyOutputOffset(const uint16_t inKeyOutputOffset)
Definition: ntv2enhancedcsc.cpp:133
ConvertCoeffDoubleToULWord
static ULWord ConvertCoeffDoubleToULWord(const double inCoefficient)
Definition: ntv2enhancedcsc.cpp:20
kK2RegMaskEnhancedCSCChromaEdgeControl
@ kK2RegMaskEnhancedCSCChromaEdgeControl
Definition: ntv2publicinterface.h:1863
kRegNumEnhancedCSCRegisters
@ kRegNumEnhancedCSCRegisters
Definition: ntv2publicinterface.h:872
CNTV2DriverInterface::GetDeviceID
virtual NTV2DeviceID GetDeviceID(void)
Definition: ntv2driverinterface.cpp:381
NTV2EnhancedCSCChromaFilterSelect
NTV2EnhancedCSCChromaFilterSelect
Definition: ntv2enhancedcsc.h:25
kK2RegShiftEnhancedCSCChromaEdgeControl
@ kK2RegShiftEnhancedCSCChromaEdgeControl
Definition: ntv2publicinterface.h:2925
kRegEnhancedCSC5Mode
@ kRegEnhancedCSC5Mode
Definition: ntv2publicinterface.h:928
kK2RegShiftEnhancedCSCKeySource
@ kK2RegShiftEnhancedCSCKeySource
Definition: ntv2publicinterface.h:2930
NTV2RegReads
NTV2RegWrites NTV2RegReads
An ordered sequence of zero or more NTV2RegInfo structs intended for ReadRegister.
Definition: ntv2publicinterface.h:4014
CNTV2EnhancedCSC::SetKeyGain
bool SetKeyGain(const double inKeyGain)
Definition: ntv2enhancedcsc.cpp:141
ntv2publicinterface.h
Declares enums and structs used by all platform drivers and the SDK.
kK2RegMaskEnhancedCSCInputPixelFormat
@ kK2RegMaskEnhancedCSCInputPixelFormat
Definition: ntv2publicinterface.h:1861
NTV2CSCCoeffIndex_B2
@ NTV2CSCCoeffIndex_B2
Proportion of input component 2 applied to B output.
Definition: ntv2cscmatrix.h:31
CNTV2EnhancedCSC::SetKeySource
bool SetKeySource(const NTV2EnhancedCSCKeySource inKeySource)
Definition: ntv2enhancedcsc.cpp:95
NTV2CSCCoeffIndex_A2
@ NTV2CSCCoeffIndex_A2
Proportion of input component 2 applied to A output.
Definition: ntv2cscmatrix.h:27
NTV2EnhancedCSCKeySource
NTV2EnhancedCSCKeySource
Definition: ntv2enhancedcsc.h:44
kK2RegMaskEnhancedCSCOutputPixelFormat
@ kK2RegMaskEnhancedCSCOutputPixelFormat
Definition: ntv2publicinterface.h:1862
NTV2CSCCoeffIndex_A1
@ NTV2CSCCoeffIndex_A1
Proportion of input component 1 applied to A output.
Definition: ntv2cscmatrix.h:26
NTV2RegInfo
Everything needed to call CNTV2Card::ReadRegister or CNTV2Card::WriteRegister functions.
Definition: ntv2publicinterface.h:3931
kRegEnhancedCSC4Mode
@ kRegEnhancedCSC4Mode
Definition: ntv2publicinterface.h:910
NTV2CSCCoeffIndex_B1
@ NTV2CSCCoeffIndex_B1
Proportion of input component 1 applied to B output.
Definition: ntv2cscmatrix.h:30
NTV2CSCOffsetIndex_PostB
@ NTV2CSCOffsetIndex_PostB
Definition: ntv2cscmatrix.h:46