Setting palette color LUT data and attributes Example for C++ 6.0 and later
//This example will set the attributes and the data for a
// Palette Color Lookup Table
long lLUTIndex;
short iRet;
VARIANT vRedLUTData;
VARIANT vGreenLUTData;
VARIANT vBlueLUTData;
ILPaletteColorLUTAttributesPtr pPaletteColorLUTAttributes = NULL;
pPaletteColorLUTAttributes = m_pLEADDicomDS->GetPaletteColorLUTAttributes ();
// Initialize Red Palette Color Lookup Table Descriptor (0028,1101)
pPaletteColorLUTAttributes->RedLUTDescriptorFirstMapped = 0;
pPaletteColorLUTAttributes->RedLUTDescriptorEntryBits = 16;
pPaletteColorLUTAttributes->RedLUTDescriptorNumberOfEntries = 0x10000;
// Initialize Green Palette Color Lookup Table Descriptor (0028,1102)
pPaletteColorLUTAttributes->GreenLUTDescriptorFirstMapped = 0;
pPaletteColorLUTAttributes->GreenLUTDescriptorEntryBits = 16;
pPaletteColorLUTAttributes->GreenLUTDescriptorNumberOfEntries = 0x10000;
// Initialize Blue Palette Color Lookup Table Descriptor (0028,1103)
pPaletteColorLUTAttributes->BlueLUTDescriptorFirstMapped = 0;
pPaletteColorLUTAttributes->BlueLUTDescriptorEntryBits = 16;
pPaletteColorLUTAttributes->BlueLUTDescriptorNumberOfEntries = 0x10000;
// Allocate a buffer to hold Red Palette Color Lookup Table Data
SAFEARRAY* psaRedLUTData = SafeArrayCreateVector(VT_I4, 0, 0x10000);
// Allocate a buffer to hold Green Palette Color Lookup Table Data
SAFEARRAY* psaGreenLUTData = SafeArrayCreateVector(VT_I4, 0, 0x10000);
// Allocate a buffer to hold Red Palette Color Lookup Table Data
SAFEARRAY* psaBlueLUTData = SafeArrayCreateVector(VT_I4, 0, 0x10000);
for(lLUTIndex=0; lLUTIndex<=0xFFFF; lLUTIndex++)
{
HRESULT hr;
long iVal;
iVal = (long)lLUTIndex;
hr = SafeArrayPutElement(psaRedLUTData, &lLUTIndex, (void*)&iVal);
iVal = (long)(lLUTIndex/2);
hr = SafeArrayPutElement(psaGreenLUTData, &lLUTIndex, (void*)&iVal);
iVal = (long)(lLUTIndex/4);
hr = SafeArrayPutElement(psaBlueLUTData, &lLUTIndex, (void*)&iVal);
}
// Delete all the elements that describe the "Palette Color Lookup Table".
iRet = m_pLEADDicomDS->DeletePaletteColorLUT(0);
if(iRet != 0)
{
SafeArrayDestroy(psaRedLUTData);
SafeArrayDestroy(psaGreenLUTData);
SafeArrayDestroy(psaBlueLUTData);
AfxMessageBox("error");
return;
}
// Set the new "Palette Color Lookup Table" attributes
iRet = m_pLEADDicomDS->SetPaletteColorLUTAttributes (0);
if(iRet != 0)
{
SafeArrayDestroy(psaRedLUTData);
SafeArrayDestroy(psaGreenLUTData);
SafeArrayDestroy(psaBlueLUTData);
AfxMessageBox("error");
return;
}
// Set Red Palette Color Lookup Table Data
VariantInit(&vRedLUTData);
vRedLUTData.vt = VT_ARRAY | VT_I4;
vRedLUTData.parray = psaRedLUTData;
iRet = m_pLEADDicomDS->SetPaletteColorLUTData (&vRedLUTData,DICOM_PALETTE_COLOR_LUT_TYPE_RED,0);
if(iRet != 0)
{
SafeArrayDestroy(psaRedLUTData);
SafeArrayDestroy(psaGreenLUTData);
SafeArrayDestroy(psaBlueLUTData);
AfxMessageBox("error");
return;
}
// Set Green Palette Color Lookup Table Data
VariantInit(&vGreenLUTData);
vGreenLUTData.vt = VT_ARRAY | VT_I4;
vGreenLUTData.parray = psaGreenLUTData;
iRet = m_pLEADDicomDS->SetPaletteColorLUTData (&vGreenLUTData,DICOM_PALETTE_COLOR_LUT_TYPE_GREEN,0);
if(iRet != 0)
{
SafeArrayDestroy(psaGreenLUTData);
SafeArrayDestroy(psaGreenLUTData);
SafeArrayDestroy(psaBlueLUTData);
AfxMessageBox("error");
return;
}
// Set Blue Palette Color Lookup Table Data
VariantInit(&vBlueLUTData);
vBlueLUTData.vt = VT_ARRAY | VT_I4;
vBlueLUTData.parray = psaBlueLUTData;
iRet = m_pLEADDicomDS->SetPaletteColorLUTData (&vBlueLUTData,DICOM_PALETTE_COLOR_LUT_TYPE_BLUE,0);
if(iRet != 0)
{
SafeArrayDestroy(psaBlueLUTData);
SafeArrayDestroy(psaGreenLUTData);
SafeArrayDestroy(psaBlueLUTData);
AfxMessageBox("error");
return;
}
SafeArrayDestroy(psaRedLUTData);
SafeArrayDestroy(psaGreenLUTData);
SafeArrayDestroy(psaBlueLUTData);
return;