]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Tue, 1 May 2012 16:40:19 +0000 (16:40 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Tue, 1 May 2012 16:40:19 +0000 (16:40 +0000)
coders/mat.c

index ba48f696a7af6dae845b60c0c9064e302cfa1204..45e8478f8d5f1247e9fb295d9a4c954861115821 100644 (file)
@@ -614,8 +614,8 @@ static Image *ReadMATImage(const ImageInfo *image_info,ExceptionInfo *exception)
   ssize_t ldblk;
   unsigned char *BImgBuff = NULL;
   double MinVal, MaxVal;
-  size_t Unknown6;
-  unsigned z;
+  unsigned z, z2;
+  unsigned Frames;
   int logging;
   int sample_size;
   MagickOffsetType filepos=0x80;
@@ -682,6 +682,7 @@ MATLAB_KO: ThrowReaderException(CorruptImageError,"ImproperImageHeader");
   filepos = TellBlob(image);
   while(!EOFBlob(image)) /* object parser loop */
   {
+    Frames = 1;
     (void) SeekBlob(image,filepos,SEEK_SET);
     /* printf("pos=%X\n",TellBlob(image)); */
 
@@ -721,12 +722,16 @@ MATLAB_KO: ThrowReaderException(CorruptImageError,"ImproperImageHeader");
 
     switch(MATLAB_HDR.DimFlag)
     {     
-      case  8: z=1; break;      /* 2D matrix*/
-      case 12: z = ReadBlobXXXLong(image2);  /* 3D matrix RGB*/
-           Unknown6 = ReadBlobXXXLong(image2);
-           (void) Unknown6;
+      case  8: z2=z=1; break;      /* 2D matrix*/
+      case 12: z2=z = ReadBlobXXXLong(image2);  /* 3D matrix RGB*/
+           (void) ReadBlobXXXLong(image2);
          if(z!=3) ThrowReaderException(CoderError, "MultidimensionalMatricesAreNotSupported");
          break;
+      case 16: z2=z = ReadBlobXXXLong(image2);  /* 4D matrix animation */
+         if(z!=3 && z!=1)
+            ThrowReaderException(CoderError, "MultidimensionalMatricesAreNotSupported");
+           Frames = ReadBlobXXXLong(image2);
+         break;
       default: ThrowReaderException(CoderError, "MultidimensionalMatricesAreNotSupported");
     }  
 
@@ -772,6 +777,7 @@ MATLAB_KO: ThrowReaderException(CorruptImageError,"ImproperImageHeader");
   
     (void) ReadBlob(image2, 4, (unsigned char *) &size);     /* data size */
 
+    NEXT_FRAME:
       /* Image is gray when no complex flag is set and 2D Matrix */
     if ((MATLAB_HDR.DimFlag == 8) &&
         ((MATLAB_HDR.StructureFlag & FLAG_COMPLEX) == 0))
@@ -1012,8 +1018,29 @@ done_reading:
       /* row scan buffer is no longer needed */
     RelinquishMagickMemory(BImgBuff);
     BImgBuff = NULL;
-  }
+
+    if(--Frames>0)
+    {
+      z = z2;
+      if(image2==NULL) image2 = image;
+      goto NEXT_FRAME;
+    }
+    if ((image2!=NULL) && (image2!=image))   /* Does shadow temporary decompressed image exist? */
+      {
+/*  CloseBlob(image2); */
+        DeleteImageFromList(&image2);
+        if(clone_info)
+        {
+          if(clone_info->file)
+          {
+            fclose(clone_info->file);
+            clone_info->file = NULL;
+            (void) remove_utf8(clone_info->filename);
+          }
+        }
+        }
     clone_info=DestroyImageInfo(clone_info);
+  }
 
   RelinquishMagickMemory(BImgBuff);
   CloseBlob(image);