Sorry.  Here is the patch.

If there was some agreement that it would be good (from others interested in DICOM reading) I could extend the respect of the flag to 8bit and 12bit images too, although it would help to have some concrete examples of such files to test against.

--- ImageMagick-svn/coders/dcm.c        2007-10-18 14:29:06.000000000 +1300
+++ ImageMagick-16bitDICOM/coders/dcm.c 2007-10-18 12:00:35.000000000 +1300
@@ -2745,6 +2745,7 @@
     number_scenes,
     quantum,
     samples_per_pixel,
+        signed_data,
     significant_bits,
     status,
     width;
@@ -2797,6 +2798,7 @@
   mask=0xffff;
   number_scenes=1;
   samples_per_pixel=1;
+  signed_data=0xffff; /* Set a value to represent unspecified */
   significant_bits=0;
   *transfer_syntax='\0';
   use_explicit=MagickFalse;
@@ -3059,6 +3061,7 @@
             /*
               Pixel representation.
             */
+                               signed_data = (unsigned long) datum;
             break;
           }
           case 0x1200:
@@ -3188,6 +3191,19 @@
       InheritException(exception,&image->exception);
       return(DestroyImageList(image));
     }
+  if (signed_data==0xffff)
+  {
+         /* Use the previous assumptions,
+                 8 bit and 12 bit are unsigned and 16 bit is signed */
+         if (significant_bits == 16)
+         {
+                 signed_data = 1;
+         }
+         else
+         {
+                 signed_data = 0;
+         }
+  }
   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))
     {
@@ -3374,9 +3390,15 @@
                   if ((bits_allocated != 12) || (significant_bits != 12))
                     {
                       if (msb_first != MagickFalse)
- index=(unsigned long) ReadBlobMSBShort(image)-32767;
+                                                               if (signed_data 
== 1)
+ index=(unsigned long) ReadBlobMSBShort(image)-32767;
+                                                          else
+                          index=(unsigned long) ReadBlobMSBShort(image);
                       else
- index=(unsigned long) ReadBlobLSBShort(image)-32767;
+                                                               if (signed_data 
== 1)
+ index=(unsigned long) ReadBlobLSBShort(image)-32767;
+                                                          else
+                          index=(unsigned long) ReadBlobLSBShort(image);
                     }
                   else
                     {
_______________________________________________
Magick-developers mailing list
Magick-developers@imagemagick.org
http://studio.imagemagick.org/mailman/listinfo/magick-developers

Reply via email to