#include "Ltdic.h"
L_LTDIC_API L_UINT16 L_DicomLoadDSMemory(hDS, pBuffer, uBufferSize, nFlags);
HDICOMDS hDS; |
a DICOM handle |
L_UCHAR* pBuffer; |
pointer to the file in memory to be loaded |
L_UINT32 uBufferSize; |
size of the file in memory (in bytes) |
L_UINT16 nFlags; |
flags that indicate file characteristics |
Loads a DICOM Data Set from memory.
Parameter | Description | |
hDS | A DICOM handle. | |
pBuffer | Pointer to the file in memory to be loaded. | |
uBufferSize | Size of the file in memory (in bytes). | |
nFlags | Meta-header flags, Transfer Syntax flags and other flags that indicate the file characteristics to use when loading the file. Possible values for the Meta-header flags are: | |
Value | Meaning | |
0 | [0x0000] LEADTOOLS will automatically determine the presence or absence of the Meta-header. | |
DS_METAHEADER_PRESENT | [0x0001] The header is present. | |
DS_METAHEADER_ABSENT | [0x0002] The header is absent. | |
Possible values and combinations for the Transfer Syntax flags are: | ||
Value | Meaning | |
0 | [0x0000] LEADTOOLS will automatically determine the Transfer Syntax. | |
DS_LITTLE_ENDIAN | [0x0004] Byte order is Little Endian. | |
DS_BIG_ENDIAN | [0x0008] Byte order is Big Endian. | |
DS_IMPLICIT_VR | [0x0010] The Value Representation is implicit. | |
DS_EXPLICIT_VR | [0x0020] The Value Representation is explicit. | |
DS_LOAD_CLOSE | [0x0200] The complete dataset will be loaded into memory and the file handle closed. | |
Any of the available Meta-header flags given above may be combined with any of the available values or combinations of values for the Transfer Syntax flags given above. For example, you may combine DS_METAHEADER_ABSENT with DS_EXPLICIT_VR, or you may combine DS_METAHEADER_PRESENT with DS_BIG_ENDIAN | DS_EXPLICIT_VR, etc. |
DICOM_SUCCESS |
The function was successful. |
>0 |
An error occurred. Refer to Return Codes. |
You must call L_DicomCreateDS to allocate memory for the Data Set, prior to calling this function.
Unless you pass the DS_LOAD_CLOSE flag, this function DOES NOT make a copy of the memory pointed to by pBuffer. Therefore, DO NOT free this memory as long as you are using the dataset referenced by hDS, or until you have reset the dataset by calling L_DicomResetDS.
Once you have called L_DicomResetDS, you can repopulate the data set referenced by hDS by calling L_DicomInitDS, L_DicomLoadDS, or L_DicomLoadDSMemory. It is not necessary to call L_DicomCreateDS again before repopulating the data set.
If you know certain characteristics of the DICOM file in memory, you can set those in nFlags. Any characteristic that you dont set will be automatically determined. For example, if you know that the metaheader is present, but you do not know the byte order, or whether the Value Representation is implicit or explicit, you can set only DS_METAHEADER_PRESENT in nFlags. During loading LEADTOOLS will determine the byte order and whether the byte order is implicit or explicit.
If you do not know any of the characteristics of the DICOM file in memory, set nFlags to 0 and LEADTOOLS will automatically determine all the file characteristics and load the file accordingly.
To load a data set from a file, call L_DicomLoadDS.
Required DLLs and Libraries
For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application. |
Win32, x64, Linux.
Functions: |
L_DicomCreateDS, L_DicomLoadDS, L_DicomSaveDS, L_DicomResetDS, L_DicomInitDS |
Topics: |
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
L_INT DicomLoadDSMemoryExample(L_VOID)
{
HDICOMDS hDS;
HANDLE hFile;
L_UCHAR* pBuffer = NULL;
L_UINT32 uBufferSize = 0;
L_BOOL bResult;
L_UINT32 NumberOfBytesRead;
L_UINT16 uDICOMRet;
L_UINT32 nClass;
L_UINT16 nFlags;
L_TCHAR szUnknown[]=TEXT("Unknown Class");
L_TCHAR *pClassName;
pDICOMIOD pIOD;
//Create the dataset
hDS = L_DicomCreateDS(NULL);
if(hDS == NULL)
return DICOM_ERROR_NULL_PTR;
//Create a handle to the DICOM file on disk
hFile = CreateFile( MAKE_IMAGE_PATH(TEXT("Image2.dcm")),
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
L_DicomFreeDS(hDS);
return DICOM_ERROR_NULL_PTR;
}
//Get the file size
uBufferSize = GetFileSize(hFile, NULL);
if(uBufferSize == INVALID_FILE_SIZE)
{
CloseHandle(hFile);
L_DicomFreeDS(hDS);
return uBufferSize;
}
//Allocate a buffer that will hold the data in the file
pBuffer = (L_UCHAR*) malloc(uBufferSize);
if(pBuffer == NULL)
{
CloseHandle(hFile);
L_DicomFreeDS(hDS);
return DICOM_ERROR_NULL_PTR;
}
//Read the file data into a buffer
bResult = ReadFile(hFile, pBuffer, uBufferSize, (LPDWORD)(&NumberOfBytesRead), NULL);
if(bResult == FALSE)
{
free(pBuffer);
CloseHandle(hFile);
L_DicomFreeDS(hDS);
return FAILURE - 1;
}
//Load DICOM file from memory
uDICOMRet = L_DicomLoadDSMemory(hDS, pBuffer, uBufferSize, 0);
if(uDICOMRet != DICOM_SUCCESS)
{
free(pBuffer);
CloseHandle(hFile);
L_DicomFreeDS(hDS);
return uDICOMRet;
}
//Get the information about the DICOM file.
L_DicomGetInfoDS(hDS, &nClass, &nFlags);
pIOD = L_DicomFindClassIOD(nClass);
if (pIOD != NULL)
{
pClassName = pIOD->pszName;
}
else
{
pClassName = szUnknown;
}
MessageBox(NULL, pClassName, TEXT("Notice"), MB_OK);
//Make sure to cleanup
free(pBuffer);
CloseHandle(hFile);
L_DicomFreeDS(hDS);
return DICOM_SUCCESS;
}