]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Sat, 10 Oct 2009 20:04:02 +0000 (20:04 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Sat, 10 Oct 2009 20:04:02 +0000 (20:04 +0000)
coders/dcm.c
coders/psd.c

index ef8d9fed27e40311e2d6a32aff84c03ac5e41bcf..dd210b218e9c8bd6d3491a9155298fe684ed5cf5 100644 (file)
@@ -2785,8 +2785,7 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
     explicit_vr[MaxTextExtent],
     implicit_vr[MaxTextExtent],
     magick[MaxTextExtent],
-    photometric[MaxTextExtent],
-    transfer_syntax[MaxTextExtent];
+    photometric[MaxTextExtent];
 
   DCMStreamInfo
     *stream_info;
@@ -2847,7 +2846,6 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
     high_bit,
     mask,
     max_value,
-    msb_first,
     number_scenes,
     quantum,
     samples_per_pixel,
@@ -2905,7 +2903,6 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
   explicit_vr[2]='\0';
   explicit_file=MagickFalse;
   graymap=(int *) NULL;
-  group=0;
   height=0;
   max_value=255UL;
   mask=0xffff;
@@ -2914,13 +2911,12 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
   scale=(Quantum *) NULL;
   signed_data=(~0UL);
   significant_bits=0;
-  *transfer_syntax='\0';
   use_explicit=MagickFalse;
   explicit_retry = MagickFalse;
   width=0;
   window_center=0;
   window_width=0;
-  while ((group != 0x7FE0) || (element != 0x0010))
+  for (group=0; (group != 0x7FE0) || (element != 0x0010); )
   {
     /*
       Read a group.
@@ -3069,12 +3065,12 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
         {
           case 0x0010:
           {
+            char
+              transfer_syntax[MaxTextExtent];
+
             /*
               Transfer Syntax.
             */
-            if (image_info->verbose != MagickFalse)
-              (void) fprintf(stderr,"transfer_syntax=%s\n",(const char*)
-                transfer_syntax);
             if ((datum == 0) && (explicit_retry == MagickFalse))
               {
                 explicit_retry=MagickTrue;
@@ -3086,11 +3082,52 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                     "Corrupted image - trying explicit format\n");
                 break;
               }
+            *transfer_syntax='\0';
             if (data != (unsigned char *) NULL)
               (void) CopyMagickString(transfer_syntax,(char *) data,
                 MaxTextExtent);
-            if (strcmp(transfer_syntax,"1.2.840.10008.1.2.5") == 0)
-              image->compression=RLECompression;
+            if (image_info->verbose != MagickFalse)
+              (void) fprintf(stderr,"transfer_syntax=%s\n",(const char*)
+                transfer_syntax);
+            if (strncmp(transfer_syntax,"1.2.840.10008.1.2",17) == 0)
+              {
+                int
+                  subtype,
+                  type;
+
+                type=0;
+                subtype=0;
+                (void) sscanf(transfer_syntax+17,".%d.%d",&type,&subtype);
+                switch (type)
+                {
+                  case 1:
+                  {
+                    image->endian=LSBEndian;
+                    break;
+                  }
+                  case 2:
+                  {
+                    image->endian=MSBEndian;
+                    break;
+                  }
+                  case 4:
+                  {
+                    if ((subtype >= 80) && (subtype <= 81))
+                      image->compression=JPEGCompression;
+                    else
+                      if ((subtype >= 90) && (subtype <= 93))
+                        image->compression=JPEG2000Compression;
+                      else
+                        image->compression=JPEGCompression;
+                    break;
+                  }
+                  case 5:
+                  {
+                    image->compression=RLECompression;
+                    break;
+                  }
+                }
+              }
             break;
           }
           default:
@@ -3361,10 +3398,8 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
   image->rows=(unsigned long) height;
   if (signed_data == 0xffff)
     signed_data=(unsigned long) (significant_bits == 16 ? 1 : 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) ||
