Stanford PVRG JPEG Patches for GE DICOM MOD

Maintained by David A. Clunie
Last updated: Mon Oct 29 07:14:08 EDT 2018

Getting it ...

What is it ...

As described in the medical image format FAQ, as well as the conformance statement for the GE CTi, there are some problems with the JPEG lossless compression on the DICOM 130mm MOD that the older models of the CTi write.

This patch to the Stanford PVRG JPEG code copes with these bugs, determining from the compressed bit stream whether the GE bug is present or not, and if present copes with it and decompresses the images as intended. Note that one also needs to handle other bugs in the DICOM encapsulation, as do the recent versions of dicom3tools (see for example dctoraw).

The patch is a composite of contributions from various other authors who have suggested ways to handle the bug in both the Stanford and the Cornell code, and thanks are due to them, as well as those at GE who were involved in detecting, describing and correcting the bug in later CTi, MR LX and AW software versions.

There is also another patch (unrelated to the GE issue) to make the codec work on MacOSX ... it turns out that the original code made assumptions about the arguments and return values of lseek() which are not valid on some systems that use a quad long (64 bits) for the offset type (off_t). The patch corrects for this, as well as taking into account that the lseek() return value doesn't seem to be set right on MacOSX and uses fstat() instead to determine file size wrt. truncation. The most recent version also accounts for the need to not use yywrap.

Comments, criticism and general abuse are greatly appreciated and should be directed to