Skip to content

Commit

Permalink
better detection of implicit mode in dcm-dump
Browse files Browse the repository at this point in the history
automatically flip to implicit mode when printing dicoms
  • Loading branch information
jcupitt committed Aug 10, 2024
1 parent 9f22a35 commit fc6b865
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

## 1.1.0, 28/3/24

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ to add support](https://github.com/ImagingDataCommons/libdicom/issues).
## Building from source

```shell
cd libdicom-1.0.0
cd libdicom-1.1.0
meson setup builddir --buildtype release
meson compile -C builddir
meson install -C builddir
Expand Down Expand Up @@ -108,7 +108,7 @@ This will print:
$ ./read-frames.py sm_image.dcm
opening libdicom ...
init for libdicom ...
libdicom version: 1.0.0
libdicom version: 1.1.0
frame 1 -> <10x10 pixels, 8 bits, 3 bands, RGB> 300 bytes
frame 2 -> <10x10 pixels, 8 bits, 3 bands, RGB> 300 bytes
frame 3 -> <10x10 pixels, 8 bits, 3 bands, RGB> 300 bytes
Expand Down
48 changes: 36 additions & 12 deletions src/dicom-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,29 @@ static DcmDataSet *dcm_filehandle_read_file_meta(DcmError **error,
}


static bool dcm_filehandle_set_transfer_syntax(DcmError **error,
DcmFilehandle *filehandle,
const char *transfer_syntax_uid)
{
if (filehandle->transfer_syntax_uid) {
free(filehandle->transfer_syntax_uid);
}

filehandle->transfer_syntax_uid = dcm_strdup(error, transfer_syntax_uid);
if (filehandle->transfer_syntax_uid == NULL) {
return false;
}

if (strcmp(filehandle->transfer_syntax_uid, "1.2.840.10008.1.2") == 0) {
filehandle->implicit = true;
}

filehandle->desc.transfer_syntax_uid = filehandle->transfer_syntax_uid;

return true;
}


const DcmDataSet *dcm_filehandle_get_file_meta(DcmError **error,
DcmFilehandle *filehandle)
{
Expand Down Expand Up @@ -610,19 +633,13 @@ const DcmDataSet *dcm_filehandle_get_file_meta(DcmError **error,
return NULL;
}

filehandle->transfer_syntax_uid =
dcm_strdup(error, transfer_syntax_uid);
if (filehandle->transfer_syntax_uid == NULL) {
if (!dcm_filehandle_set_transfer_syntax(error,
filehandle,
transfer_syntax_uid)) {
dcm_dataset_destroy(file_meta);
return NULL;
}

if (strcmp(filehandle->transfer_syntax_uid, "1.2.840.10008.1.2") == 0) {
filehandle->implicit = true;
}

filehandle->desc.transfer_syntax_uid = filehandle->transfer_syntax_uid;

filehandle->file_meta = file_meta;
} else {
// move the read point to the start of the slide metadata
Expand Down Expand Up @@ -1503,7 +1520,15 @@ static bool print_element_create(DcmError **error,
{
DcmFilehandle *filehandle = (DcmFilehandle *) client;

USED(error);
// we must record the transfer syntax in the file meta since we need it
// to determine implicit/explicit encoding
if (tag == TAG_TRANSFER_SYNTAX_UID &&
vr == DCM_VR_UI &&
value &&
length > 10 &&
!dcm_filehandle_set_transfer_syntax(error, filehandle, value)) {
return false;
}

printf("%*.*s(%04x,%04x) ",
filehandle->indent * 2,
Expand Down Expand Up @@ -1615,8 +1640,7 @@ bool dcm_filehandle_print(DcmError **error,
dcm_log_info("Read metadata");
if (!dcm_parse_dataset(error,
filehandle->io,
// FIXME we should check transfer syntax for this
false,
filehandle->implicit,
&parse,
filehandle)) {
return false;
Expand Down
1 change: 1 addition & 0 deletions src/pdicom.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef SSIZE_T ssize_t;
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define USED(x) (void)(x)

#define TAG_TRANSFER_SYNTAX_UID 0x00020010
#define TAG_DIMENSION_INDEX_VALUES 0x00209157
#define TAG_REFERENCED_IMAGE_NAVIGATION_SEQUENCE 0x00480200
#define TAG_PLANE_POSITION_SLIDE_SEQUENCE 0x0048021a
Expand Down

0 comments on commit fc6b865

Please sign in to comment.