Home > Back-end >  Dicom convert BMP, C program comments help a great god
Dicom convert BMP, C program comments help a great god

Time:09-24

//DicomBMPDlg. CPP: implementation file
# include "stdafx. H"
# include "DicomBMP. H"
# include "DicomBMPDlg. H"
#include
Enum CONVERSION_MODE
{
MODE_DICOM2BMP=0,
MODE_BMP2DICOM
};
Enum COMPRESSION_MODE
{
COMPRESS_NONE=0,
COMPRESS_RLE,
COMPRESS_JPEGLOSSY,
COMPRESS_JPEGLOSSY12BIT,
COMPRESS_JPEGLOSSLESS,
COMPRESS_JPEGLOSSLESS2
};
The static char szFilter_in []="DICOM File (*. DCM) | *. DCM | BMP File (*. BMP) | *. BMP | All files (*. *) | *. * | |";
# ifdef _DEBUG
# define new DEBUG_NEW
# undef THIS_FILE
The static char THIS_FILE []=__FILE__;
# endif

The class CAboutDlg: public CDialog
{
Public:
CAboutDlg ();
Protected:
DECLARE_MESSAGE_MAP ()
};

CAboutDlg: : CAboutDlg () : CDialog CAboutDlg: : (IDD)
{
}

Void CAboutDlg: : DoDataExchange (CDataExchange * symbol)
{
CDialog: : DoDataExchange (symbol);
}

BEGIN_MESSAGE_MAP (CAboutDlg CDialog)

END_MESSAGE_MAP ()
CDicomBMPDlg: : CDicomBMPDlg (pParent/*=NULL CWnd * */)
: CDialog (CDicomBMPDlg: : IDD, pParent)
{

M_hIcon=AfxGetApp () - & gt; LoadIcon (IDR_MAINFRAME);
M_strFileDir=AfxGetApp () - & gt; GetProfileString (" Defaults ", "Dir", "");
M_nFileFormat=AfxGetApp () - & gt; GetProfileInt (" Defaults ", "Format", 0).
M_nConvertMode=AfxGetApp () - & gt; GetProfileInt (" Defaults ", "Mode," MODE_DICOM2BMP);
}

Void CDicomBMPDlg: : DoDataExchange (CDataExchange * symbol)
{
CDialog: : DoDataExchange (symbol);
}

BEGIN_MESSAGE_MAP (CDicomBMPDlg CDialog)

END_MESSAGE_MAP ()

Void CDicomBMPDlg: : removeTailingSpace (char * pszStr)
{
Char * cc=pszStr + strlen (pszStr) - 1;

While (((* cc==' ') | | cc=='\ t') (*) & amp; & (cc!=pszStr))
{
* cc -='\ 0';
}
}
Void CDicomBMPDlg: : SwapWord (char * pArray, int nWords)
{
Char * cc=pArray, c0;
int i;

//Swap every two bytes
For (I=0; I & lt; NWords; I + +)
{
C0=* cc;
* cc=* (cc + 1);
* (cc + 1)=c0;

Cc +=2;
}
}
Void CDicomBMPDlg: : SwapDWord (char * pArray, int nDWords)
{
Char * cc=pArray, c0;
int i;
For (I=0; I & lt; NDWords; I + +)
{

//Swap the first and the last bytes
C0=* cc;
* cc=* (cc + 3);
* (cc + 3)=c0;

//Swap middle two bytes
C0=* (cc + 2);
* (cc + 2)=* (cc + 1);
* (cc + 1)=c0;

Cc +=4;
}
}
Int CDicomBMPDlg: : readUS (FILE * fp, DATA_ENDIAN nDataEndian)
{
Unsigned short nVal;

Fseek (fp, 4, SEEK_CUR);
Fread (& amp; NVal, 1, sizeof (short), fp);
If (nDataEndian==BIG_ENDIAN)
SwapWord ((char *) & amp; NVal, 1);
Return (int) nVal;
}
Long int CDicomBMPDlg: : readLength (FILE * fp, BOOL bImplicitVR, DATA_ENDIAN nDataEndian)
{
Long int nValLength=0;
Short int nsLength;

If (bImplicitVR)
{
Fread (& amp; NValLength, sizeof (long), 1, fp);
If (nDataEndian==BIG_ENDIAN)
SwapDWord ((char *) & amp; NValLength, 1);
}
The else
{
Fseek (fp, 2, SEEK_CUR);//the Skip VR 2 bytes

Fread (& amp; NsLength, sizeof (short), 1, fp);
If (nDataEndian==BIG_ENDIAN)
SwapWord ((char *) & amp; NsLength, 1);

NValLength=nsLength;
}

Return nValLength;
}
Int CDicomBMPDlg: : readIS (FILE * fp, BOOL bImplicitVR, DATA_ENDIAN nDataEndian)
{
Char szTemp [64]="";
Int nVal=0;

If (readString (fp, szTemp, bImplicitVR nDataEndian)==0)
Sscanf (szTemp, "% d", & amp; NVal);

Return nVal;
}
Float CDicomBMPDlg: : readDS (FILE * fp, BOOL bImplicitVR, DATA_ENDIAN nDataEndian)
{
Char szTemp [64]="";
Float fVal=0;

If (readString (fp, szTemp, bImplicitVR nDataEndian)==0)
Sscanf (szTemp, "% f", & amp; FVal);

Return fVal;
}
Int CDicomBMPDlg: : readString (FILE * fp, char * pszStr, BOOL bImplicitVR, DATA_ENDIAN nDataEndian)
{
Long int nValLength=0;

NValLength=readLength (fp, bImplicitVR nDataEndian);

If ((nValLength & gt; 64) | | (nValLength & lt; 0))
return -1;

Fread (pszStr, 1, nValLength, fp);
PszStr [nValLength]='\ 0';
RemoveTailingSpace (pszStr);

return 0;
}
Char * CDicomBMPDlg: : convertTo8Bit (char * pData, long int nNumPixels, BOOL bIsSigned, short nHighBit,
Float fRescaleSlope, float fRescaleIntercept,
Float fWindowCenter, float fWindowWidth)
{
Unsigned char * pNewData=https://bbs.csdn.net/topics/0;
Long int nCount;
Short * pp;

//1. Clip the high bits.
If (nHighBit & lt; 15)
{
Short nMask;
Short nSignBit;

Pp=(short * pData);
NCount=nNumPixels;

If (bIsSigned==0)//Unsigned integer
{
NMask=0 XFFFF & lt;
  • Related