]> granicus.if.org Git - imagemagick/blobdiff - coders/dcm.c
Added new coder to take a screen shot of a monitor in Windows.
[imagemagick] / coders / dcm.c
index 4e549249af3746ab01c19b6bf283356b7c0038d8..8202eb30ca25c977bec3337f0f335d2aa6e50942 100644 (file)
 %                          Read DICOM Image Format                            %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -2815,9 +2815,10 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
 
   MagickBooleanType
     explicit_file,
-    use_explicit,
     explicit_retry,
-    polarity;
+    polarity,
+    sequence,
+    use_explicit;
 
   MagickOffsetType
     offset;
@@ -2861,7 +2862,6 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
     window_center,
     y;
 
-
   unsigned char
     *data;
 
@@ -2923,6 +2923,7 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
   number_scenes=1;
   samples_per_pixel=1;
   scale=(Quantum *) NULL;
+  sequence=MagickFalse;
   signed_data=(~0UL);
   significant_bits=0;
   use_explicit=MagickFalse;
@@ -2930,7 +2931,8 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
   width=0;
   window_center=0;
   window_width=0;
-  for (group=0; (group != 0x7FE0) || (element != 0x0010); )
+  for (group=0; (group != 0x7FE0) || (element != 0x0010) ||
+                (sequence != MagickFalse); )
   {
     /*
       Read a group.
@@ -2952,9 +2954,9 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
       Check for "explicitness", but meta-file headers always explicit.
     */
     if ((explicit_file == MagickFalse) && (group != 0x0002))
-      explicit_file=(isupper((int) *explicit_vr) != MagickFalse) &&
-        (isupper((int) *(explicit_vr+1)) != MagickFalse) ? MagickTrue :
-        MagickFalse;
+      explicit_file=(isupper((unsigned char) *explicit_vr) != MagickFalse) &&
+        (isupper((unsigned char) *(explicit_vr+1)) != MagickFalse) ?
+        MagickTrue : MagickFalse;
     use_explicit=((group == 0x0002) && (explicit_retry == MagickFalse)) ||
       (explicit_file != MagickFalse) ? MagickTrue : MagickFalse;
     if ((use_explicit != MagickFalse) && (strcmp(implicit_vr,"xs") == 0))
@@ -3032,7 +3034,7 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
           (void) FormatLocaleFile(stdout," %s",dicom_info[i].description);
         (void) FormatLocaleFile(stdout,": ");
       }
-    if ((group == 0x7FE0) && (element == 0x0010))
+    if ((sequence == MagickFalse) && (group == 0x7FE0) && (element == 0x0010))
       {
         if (image_info->verbose != MagickFalse)
           (void) FormatLocaleFile(stdout,"\n");
@@ -3071,6 +3073,22 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                 }
               data[length*quantum]='\0';
             }
+          else
+            if ((unsigned int) datum == 0xFFFFFFFFU)
+              {
+                sequence=MagickTrue;
+                continue;
+              }
+
+    if (((group << 16) | element) == 0xFFFEE0DD)
+      {
+        sequence=MagickFalse;
+        continue;
+      }
+
+    if (sequence != MagickFalse)
+      continue;
+
     switch (group)
     {
       case 0x0002:
@@ -3145,12 +3163,7 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
             break;
           }
           default:
-          {
-            (void) FormatLocaleFile(stderr,"(%04x,%04x) %d %d "
-              "not found in dictionary\n",(int) group,(int) element,(int)
-              length,datum);
             break;
-          }
         }
         break;
       }
@@ -3380,12 +3393,7 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
             break;
           }
           default:
-          {
-            (void) FormatLocaleFile(stderr,"(%04x,%04x) %d %d "
-              "not found in dictionary\n",(int) group,(int) element,(int)
-              length,datum);
             break;
-          }
         }
         break;
       }
@@ -3401,22 +3409,12 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
             break;
           }
           default:
-          {
-            (void) FormatLocaleFile(stderr,"(%04x,%04x) %d %d "
-              "not found in dictionary\n",(int) group,(int) element,(int)
-              length,datum);
             break;
-          }
         }
         break;
       }
       default:
-      {
-        (void) FormatLocaleFile(stderr,"(%04x,%04x) %d %d "
-          "not found in dictionary\n",(int) group,(int) element,(int) length,
-          datum);
         break;
-      }
     }
     if (data != (unsigned char *) NULL)
       {
@@ -3582,7 +3580,7 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
           "jpeg:%s",filename);
         if (image->compression == JPEG2000Compression)
           (void) FormatLocaleString(read_info->filename,MaxTextExtent,
-            "jp2:%s",filename);
+            "j2k:%s",filename);
         jpeg_image=ReadImage(read_info,exception);
         if (jpeg_image != (Image *) NULL)
           {
@@ -3720,7 +3718,7 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
         tag=(ReadBlobLSBShort(image) << 16) | ReadBlobLSBShort(image);
         stream_info->remaining=(size_t) ReadBlobLSBLong(image);
         if ((tag != 0xFFFEE000) || (stream_info->remaining <= 64) ||
-            (EOFBlob(image) == MagickTrue))
+            (EOFBlob(image) != MagickFalse))
           ThrowReaderException(CorruptImageError,"ImproperImageHeader");
         stream_info->count=0;
         stream_info->segment_count=ReadBlobLSBLong(image);