GraphicsMagick: VisualMagick/tests/runtest.bat Added checking fo...

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.12656.1683090297.6776.graphicsmagick-commit@lists.sourceforge.net>
changeset 5ba5891bf44e in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=5ba5891bf44e
summary: VisualMagick/tests/runtest.bat Added checking for TopoL

diffstat:

 ChangeLog                      |    5 +
 VisualMagick/tests/runtest.bat |    5 +
 coders/topol.c                 |  152 +++++++++++++++++-----------------------
 3 files changed, 76 insertions(+), 86 deletions(-)

diffs (241 lines):

diff -r 36130eec721f -r 5ba5891bf44e ChangeLog
--- a/ChangeLog	Tue May 02 16:35:03 2023 -0500
+++ b/ChangeLog	Wed May 03 07:04:20 2023 +0200
@@ -1,3 +1,8 @@
+2023-05-03  Fojtik Jaroslav  <[email protected]>
+
+	* VisualMagick/tests/runtest.bat Added checking for TopoL.
+	* coders/topol.c: Added extension checking to function.
+
 2023-05-02  Fojtik Jaroslav  <[email protected]>
 
 	* coders/topol.c: Fix a problem when filename contains garbage only.
diff -r 36130eec721f -r 5ba5891bf44e VisualMagick/tests/runtest.bat
--- a/VisualMagick/tests/runtest.bat	Tue May 02 16:35:03 2023 -0500
+++ b/VisualMagick/tests/runtest.bat	Wed May 03 07:04:20 2023 +0200
@@ -325,6 +325,11 @@
 if not %COUNT% EQU 6 goto :_failed
 @rem call :_dorwtest both TIM
 @rem if not %COUNT% EQU 6 goto :_failed
+@rem These two extensions clashes with TopoL format
+del out_?.mez
+del out_?.pal
+call :_dorwtest file TOPOL
+if not %COUNT% EQU 3 goto :_failed
 @rem call :_dorwtest both TTF
 @rem if not %COUNT% EQU 6 goto :_failed
 call :_dorwtest both TXT
diff -r 36130eec721f -r 5ba5891bf44e coders/topol.c
--- a/coders/topol.c	Tue May 02 16:35:03 2023 -0500
+++ b/coders/topol.c	Wed May 03 07:04:20 2023 +0200
@@ -318,10 +318,45 @@
                                pHeader->Version,
 			       pHeader->Komprese,
                                pHeader->Stav);
-
 }
 
 
+static ImageInfo *CheckFName(ImageInfo *clone_info, size_t *i)
+{
+size_t j;
+  if(clone_info==NULL || i==NULL) return NULL;
+  //if((clone_info=CloneImageInfo(clone_info)) == NULL) return NULL;
+
+  *i = strnlen(clone_info->filename, sizeof(clone_info->filename));
+  if(*i >= sizeof(clone_info->filename))
+  {
+    DestroyImageInfo(clone_info);
+    return NULL;
+  }
+
+  j = *i;
+  while(--*i > 0)
+  {
+    if(clone_info->filename[*i]=='.')
+    {
+      break;
+    }
+    if(clone_info->filename[*i]=='/' || clone_info->filename[*i]=='\\' || clone_info->filename[*i]==':' )
+    {
+      *i = j;
+      break;
+    }
+  }
+
+  if(*i <= 0)
+  {
+    DestroyImageInfo(clone_info);
+    return NULL;
+  }
+
+return clone_info;
+}
+
 
 
 /*
@@ -384,8 +419,8 @@
     depth,
     status;
 
+  size_t i;
   long
-    i,
     j,
     ldblk;
 
@@ -524,25 +559,7 @@
 
   if(Header.FileType>=5) goto NoMEZ;
 
-  if ((clone_info=CloneImageInfo(image_info)) == NULL) goto NoMEZ;
-
-  i=(long) strlen(clone_info->filename);
-  j=i;
-  while(--i>0)
-    {
-      if(clone_info->filename[i]=='.')
-      {
-        break;
-      }
-      if(clone_info->filename[i]=='/' || clone_info->filename[i]=='\\' || clone_info->filename[i]==':' )
-      {
-        i=j;
-        break;
-      }
-    }
-
-  if (i <= 0)
-    goto NoPalette;
+  if((clone_info=CheckFName(CloneImageInfo(image_info),&i)) == NULL) goto NoMEZ;
 
   (void) strlcpy(clone_info->filename+i,".MEZ",sizeof(clone_info->filename)-i);
   if((clone_info->file=fopen(clone_info->filename,"rb"))==NULL)
@@ -575,26 +592,7 @@
 
   /* ----- Do something with palette ----- */
   if(Header.FileType==5) goto NoPalette;
