Skip to content

Commit fc6b865

Browse files
committed
better detection of implicit mode in dcm-dump
automatically flip to implicit mode when printing dicoms
1 parent 9f22a35 commit fc6b865

4 files changed

Lines changed: 40 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* fix build with uthash \< 2.3.0 [bgilbert]
44
* explicitly fail if macOS universal build is attempted [bgilbert]
5+
* better handling of implicit mode in dcm-dump [jcupitt]
56

67
## 1.1.0, 28/3/24
78

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ to add support](https://github.com/ImagingDataCommons/libdicom/issues).
2424
## Building from source
2525

2626
```shell
27-
cd libdicom-1.0.0
27+
cd libdicom-1.1.0
2828
meson setup builddir --buildtype release
2929
meson compile -C builddir
3030
meson install -C builddir
@@ -108,7 +108,7 @@ This will print:
108108
$ ./read-frames.py sm_image.dcm
109109
opening libdicom ...
110110
init for libdicom ...
111-
libdicom version: 1.0.0
111+
libdicom version: 1.1.0
112112
frame 1 -> <10x10 pixels, 8 bits, 3 bands, RGB> 300 bytes
113113
frame 2 -> <10x10 pixels, 8 bits, 3 bands, RGB> 300 bytes
114114
frame 3 -> <10x10 pixels, 8 bits, 3 bands, RGB> 300 bytes

src/dicom-file.c

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,29 @@ static DcmDataSet *dcm_filehandle_read_file_meta(DcmError **error,
579579
}
580580

581581

582+
static bool dcm_filehandle_set_transfer_syntax(DcmError **error,
583+
DcmFilehandle *filehandle,
584+
const char *transfer_syntax_uid)
585+
{
586+
if (filehandle->transfer_syntax_uid) {
587+
free(filehandle->transfer_syntax_uid);
588+
}
589+
590+
filehandle->transfer_syntax_uid = dcm_strdup(error, transfer_syntax_uid);
591+
if (filehandle->transfer_syntax_uid == NULL) {
592+
return false;
593+
}
594+
595+
if (strcmp(filehandle->transfer_syntax_uid, "1.2.840.10008.1.2") == 0) {
596+
filehandle->implicit = true;
597+
}
598+
599+
filehandle->desc.transfer_syntax_uid = filehandle->transfer_syntax_uid;
600+
601+
return true;
602+
}
603+
604+
582605
const DcmDataSet *dcm_filehandle_get_file_meta(DcmError **error,
583606
DcmFilehandle *filehandle)
584607
{
@@ -610,19 +633,13 @@ const DcmDataSet *dcm_filehandle_get_file_meta(DcmError **error,
610633
return NULL;
611634
}
612635

613-
filehandle->transfer_syntax_uid =
614-
dcm_strdup(error, transfer_syntax_uid);
615-
if (filehandle->transfer_syntax_uid == NULL) {
636+
if (!dcm_filehandle_set_transfer_syntax(error,
637+
filehandle,
638+
transfer_syntax_uid)) {
616639
dcm_dataset_destroy(file_meta);
617640
return NULL;
618641
}
619642

620-
if (strcmp(filehandle->transfer_syntax_uid, "1.2.840.10008.1.2") == 0) {
621-
filehandle->implicit = true;
622-
}
623-
624-
filehandle->desc.transfer_syntax_uid = filehandle->transfer_syntax_uid;
625-
626643
filehandle->file_meta = file_meta;
627644
} else {
628645
// move the read point to the start of the slide metadata
@@ -1503,7 +1520,15 @@ static bool print_element_create(DcmError **error,
15031520
{
15041521
DcmFilehandle *filehandle = (DcmFilehandle *) client;
15051522

1506-
USED(error);
1523+
// we must record the transfer syntax in the file meta since we need it
1524+
// to determine implicit/explicit encoding
1525+
if (tag == TAG_TRANSFER_SYNTAX_UID &&
1526+
vr == DCM_VR_UI &&
1527+
value &&
1528+
length > 10 &&
1529+
!dcm_filehandle_set_transfer_syntax(error, filehandle, value)) {
1530+
return false;
1531+
}
15071532

15081533
printf("%*.*s(%04x,%04x) ",
15091534
filehandle->indent * 2,
@@ -1615,8 +1640,7 @@ bool dcm_filehandle_print(DcmError **error,
16151640
dcm_log_info("Read metadata");
16161641
if (!dcm_parse_dataset(error,
16171642
filehandle->io,
1618-
// FIXME we should check transfer syntax for this
1619-
false,
1643+
filehandle->implicit,
16201644
&parse,
16211645
filehandle)) {
16221646
return false;

src/pdicom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef SSIZE_T ssize_t;
4343
#define MAX(A, B) ((A) > (B) ? (A) : (B))
4444
#define USED(x) (void)(x)
4545

46+
#define TAG_TRANSFER_SYNTAX_UID 0x00020010
4647
#define TAG_DIMENSION_INDEX_VALUES 0x00209157
4748
#define TAG_REFERENCED_IMAGE_NAVIGATION_SEQUENCE 0x00480200
4849
#define TAG_PLANE_POSITION_SLIDE_SEQUENCE 0x0048021a

0 commit comments

Comments
 (0)