Skip to content

Commit 0b6836a

Browse files
committed
fix handling of AT
We were treating AT as a string rather than a fixed length numeric array. Improve display with dcm-dump as well.
1 parent 38fce1e commit 0b6836a

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

src/dicom-data.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,11 @@ char *dcm_element_value_to_string(const DcmElement *element)
12231223
result = dcm_printf_append(result,
12241224
"%"PRIu64,
12251225
(uint64_t)i);
1226+
} else if (element->vr == DCM_VR_AT) {
1227+
// a ushort with half of a tag
1228+
result = dcm_printf_append(result,
1229+
"%04x",
1230+
i);
12261231
} else {
12271232
result = dcm_printf_append(result, "%"PRId64, i);
12281233
}
@@ -1271,6 +1276,23 @@ char *dcm_element_value_to_string(const DcmElement *element)
12711276
}
12721277
}
12731278

1279+
// AT is a two-element ushort array holding a DICOM tag ... print the tag
1280+
// name if we can
1281+
if (element->vr == DCM_VR_AT && element->vm == 2) {
1282+
int64_t grp;
1283+
int64_t ele;
1284+
(void) dcm_element_get_value_integer(NULL, element, 0, &grp);
1285+
(void) dcm_element_get_value_integer(NULL, element, 1, &ele);
1286+
1287+
uint32_t tag = grp << 16 | ele;
1288+
1289+
const char *keyword = dcm_dict_keyword_from_tag(tag);
1290+
1291+
if (keyword) {
1292+
result = dcm_printf_append(result, " (%s)", keyword);
1293+
}
1294+
}
1295+
12741296
return result;
12751297
}
12761298

src/dicom-dict.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct _DcmVRTable_hash_entry {
5454
static const struct _DcmVRTable vr_table[] = {
5555
{DCM_VR_AE, "AE", DCM_VR_CLASS_STRING_MULTI, 0, DCM_CAPACITY_AE, 2},
5656
{DCM_VR_AS, "AS", DCM_VR_CLASS_STRING_SINGLE, 0, DCM_CAPACITY_AS, 2},
57-
{DCM_VR_AT, "AT", DCM_VR_CLASS_STRING_MULTI, 0, DCM_CAPACITY_AT, 2},
57+
{DCM_VR_AT, "AT", DCM_VR_CLASS_NUMERIC_INTEGER, 2, DCM_CAPACITY_AT, 2},
5858
{DCM_VR_CS, "CS", DCM_VR_CLASS_STRING_MULTI, 0, DCM_CAPACITY_CS, 2},
5959
{DCM_VR_DA, "DA", DCM_VR_CLASS_STRING_SINGLE, 0, DCM_CAPACITY_DA, 2},
6060
{DCM_VR_DS, "DS", DCM_VR_CLASS_STRING_MULTI, 0, DCM_CAPACITY_DS, 2},

src/dicom-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ static bool print_element_create(DcmError **error,
12751275
filehandle->indent * 2,
12761276
" ",
12771277
(tag & 0xffff0000) >> 16,
1278-
tag >> 16);
1278+
tag & 0xffff);
12791279

12801280
if (dcm_is_public_tag(tag)) {
12811281
printf("%s ", dcm_dict_keyword_from_tag(tag));

src/pdicom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ int dcm_dict_vr_header_length(DcmVR vr);
6767

6868
#define DCM_SWITCH_NUMERIC(VR, OPERATION) \
6969
switch (VR) { \
70+
case DCM_VR_AT: OPERATION(uint16_t); break; \
7071
case DCM_VR_FL: OPERATION(float); break; \
7172
case DCM_VR_FD: OPERATION(double); break; \
7273
case DCM_VR_SL: OPERATION(int32_t); break; \

0 commit comments

Comments
 (0)