-  if ((clone_info=CloneImageInfo(image_info)) == NULL) goto NoPalette;
-
-  i=(long) strlen(clone_info->filename);
-  j=i;
-  while(--i>0)
-    {
-      if(clone_info->filename[i]=='.')
-        {
-          break;
-        }
-      if(clone_info->filename[i]=='/' || clone_info->filename[i]=='\\' ||
-         clone_info->filename[i]==':' )
-        {
-          i=j;
-          break;
-        }
-    }
-
-  if (i <= 0)
-    goto NoPalette;
+  if ((clone_info=CheckFName(CloneImageInfo(image_info),&i)) == NULL) goto NoPalette;
 
   (void) strlcpy(clone_info->filename+i,".PAL",sizeof(clone_info->filename)-i);
   if ((clone_info->file=fopen(clone_info->filename,"rb"))==NULL)
@@ -827,7 +825,6 @@
   size_t DataSize;
   QuantumType qt;
   int bpp;
-  ImageInfo *clone_info;
 
 	/* Open output image file. */
   assert(image_info != (const ImageInfo *) NULL);
@@ -931,55 +928,39 @@
 	/* Palette */
   if(qt == IndexQuantum)
   {
-    if((clone_info=CloneImageInfo(image_info)) != NULL)
+    ImageInfo *clone_info;
+    size_t i;
+    if((clone_info=CheckFName(CloneImageInfo(image_info),&i)) != NULL)
     {
-      size_t i,j;
-      Image *Palette;
-      ExceptionInfo exception;
-
-      i = strnlen(clone_info->filename, sizeof(clone_info->filename));
-      if(i < sizeof(clone_info->filename))
+      (void)strlcpy(clone_info->filename+i,".pal",sizeof(clone_info->filename)-i);
+      if((clone_info->file=fopen(clone_info->filename,"wb"))!=NULL)
       {
-        j = i;
-        while(--i > 0)
-        {
-          if(clone_info->filename[i]=='.')
-          {
-            break;
-          }
-          if(clone_info->filename[i]=='/' || clone_info->filename[i]=='\\' || clone_info->filename[i]==':' )
-          {
-            i=j;
-            break;
-          }
-        }
-        (void) strlcpy(clone_info->filename+i,".pal",sizeof(clone_info->filename)-i);
-        if((clone_info->file=fopen(clone_info->filename,"wb"))!=NULL)
+        Image *Palette;
+        if((Palette=AllocateImage(clone_info))!=NULL )
         {
-          if((Palette=AllocateImage(clone_info))!=NULL )
+          ExceptionInfo exception;
+          if(OpenBlob(clone_info,Palette,WriteBinaryBlobMode,&exception))
           {
-            if(OpenBlob(clone_info,Palette,WriteBinaryBlobMode,&exception))
+            size_t j;
+            if(Header.FileType == 2)
+              j = 256;
+            else
+              j = 15;
+            WriteBlobByte(Palette,j);
+            for(i=0; i<j; i++)
             {
-              if(Header.FileType == 2)
-                j = 256;
-              else
-                j = 15;
-              WriteBlobByte(Palette,j);
-              for(i=0; i<j; i++)
+              WriteBlobByte(Palette, i&0xFF);
+              if(i<image->colors)
               {
-                WriteBlobByte(Palette, i&0xFF);
-                if(i<image->colors)
-                {
-                  WriteBlobByte(Palette,i);
-                  WriteBlobByte(Palette,i);
-                  WriteBlobByte(Palette,i);
-                }
-                else
-                {
-                  WriteBlobByte(Palette,ScaleQuantumToChar(image->colormap[i].red));
-                  WriteBlobByte(Palette,ScaleQuantumToChar(image->colormap[i].green));
-                  WriteBlobByte(Palette,ScaleQuantumToChar(image->colormap[i].blue));
-                }
+                WriteBlobByte(Palette,i);
+                WriteBlobByte(Palette,i);
+                WriteBlobByte(Palette,i);
+              }
+              else
+              {
+                WriteBlobByte(Palette,ScaleQuantumToChar(image->colormap[i].red));
+                WriteBlobByte(Palette,ScaleQuantumToChar(image->colormap[i].green));
+                WriteBlobByte(Palette,ScaleQuantumToChar(image->colormap[i].blue));
               }
             }
           }
@@ -989,7 +970,6 @@
     }
   }
 
-
   if(logging)
     (void)LogMagickEvent(CoderEvent,GetMagickModule(),"return TopoL");
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.