@@ -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// ----------------------------------------------------------------------------
19451972PlusStatus 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// ----------------------------------------------------------------------------
19612015PlusStatus 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 (¤tNegative) != 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
0 commit comments