-      (strcmp(transfer_syntax,"1.2.840.10008.1.2.4.90") == 0) ||
-      (strcmp(transfer_syntax,"1.2.840.10008.1.2.4.91") == 0))
+  if ((image->compression == JPEGCompression) ||
+      (image->compression == JPEG2000Compression))
     {
       Image
         *images;
@@ -3457,8 +3492,7 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
         (void) fclose(file);
         (void) FormatMagickString(read_info->filename,MaxTextExtent,
           "jpeg:%s",filename);
-        if ((strcmp(transfer_syntax,"1.2.840.10008.1.2.4.90") == 0) ||
-            (strcmp(transfer_syntax,"1.2.840.10008.1.2.4.91") == 0))
+        if (image->compression == JPEG2000Compression)
           (void) FormatMagickString(read_info->filename,MaxTextExtent,
             "jp2:%s",filename);
         jpeg_image=ReadImage(read_info,exception);
@@ -3499,8 +3533,6 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
       for (i=0; i < (long) (GetQuantumRange(image->depth)+1); i++)
         scale[i]=ScaleAnyToQuantum((unsigned long) i,range);
     }
-  msb_first=strcmp(transfer_syntax,"1.2.840.10008.1.2.2") == 0 ? MagickTrue :
-    MagickFalse;
   if (image->compression == RLECompression)
     {
       unsigned int
@@ -3664,7 +3696,7 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                 else
                   if ((bits_allocated != 12) || (significant_bits != 12))
                     {
-                      if (msb_first != MagickFalse)
+                      if (image->endian == MSBEndian)
                         pixel_value=(int) (polarity != MagickFalse ? (max_value-
                           ReadDCMMSBShort(stream_info,image)) :
                           ReadDCMMSBShort(stream_info,image));
@@ -3682,7 +3714,7 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                           byte;
                       else
                         {
-                          if (msb_first != MagickFalse)
+                          if (image->endian == MSBEndian)
                             pixel_value=(int) ReadDCMMSBShort(stream_info,
                               image);
                           else
@@ -3737,7 +3769,7 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
                   }
                 else
                   {
-                    if (msb_first != MagickFalse)
+                    if (image->endian == MSBEndian)
                       {
                         pixel.red=ReadDCMMSBShort(stream_info,image);
                         pixel.green=ReadDCMMSBShort(stream_info,image);
index e50b6ac125470cde5efc7d86de38a6db15619640..e05d72a34b8dc3124200d4c33ac06426a8b916b2 100644 (file)
@@ -945,33 +945,18 @@ static Image *ReadPSDImage(const ImageInfo *image_info,ExceptionInfo *exception)
                           blend_source,(unsigned int) blend_dest);
                     }
                   }
-                combinedlength+=length + 4;  /* +4 for length */
+                combinedlength+=length+4;
+                /*
+                  Layer name.
+                */
                 length=(size_t) ReadBlobByte(image);
-                if (length != 0)
-                  {
-                    /*
-                      Layer name.
-                    */
-                    for (j=0; j < (long) (length); j++)
-                      layer_info[i].name[j]=(unsigned char) ReadBlobByte(image);
-                    layer_info[i].name[j]='\0';
-                    if (image->debug != MagickFalse)
-                      (void) LogMagickEvent(CoderEvent,GetMagickModule(),
-                        "      layer name: %s",layer_info[i].name);
-                 }
-#if     0
-          if ( length == 0 )
-            padBytes = 3;
-          else
-            padBytes = (4 - (length % 4));
-          if ( padBytes != 0 ) { /* we need to pad */
-            for ( i=0; i < padBytes; i++)
-              (void) ReadBlobByte(image);
-          }
-                combinedlength += length + padBytes + 1;  /* +1 for length */
-#else
-               combinedlength+=length + 1;  /* +1 for length */
-#endif
+                for (j=0; j < (long) length; j++)
+                  layer_info[i].name[j]=(unsigned char) ReadBlobByte(image);
+                layer_info[i].name[j]='\0';
+                if (image->debug != MagickFalse)
+                  (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                    "      layer name: %s",layer_info[i].name);
+                combinedlength+=length+1;
 
 #if     0  /* still in development */
           /*
@@ -1096,109 +1081,113 @@ static Image *ReadPSDImage(const ImageInfo *image_info,ExceptionInfo *exception)
                 }
 #endif
               compression=ReadBlobMSBShort(layer_info[i].image);
-              if (compression == 1)
+              if ((layer_info[i].page.height != 0) &&
+                  (layer_info[i].page.width != 0))
                 {
+                  if (compression == 1)
+                    {
+                      /*
+                        Read RLE compressed data.
+                      */
+                      if (image->debug != MagickFalse)
+                        (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                          "      layer data is RLE compressed");
+                      for (y=0; y < (long) layer_info[i].image->rows; y++)
+                        (void) ReadBlobMSBShort(layer_info[i].image);
+                      (void) DecodeImage(layer_info[i].image,
+                         layer_info[i].channel_info[j].type);
+                      continue;
+                    }
                   /*
-                    Read RLE compressed data.
+                    Read uncompressed pixel datas separate planes.
                   */
                   if (image->debug != MagickFalse)
                     (void) LogMagickEvent(CoderEvent,GetMagickModule(),
-                      "      layer data is RLE compressed");
-                  for (y=0; y < (long) layer_info[i].image->rows; y++)
-                    (void) ReadBlobMSBShort(layer_info[i].image);
-                  (void) DecodeImage(layer_info[i].image,
-                     layer_info[i].channel_info[j].type);
-                  continue;
-                }
-              /*
-                Read uncompressed pixel datas separate planes.
-              */
-              if (image->debug != MagickFalse)
-                (void) LogMagickEvent(CoderEvent,GetMagickModule(),
-                  "      layer data is uncompressed");
-              packet_size=1;
-              if (layer_info[i].image->storage_class == PseudoClass)
-                {
-                  if (layer_info[i].image->colors > 256)
-                    packet_size++;
-                }
-              else
-                if (layer_info[i].image->depth > 8)
-                  packet_size++;
-              for (y=0; y < (long) layer_info[i].image->rows; y++)
-              {
-                q=GetAuthenticPixels(layer_info[i].image,0,y,
-                  layer_info[i].image->columns,1,exception);
-                if (q == (PixelPacket *) NULL)
-                  break;
-                indexes=GetAuthenticIndexQueue(layer_info[i].image);
-                for (x=0; x < (long) layer_info[i].image->columns; x++)
-                {
-                  if (packet_size == 1)
-                    pixel=(unsigned long) ScaleCharToQuantum((unsigned char)
-                      ReadBlobByte(layer_info[i].image));
+                      "      layer data is uncompressed");
+                  packet_size=1;
+                  if (layer_info[i].image->storage_class == PseudoClass)
+                    {
+                      if (layer_info[i].image->colors > 256)
+                        packet_size++;
+                    }
                   else
-                    pixel=(unsigned long) ScaleShortToQuantum(ReadBlobMSBShort(
-                      layer_info[i].image));
-                  switch (layer_info[i].channel_info[j].type)
+                    if (layer_info[i].image->depth > 8)
+                      packet_size++;
+                  for (y=0; y < (long) layer_info[i].image->rows; y++)
                   {
-                    case -1:  /* transparency mask */
-                    {
-                      q->opacity=(Quantum) (QuantumRange-pixel);
+                    q=GetAuthenticPixels(layer_info[i].image,0,y,
+                      layer_info[i].image->columns,1,exception);
+                    if (q == (PixelPacket *) NULL)
                       break;
-                    }
-                    case 0:  /* first component (Red, Cyan, Gray or Index) */
+                    indexes=GetAuthenticIndexQueue(layer_info[i].image);
+                    for (x=0; x < (long) layer_info[i].image->columns; x++)
                     {
-                      q->red=(Quantum) pixel;
-                      if (layer_info[i].image->storage_class == PseudoClass)
+                      if (packet_size == 1)
+                        pixel=(unsigned long) ScaleCharToQuantum((unsigned char)
+                          ReadBlobByte(layer_info[i].image));
+                      else
+                        pixel=(unsigned long) ScaleShortToQuantum(
+                          ReadBlobMSBShort(layer_info[i].image));
+                      switch (layer_info[i].channel_info[j].type)
+                      {
+                        case -1:  /* transparency mask */
+                        {
+                          q->opacity=(Quantum) (QuantumRange-pixel);
+                          break;
+                        }
+                        case 0:  /* first component (Red, Cyan, Gray or Index) */
+                        {
+                          q->red=(Quantum) pixel;
+                          if (layer_info[i].image->storage_class == PseudoClass)
+                            {
+                              if (packet_size == 1)
+                                indexes[x]=(IndexPacket) ScaleQuantumToChar(
+                                  (Quantum) pixel);
+                              else
+                                indexes[x]=(IndexPacket) ScaleQuantumToShort(
+                                  (Quantum) pixel);
+                              q->red=layer_info[i].image->colormap[(long) *indexes].red;
+                              q->green=layer_info[i].image->colormap[(long) *indexes].green;
+                              q->blue=layer_info[i].image->colormap[(long) *indexes].blue;
+                            }
+                          break;
+                        }
+                        case 1:  /* second component (Green, Magenta, or opacity) */
                         {
-                          if (packet_size == 1)
-                            indexes[x]=(IndexPacket) ScaleQuantumToChar(
-                              (Quantum) pixel);
+                          if (layer_info[i].image->storage_class == PseudoClass)
+                            q->opacity=(Quantum) (QuantumRange-pixel);
                           else
-                            indexes[x]=(IndexPacket) ScaleQuantumToShort(
-                              (Quantum) pixel);
-                          q->red=layer_info[i].image->colormap[(long) *indexes].red;
-                          q->green=layer_info[i].image->colormap[(long) *indexes].green;
-                          q->blue=layer_info[i].image->colormap[(long) *indexes].blue;
+                            q->green=(Quantum) pixel;
+                          break;
                         }
-                      break;
-                    }
-                    case 1:  /* second component (Green, Magenta, or opacity) */
-                    {
-                      if (layer_info[i].image->storage_class == PseudoClass)
-                        q->opacity=(Quantum) (QuantumRange-pixel);
-                      else
-                        q->green=(Quantum) pixel;
-                      break;
-                    }
-                    case 2:  /* third component (Blue or Yellow) */
-                    {
-                      q->blue=(Quantum) pixel;
-                      break;
-                    }
-                    case 3:  /* fourth component (Opacity or Black) */
-                    {
-                      if (image->colorspace == CMYKColorspace)
-                        indexes[x]=(Quantum) pixel;
-                      else
-                        q->opacity=(Quantum) (QuantumRange-pixel);
-                      break;
-                    }
-                    case 4:  /* fifth component (opacity) */
-                    {
-                      q->opacity=(Quantum) (QuantumRange-pixel);
-                      break;
+                        case 2:  /* third component (Blue or Yellow) */
+                        {
+                          q->blue=(Quantum) pixel;
+                          break;
+                        }
+                        case 3:  /* fourth component (Opacity or Black) */
+                        {
+                          if (image->colorspace == CMYKColorspace)
+                            indexes[x]=(Quantum) pixel;
+                          else
+                            q->opacity=(Quantum) (QuantumRange-pixel);
+                          break;
+                        }
+                        case 4:  /* fifth component (opacity) */
+                        {
+                          q->opacity=(Quantum) (QuantumRange-pixel);
+                          break;
+                        }
+                        default:
+                          break;
+                      }
+                      q++;
                     }
-                    default:
+                    if (SyncAuthenticPixels(layer_info[i].image,exception) == MagickFalse)
                       break;
                   }
-                  q++;
+                  }
                 }
-                if (SyncAuthenticPixels(layer_info[i].image,exception) == MagickFalse)
-                  break;
-              }
-            }
             if (layer_info[i].opacity != OpaqueOpacity)
               {
                 /*