Page 1 of 1

Kernels from text files

Posted: 2014-10-30T13:28:33-07:00
by snibgo
I would like to create and process morphology kernels just like any other image. Having to specify them as text is clumsy. That would need a major change.

As a simpler partial solution, I propose that kernels should be readable from text files. FileToString() seems suitable for this. The best place to put this seems to be AcquireKernelInfo() in morphology.c.

The following diff (from v6.8.9-6) makes kernels readable from text files.

Code: Select all

--- /home/Alan/imdevsrc/../ImageMagick-6.8.9-6/magick/morphology.c	2014-04-18 02:27:41.000000000 +0100
+++ /home/Alan/imdevsrc/magick/morphology.c	2014-10-30 19:30:37.348558500 +0000
@@ -501,9 +501,30 @@
   const char
     *p;
 
+  char
+    *expanded;
+
+  ExceptionInfo 
+    exception;
+
+
   if (kernel_string == (const char *) NULL)
     return(ParseKernelArray(kernel_string));
-  p=kernel_string;
+
+  expanded = NULL;
+
+  if (*kernel_string == '@') {
+    printf ("expanding file [%s]\n", kernel_string+1);
+    expanded=FileToString(kernel_string+1,~0UL,&exception);
+    if (expanded == (char *) NULL) {
+      printf ("FileToString failed");
+      return((KernelInfo *) NULL);
+    }
+    printf ("Expanded to [%s]\n", expanded);
+    p=expanded;
+  } else {
+    p=kernel_string;
+  }
   kernel=NULL;
 
   while (GetMagickToken(p,NULL,token), *token != '\0')
@@ -538,6 +559,10 @@
       break;
     p++;
   }
+
+  if (expanded != NULL)
+    expanded=DestroyString(expanded);
+
   return(kernel);
 }

Re: Kernels from text files

Posted: 2014-10-30T16:19:55-07:00
by fmw42
That is a good idea. I concur.

Re: Kernels from text files

Posted: 2014-10-30T17:47:09-07:00
by magick
Look for a patch in ImageMagick 6.8.9-10 Beta by sometime tomorrow.

Re: Kernels from text files

Posted: 2014-10-30T18:24:58-07:00
by snibgo
Thanks.

The diff contains debugging printf statements. I meant to remove them before posting here, but somehow forgot. Sorry about that.