Skip to content

Commit 2eda76f

Browse files
committed
BUG: Fix Telemed SetNegative always failing with "not connected to hardware interface"
IID_IUsgPaletteCalculator was being requested through m_data_view->GetControlObj(), the same path used for scan-mode-bound controls (TGC, rejection, etc.). But IUsgPaletteCalculator is a standalone COM object, not a data-view control, so the lookup always returned NULL and SetNegative()/GetNegative() failed on every startup regardless of hardware state. Create the palette calculator via CoCreateInstance instead, and obtain the actual palette control via IID_IUsgPalette. SetNegative() now computes grayscale palette entries with the calculator and pushes them to the palette control; GetNegative() tracks the locally-applied state since it isn't independently queryable from the device. Also set SpeckleReductionEnabled to int since it is used as a tri-state value (-1 unset, 0/1 FALSE/TRUE)
1 parent 8b7d3d4 commit 2eda76f

3 files changed

Lines changed: 77 additions & 21 deletions

File tree

‎src/PlusDataCollection/Telemed/TelemedUltrasound.cxx‎

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ TelemedUltrasound::TelemedUltrasound()
4646
m_b_image_enhancement_ctrl = NULL;
4747
m_b_rejection_ctrl = NULL;
4848
m_b_image_orientation_ctrl = NULL;
49-
m_b_palette_calculator_ctrl = NULL;
49+
m_b_palette_ctrl = NULL;
5050
m_b_tgc_ctrl = NULL;
51+
m_palette_calculator = NULL;
52+
m_negative = false;
5153
m_usg_control_change_cpnt = NULL;
5254
m_usg_control_change_cpnt_cookie = 0;
5355
m_usg_device_change_cpnt = NULL;
@@ -651,16 +653,40 @@ void TelemedUltrasound::CreateUsgControls(int probeId /* = 0 */)
651653
m_b_image_orientation_ctrl = NULL;
652654
}
653655

654-
// create B mode palette calculator control (for negative rendering)
656+
// create B mode palette control (for applying negative/palette values to the live image)
655657
tmp_obj = NULL;
656-
CreateUsgControl(m_data_view, IID_IUsgPaletteCalculator, SCAN_MODE_B, 0, (void**)&tmp_obj);
658+
CreateUsgControl(m_data_view, IID_IUsgPalette, SCAN_MODE_B, 0, (void**)&tmp_obj);
657659
if (tmp_obj != NULL)
658660
{
659-
m_b_palette_calculator_ctrl = (IUsgPaletteCalculator*)tmp_obj;
661+
m_b_palette_ctrl = (IUsgPalette*)tmp_obj;
660662
}
661663
else
662664
{
663-
m_b_palette_calculator_ctrl = NULL;
665+
m_b_palette_ctrl = NULL;
666+
}
667+
668+
// create palette calculator helper object. Unlike the controls above, this is a standalone COM
669+
// object (not obtained via m_data_view->GetControlObj) used to compute grayscale palette values
670+
// (gamma/brightness/contrast/negative); the computed values are then pushed to m_b_palette_ctrl.
671+
hr = CoCreateInstance(CLSID_UsgPaletteCalculator, NULL, CLSCTX_INPROC_SERVER, IID_IUsgPaletteCalculator, (LPVOID*)&m_palette_calculator);
672+
if (hr != S_OK)
673+
{
674+
m_palette_calculator = NULL;
675+
}
676+
else
677+
{
678+
// Initialize with an identity reference palette (linear grayscale ramp) and neutral gamma/brightness/contrast
679+
const LONG paletteSize = 256;
680+
std::vector<LONG> referenceData(paletteSize);
681+
for (LONG i = 0; i < paletteSize; ++i)
682+
{
683+
referenceData[i] = i;
684+
}
685+
m_palette_calculator->SetReferenceData(paletteSize - 1, paletteSize, referenceData.data());
686+
m_palette_calculator->put_Gamma(100);
687+
m_palette_calculator->put_Brightness(0);
688+
m_palette_calculator->put_Contrast(0);
689+
m_palette_calculator->put_Negative(m_negative ? TRUE : FALSE);
664690
}
665691

