TPCCLIB
Loading...
Searching...
No Matches
dcmvr.c File Reference

DICOM Value Representations (VRs). More...

#include "tpcclibConfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "tpcextensions.h"
#include "tpcdcm.h"

Go to the source code of this file.

Functions

unsigned char dcmVRReserved (dcmvr id)
 
dcmvr dcmVRId (const char *s)
 
char * dcmVRName (dcmvr id)
 
size_t dcmVRVLength (dcmvr id)
 
char * dcmVRDescr (dcmvr id)
 
char * dcmDA2intl (const char *orig, char *intl)
 
char * dcmTM2intl (const char *orig, char *intl)
 
char * dcmDT2intl (const char *orig, char *intl)
 

Detailed Description

DICOM Value Representations (VRs).

Definition in file dcmvr.c.

Function Documentation

◆ dcmDA2intl()

char * dcmDA2intl ( const char * orig,
char * intl )

Convert DICOM date 'DA' to international format YYYY-MM-DD.

Returns
Returns pointer to the date string, or NULL in case of an error.
Parameters
origPointer to original DICOM string.
intlPointer to string where date in international format will be written; must be allocated for at least 11 characters.

Definition at line 179 of file dcmvr.c.

185 {
186 if(orig==NULL || intl==NULL) return(NULL);
187 if(strnlen(orig, 10)<8) return(NULL);
188 if(isdigit(orig[4])) { // modern format YYYYMMDD
189 sprintf(intl, "%4.4s-%2.2s-%2.2s", orig, orig+4, orig+6);
190 } else { // old format YYYY.MM.DD
191 sprintf(intl, "%4.4s-%2.2s-%2.2s", orig, orig+5, orig+8);
192 }
193 if(strDateValid(intl)) {intl[0]=(char)0; return(NULL);}
194 return(intl);
195}
int strDateValid(const char *str)
Definition datetime.c:155
size_t strnlen(const char *s, size_t n)
Definition stringext.c:566

Referenced by dcmMListRead().

◆ dcmDT2intl()

char * dcmDT2intl ( const char * orig,
char * intl )

Convert DICOM datetime 'DT' to international format YYYY-MM-DD hh:mm:ss.

Returns
Returns pointer to the time string, or NULL in case of an error.
Parameters
origPointer to original DICOM string. Should be in format YYYYMMDDhhmmss.FFFFFF+hhmm
intlPointer to string where date and time in international format will be written; must be allocated for at least 20 characters.

Definition at line 225 of file dcmvr.c.

232 {
233 if(orig==NULL || intl==NULL) return(NULL);
234 if(strnlen(orig, 26)<14) return(NULL);
235 sprintf(intl, "%4.4s-%2.2s-%2.2s %2.2s:%2.2s:%2.2s",
236 orig, orig+4, orig+6, orig+8, orig+10, orig+12);
237 if(strDateTimeValid(intl, NULL)) {intl[0]=(char)0; return(NULL);}
238 return(intl);
239}
int strDateTimeValid(const char *str, char *intdate)
Definition datetime.c:308

Referenced by dcmMListRead(), and imgReadDICOM().

◆ dcmTM2intl()

char * dcmTM2intl ( const char * orig,
char * intl )

Convert DICOM time 'TM' to international format hh:mm:ss.

Returns
Returns pointer to the time string, or NULL in case of an error.
Parameters
origPointer to original DICOM string.
intlPointer to string where time in international format will be written; must be allocated for at least 9 characters.

Definition at line 202 of file dcmvr.c.

208 {
209 if(orig==NULL || intl==NULL) return(NULL);
210 if(strnlen(orig, 14)<6) return(NULL);
211 if(isdigit(orig[2])) { // modern format hhmmss.fract
212 sprintf(intl, "%2.2s:%2.2s:%2.2s", orig, orig+2, orig+4);
213 } else { // old format hh.mm.ss
214 sprintf(intl, "%2.2s:%2.2s:%2.2s", orig, orig+3, orig+6);
215 }
216 if(strTimeValid(intl)) {intl[0]=(char)0; return(NULL);}
217 return(intl);
218}
int strTimeValid(const char *str)
Definition datetime.c:284

