Skip to content

Commit 60df482

Browse files
committed
handle generic group length tags
and start to look at tags that need contextual VRs
1 parent ce788f6 commit 60df482

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/dicom-data.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,13 @@ void dcm_element_destroy(DcmElement *element)
216216

217217
uint16_t dcm_element_get_group_number(const DcmElement *element)
218218
{
219-
return (uint16_t)(element->tag >> 16);
219+
return element->tag >> 16;
220220
}
221221

222222

223223
uint16_t dcm_element_get_element_number(const DcmElement *element)
224224
{
225-
return (uint16_t)(element->tag);
225+
return element->tag & 0xffff;
226226
}
227227

228228

src/dicom-dict.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ static const struct _DcmAttribute attribute_table[] = {
304304
{0X00041512, DCM_VR_TAG_UI, "ReferencedTransferSyntaxUIDInFile"},
305305
{0X0004151A, DCM_VR_TAG_UI, "ReferencedRelatedGeneralSOPClassUIDInFile"},
306306
{0X00041600, DCM_VR_TAG_UL, "NumberOfReferences"},
307+
{0X00080000, DCM_VR_TAG_UL, "GenericGroupLength"},
307308
{0X00080001, DCM_VR_TAG_UL, "LengthToEnd"},
308309
{0X00080005, DCM_VR_TAG_CS, "SpecificCharacterSet"},
309310
{0X00080006, DCM_VR_TAG_SQ, "LanguageCodeSequence"},
@@ -5281,6 +5282,13 @@ static const struct _DcmAttribute *attribute_from_tag(uint32_t tag)
52815282

52825283
dcm_init();
52835284

5285+
// tags with element number 0 are generic group length tags ... map all of
5286+
// these (except 0000,0000) to tag 0008,0000 (GenericGroupLength)
5287+
if (tag != 0 &&
5288+
(tag & 0xffff) == 0) {
5289+
tag = 0x00080000;
5290+
}
5291+
52845292
HASH_FIND_INT(attribute_from_tag_dict, &tag, entry);
52855293

52865294
return (const struct _DcmAttribute *)entry;
@@ -5313,12 +5321,11 @@ DcmVR dcm_vr_from_tag(uint32_t tag)
53135321
{
53145322
const struct _DcmAttribute *attribute;
53155323

5316-
if ((attribute = attribute_from_tag(tag)) &&
5317-
dcm_dict_str_from_vr((DcmVR) attribute->vr_tag)) {
5318-
return (DcmVR) attribute->vr_tag;
5324+
if (!(attribute = attribute_from_tag(tag))) {
5325+
return DCM_VR_ERROR;
53195326
}
53205327

5321-
return DCM_VR_ERROR;
5328+
return (DcmVR) attribute->vr_tag;
53225329
}
53235330

53245331

src/dicom-file.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,15 @@ static DcmElement *read_element_header(DcmError **error,
353353

354354
DcmVR vr;
355355
if (implicit) {
356+
// this can be an ambiguious VR, eg. pixeldata is allowed in implicit
357+
// mode and has to be disambiguated later from other tags
356358
vr = dcm_vr_from_tag(tag);
357359
if (vr == DCM_VR_ERROR) {
358360
dcm_error_set(error, DCM_ERROR_CODE_PARSE,
359361
"Reading of Data Element header failed",
360362
"Tag %08X not allowed in implicit mode", tag);
361363
}
364+
362365
if (!read_uint32(error, filehandle, length, position)) {
363366
return NULL;
364367
}

0 commit comments

Comments
 (0)