666692
// create B mode TGC (time-gain-compensation) control
@@ -1057,7 +1083,8 @@ void TelemedUltrasound::ReleaseUsgControls(bool release_usgfw2)
10571083
SAFE_RELEASE(m_b_image_enhancement_ctrl);
10581084
SAFE_RELEASE(m_b_rejection_ctrl);
10591085
SAFE_RELEASE(m_b_image_orientation_ctrl);
1060-
SAFE_RELEASE(m_b_palette_calculator_ctrl);
1086+
SAFE_RELEASE(m_b_palette_ctrl);
1087+
SAFE_RELEASE(m_palette_calculator);
10611088
SAFE_RELEASE(m_b_tgc_ctrl);
10621089
SAFE_RELEASE(m_mixer_control);
10631090
SAFE_RELEASE(m_data_view);
@@ -1944,34 +1971,57 @@ PlusStatus TelemedUltrasound::GetRejection(int& rejection)
19441971
//----------------------------------------------------------------------------
19451972
PlusStatus TelemedUltrasound::SetNegative(bool enabled)
19461973
{
1947-
if (m_b_palette_calculator_ctrl == NULL)
1974+
if (m_palette_calculator == NULL || m_b_palette_ctrl == NULL)
19481975
{
1949-
LOG_ERROR("TelemedUltrasound::SetNegative failed: not connected to hardware interface");
1976+
LOG_ERROR("TelemedUltrasound::SetNegative failed: palette control not available");
19501977
return PLUS_FAIL;
19511978
}
1952-
if (m_b_palette_calculator_ctrl->put_Negative(enabled ? TRUE : FALSE) != S_OK)
1979+
1980+
if (m_palette_calculator->put_Negative(enabled ? TRUE : FALSE) != S_OK)
19531981
{
1954-
LOG_ERROR("TelemedUltrasound::SetNegative failed: unable to set value on device");
1982+
LOG_ERROR("TelemedUltrasound::SetNegative failed: unable to set negative flag on palette calculator");
19551983
return PLUS_FAIL;
19561984
}
1985+
1986+
const LONG paletteSize = 256;
1987+
std::vector<LONG> calculated(paletteSize);
1988+
if (m_palette_calculator->Calculate(0, paletteSize, calculated.data()) != S_OK)
1989+
{
1990+
LOG_ERROR("TelemedUltrasound::SetNegative failed: unable to calculate palette values");
1991+
return PLUS_FAIL;
1992+
}
1993+
1994+
std::vector<PALETTEENTRY> paletteEntries(paletteSize);
1995+
for (LONG i = 0; i < paletteSize; ++i)
1996+
{
1997+
BYTE value = (BYTE)calculated[i];
1998+
paletteEntries[i].peRed = value;
1999+
paletteEntries[i].peGreen = value;
2000+
paletteEntries[i].peBlue = value;
2001+
paletteEntries[i].peFlags = 0;
2002+
}
2003+
2004+
if (m_b_palette_ctrl->SetPaletteEntries(0, paletteSize, paletteEntries.data()) != S_OK)
2005+
{
2006+
LOG_ERROR("TelemedUltrasound::SetNegative failed: unable to apply palette to B mode image");
2007+
return PLUS_FAIL;
2008+
}
2009+
2010+
m_negative = enabled;
19572011
return PLUS_SUCCESS;
19582012
}
19592013

19602014
//----------------------------------------------------------------------------
19612015
PlusStatus TelemedUltrasound::GetNegative(bool& enabled)
19622016
{
1963-
if (m_b_palette_calculator_ctrl == NULL)
1964-
{
1965-
LOG_ERROR("TelemedUltrasound::GetNegative failed: not connected to hardware interface");
1966-
return PLUS_FAIL;
1967-
}
1968-
BOOL currentNegative = FALSE;
1969-
if (m_b_palette_calculator_ctrl->get_Negative(&currentNegative) != S_OK)
2017+
if (m_palette_calculator == NULL || m_b_palette_ctrl == NULL)
19702018
{
1971-
LOG_ERROR("TelemedUltrasound::GetNegative failed: unable to query value from device");
2019+
LOG_ERROR("TelemedUltrasound::GetNegative failed: palette control not available");
19722020
return PLUS_FAIL;
19732021
}
1974-
enabled = (currentNegative != FALSE);
2022+
// The applied negative state is not independently queryable from the device; it is tracked
2023+
// locally since it is entirely driven by what this class last computed and pushed via SetNegative.
2024+
enabled = m_negative;
19752025
return PLUS_SUCCESS;
19762026
}
19772027

‎src/PlusDataCollection/Telemed/TelemedUltrasound.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,15 @@ class TelemedUltrasound : public IUsgDeviceChangeSink
122122
IUsgImageEnhancement* m_b_image_enhancement_ctrl;
123123
IUsgRejection2* m_b_rejection_ctrl;
124124
IUsgImageOrientation* m_b_image_orientation_ctrl;
125-
IUsgPaletteCalculator* m_b_palette_calculator_ctrl;
125+
IUsgPalette* m_b_palette_ctrl;
126126
IUsgTgc* m_b_tgc_ctrl;
127127

128+
// Palette calculator is a standalone helper COM object (not bound to the data view/scan mode,
129+
// unlike the controls above) used to compute grayscale palette values (gamma/brightness/contrast/
130+
// negative), which must then be pushed to m_b_palette_ctrl to actually affect the live image.
131+
IUsgPaletteCalculator* m_palette_calculator;
132+
bool m_negative;
133+
128134
IConnectionPoint* m_usg_device_change_cpnt; // connection point for device change events
129135
DWORD m_usg_device_change_cpnt_cookie;
130136

‎src/PlusDataCollection/Telemed/vtkPlusTelemedVideoSource.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class vtkPlusDataCollectionExport vtkPlusTelemedVideoSource : public vtkPlusUsDe
191191
double PowerDb;
192192
double FocusDepthPercent;
193193
std::vector<double> TimeGainCompensation;
194-
bool SpeckleReductionEnabled;
194+
int SpeckleReductionEnabled;
195195
int SpeckleReductionMethod;
196196
int DynamicFocusEnabled;
197197
int FocusesNumber;

0 commit comments

Comments
 (0)