[prev in list] [next in list] [prev in thread] [next in thread] 

List:       imagemagick-developer
Subject:    [magick-developers] Re: dicom patches
From:       Syam Gadde <gadde () biac ! duke ! edu>
Date:       2002-03-28 16:17:14
[Download RAW message or body]

On Thu, 2002-03-28 at 10:46, Syam Gadde wrote:
> I've attached minor patches to dcm.c

Sure I did.  Here they are. :)

-syam


["ImageMagick-5.4.4-dcm.patch" (ImageMagick-5.4.4-dcm.patch)]

diff -ur ImageMagick-5.4.4.orig/coders/dcm.c ImageMagick-5.4.4/coders/dcm.c
--- ImageMagick-5.4.4.orig/coders/dcm.c	Thu Mar 28 10:00:52 2002
+++ ImageMagick-5.4.4/coders/dcm.c	Thu Mar 28 10:06:34 2002
@@ -2594,9 +2594,9 @@
     { 0x7ff1, 0x000d, (char *) "US", (char *) "?" },
     { 0x7ff1, 0x0010, (char *) "US", (char *) "?" },
     { 0xfffc, 0xfffc, (char *) "OB", (char *) "Data Set Trailing Padding" },
-    { 0xfffe, 0xe000, (char *) "xs", (char *) "Item" },
-    { 0xfffe, 0xe00d, (char *) "xs", (char *) "Item Delimitation Item" },
-    { 0xfffe, 0xe0dd, (char *) "xs", (char *) "Sequence Delimitation Item" },
+    { 0xfffe, 0xe000, (char *) "!!", (char *) "Item" },
+    { 0xfffe, 0xe00d, (char *) "!!", (char *) "Item Delimitation Item" },
+    { 0xfffe, 0xe0dd, (char *) "!!", (char *) "Sequence Delimitation Item" },
     { 0xffff, 0xffff, (char *) "xs", (char *) "" }
   };
 
@@ -2684,10 +2684,12 @@
   int
     blue,
     element,
+    file_explicit,
     green,
     group,
     red,
-    scene;
+    scene,
+    use_explicit;
 
   long
     datum,
@@ -2765,6 +2767,7 @@
   data=NULL;
   element=0;
   explicit_vr[2]='\0';
+  file_explicit=-1;
   graymap=(unsigned short *) NULL;
   group=0;
   height=0;
@@ -2775,6 +2778,7 @@
   samples_per_pixel=1;
   significant_bits=0;
   *transfer_syntax='\0';
+  use_explicit=-1;
   width=0;
   while ((group != 0x7FE0) || (element != 0x0010))
   {
@@ -2794,11 +2798,16 @@
         break;
     (void) strncpy(implicit_vr,dicom_info[i].vr,MaxTextExtent-1);
     count=ReadBlob(image,2,(char *) explicit_vr);
-    if (strcmp(implicit_vr,"xs") == 0)
-      if (isupper((int) *explicit_vr) && isupper((int) *(explicit_vr+1)))
-        (void) strncpy(implicit_vr,explicit_vr,MaxTextExtent-1);
-    if (strcmp(implicit_vr,explicit_vr) == 0)
+    /* check for "explicitness", but meta-file headers always explicit */
+    if (group != 0x0002 && file_explicit == -1)
+      file_explicit = (isupper((int) *explicit_vr) &&
+		       isupper((int) *(explicit_vr+1)));
+    use_explicit = (file_explicit || (group == 0x0002));
+    if (use_explicit && (strcmp(implicit_vr,"xs") == 0))
+      (void) strncpy(implicit_vr,explicit_vr,MaxTextExtent-1);
+    if (use_explicit && (strcmp(implicit_vr,"!!") != 0))
       {
+	/* when in doubt, believe the explicitly declared type */
         quantum=2;
         if ((strcmp(explicit_vr,"OB") == 0) ||
             (strcmp(explicit_vr,"UN") == 0) ||
@@ -2810,19 +2819,8 @@
       }
     else
       {
-        if (strcmp(implicit_vr,"xs") != 0)
-          {
-            (void) SeekBlob(image,(off_t) -2,SEEK_CUR);
-            quantum=4;
-          }
-        else
-          if ((strcmp(explicit_vr,"SS") == 0) ||
-              (strcmp(explicit_vr,"US") == 0))
-            quantum=2;
-          else
-            (void) SeekBlob(image,(off_t) -2,SEEK_CUR);
-        if (strcmp(implicit_vr,"SQ") != 0)
-          quantum=4;
+	(void) SeekBlob(image,(off_t) -2,SEEK_CUR);
+	quantum=4;
       }
     datum=0;
     if (quantum == 4)
@@ -2836,60 +2834,32 @@
       {
         if ((strcmp(implicit_vr,"SS") == 0) ||
             (strcmp(implicit_vr,"US") == 0))
-          switch ((int) datum)
-          {
-            case 2:
-            default:
-            {
-              quantum=2;
-              datum=datum/2;
-              length=(size_t) datum;
-              break;
-            }
-            case 4:
-            {
-              quantum=4;
-              break;
-            }
-            case 8:
-            {
-              quantum=2;
-              length=4;
-              break;
-            }
-          }
+	  quantum=2;
         else
           if ((strcmp(implicit_vr,"UL") == 0) ||
-              (strcmp(implicit_vr,"SL") == 0))
+              (strcmp(implicit_vr,"SL") == 0) ||
+	      (strcmp(implicit_vr,"FL") == 0))
             quantum=4;
           else
-            if (strcmp(implicit_vr,"xs") != 0)
-              {
-                quantum=1;
-                length=(size_t) datum;
-                if (datum == -1)
-                  length=8;
-              }
-            else
-              if ((strcmp(implicit_vr,"FL") == 0) ||
-                  (strcmp(explicit_vr,"SS") == 0) ||
-                  (strcmp(explicit_vr,"US") == 0))
-                quantum=2;
-              else
-                if (strcmp(implicit_vr,"FD") == 0)
-                  quantum=8;
-                else
-                  {
-                    quantum=2;
-                    datum=datum/2;
-                    length=(size_t) datum;
-                  }
+	    if (strcmp(implicit_vr,"FD") == 0)
+	      quantum=8;
+	    else
+	      quantum=1;
+	if (datum == -1) /* sequence and item undef. lengths */
+	  {
+	    quantum = 0;
+	    length = 0;
+	  }
+	else
+	  length=(size_t) datum/quantum;
       }
     if (image_info->verbose)
       {
         /*
           Display Dicom info.
         */
+	if (!use_explicit)
+	  explicit_vr[0]='\0';
         for (i=0; dicom_info[i].description != (char *) NULL; i++)
           if ((group == dicom_info[i].group) &&
               (element == dicom_info[i].element))

_______________________________________________
Magick-developers mailing list
Magick-developers@imagemagick.org
http://studio.imagemagick.org/mailman/listinfo/magick-developers

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic