dicom properties

Shane Blackett <[email protected]>
Newsgroups gmane.comp.video.image-magick.devel
Message-ID <[email protected]>
Hi,

dicom files have many fields of metadata.  In general these are parsed 
and stored in the image properties.

Unfortunately for dicom files which contain jpeg encoded images, a 
separate image is written out and passed to the jpeg coder to read and 
all the metadata is lost.

As a simple way of maintaining this data I have delayed the destroy of 
the dicom image and read the jpeg_image into a separate variable, and 
then copied all the parameters from the dicom to the jpeg.

The patch against subversion is below if you think this is useful.

Shane.

Index: coders/dcm.c
===================================================================
--- coders/dcm.c        (revision 8485)
+++ coders/dcm.c        (working copy)
@@ -3196,6 +3196,10 @@
    if ((strcmp(transfer_syntax,"1.2.840.10008.1.2.4.50") == 0) ||
        (strcmp(transfer_syntax,"1.2.840.10008.1.2.4.70") == 0))
      {
+      const char
+        *property,
+        *property_value;
+
        char
          filename[MaxTextExtent];

@@ -3206,6 +3210,9 @@
          c,
          unique_file;

+      Image
+        *jpeg_image;
+
        ImageInfo
          *read_info;

@@ -3244,15 +3251,22 @@
          c=ReadBlobByte(image);
        }
        (void) fclose(file);
-      image=DestroyImage(image);
        read_info=CloneImageInfo(image_info);
        SetImageInfoBlob(read_info,(void *) NULL,0);
        (void) FormatMagickString(read_info->filename,MaxTextExtent,
          "jpeg:%s",filename);
-      image=ReadImage(read_info,exception);
+      jpeg_image=ReadImage(read_info,exception);
+      /* Copy dcm attributes from image to jpeg image */
+      ResetImagePropertyIterator(image);
+      while(NULL != (property = GetNextImageProperty(image)))
+      {
+        property_value = GetImageProperty(image,property);
+        (void) SetImageProperty(jpeg_image,property,property_value);
+      }
+      image=DestroyImage(image);
        (void) RelinquishUniqueFileResource(filename);
        read_info=DestroyImageInfo(read_info);
-      return(GetFirstImageInList(image));
+      return(GetFirstImageInList(jpeg_image));
      }
    scale=(Quantum *) NULL;
    if (depth != (1UL*QuantumDepth))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.