Referenced by dcmMListRead().

◆ dcmVRDescr()

char * dcmVRDescr ( dcmvr id)

Get the DICOM VR description.

Returns
Returns pointer to the description string.
See also
dcmIdentifyVR
Parameters
idVR id (DCM_VR_AE, ...).

Definition at line 162 of file dcmvr.c.

165 {
166 unsigned short int i=0;
167 while(dcm_vr[i].vr!=DCM_VR_INVALID) {
168 if(id==dcm_vr[i].vr) return(dcm_vr[i].descr);
169 i++;
170 }
171 return(dcm_vr[DCM_VR_INVALID].descr);
172}
@ DCM_VR_INVALID
Invalid DICOM value representation.
Definition tpcdcm.h:123

Referenced by dcmFileReadNextElement().

◆ dcmVRId()

dcmvr dcmVRId ( const char * s)

Identify the DICOM VR based on the two-character long string.

Returns
Returns the VR id.
See also
dcmVRName
Parameters
sVR string. Two first characters are used. String does not need to be null-terminated.

Definition at line 103 of file dcmvr.c.

107 {
108 if(s==NULL) return(DCM_VR_INVALID);
109 char buf[3]; buf[0]=s[0]; buf[1]=s[1]; buf[2]=(char)0;
110
111 /* Identify the VR */
112 unsigned short int i=0;
113 while(dcm_vr[i].vr!=DCM_VR_INVALID) {
114 if(strncmp(dcm_vr[i].name, buf, 2)==0) return(dcm_vr[i].vr);
115 i++;
116 }
117 return(DCM_VR_INVALID);
118}

Referenced by dcmFileReadNextElement(), dcmReadFileVR(), and dcmReadFileVRVL().

◆ dcmVRName()

char * dcmVRName ( dcmvr id)

Get the DICOM VR name.

Returns
Returns pointer to the name string.
See also
dcmIdentifyVR
Parameters
idVR id (DCM_VR_AE, ...).

Definition at line 126 of file dcmvr.c.

129 {
130 unsigned short int i=0;
131 while(dcm_vr[i].vr!=DCM_VR_INVALID) {
132 if(id==dcm_vr[i].vr) return(dcm_vr[i].name);
133 i++;
134 }
135 return(dcm_vr[DCM_VR_INVALID].name);
136}

Referenced by dcmAddItem(), dcmFileReadNextElement(), dcmitemPrint(), dcmReadFileVR(), and dcmWriteFileVRVL().

◆ dcmVRReserved()

unsigned char dcmVRReserved ( dcmvr id)

Is the explicit VR (2 bytes) followed by reserved 2 bytes? If yes, then the following Value Length is also given as 32-byte integer, if no, then as 16-bit integer.

Returns
Returns 0, if not, and 2, if it is.
Parameters
idVR id (DCM_VR_AE, ...).

Definition at line 85 of file dcmvr.c.

88 {
89 unsigned short int i=0;
90 while(dcm_vr[i].vr!=DCM_VR_INVALID) {
91 if(id==dcm_vr[i].vr) return(dcm_vr[i].res);
92 i++;
93 }
94 return(2);
95}

Referenced by dcmReadFileVR(), dcmReadFileVRVL(), dcmReadTransferSyntaxUID(), and dcmWriteFileVRVL().

◆ dcmVRVLength()

size_t dcmVRVLength ( dcmvr id)

Get the DICOM VR max value length in bytes; 0 if not defined.

Returns
Returns the length in bytes.
See also
dcmIdentifyVR
Parameters
idVR id (DCM_VR_AE, ...).

Definition at line 144 of file dcmvr.c.

147 {
148 unsigned short int i=0;
149 while(dcm_vr[i].vr!=DCM_VR_INVALID) {
150 if(id==dcm_vr[i].vr) return(dcm_vr[i].s);
151 i++;
152 }
153 return(dcm_vr[DCM_VR_INVALID].s);
154}

Referenced by dcmAddItem(), dcmFileReadNextElement(), dcmFileWrite(), and dcmValueString().