Page 1 of 1

Embedding MSL into scripting languages Like Lua

Posted: 2012-12-27T05:05:47-07:00
by lbsl
Hi,

I'm currently messing around with MSL inside a Lua scripting engine of an application that is compiled for OSX, Linux and Windows which is the reason for me to try MSL:requires the least hassle and allows running conjure out-of-the-box from a custom location.

The Lua scripting engine has a document engine that allows for writing output in XML code, but it has its limitations.
One of the limitations is that using the same tags in an existing (sub)node is prohibited. e.g.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<group>
  <image>
....
  </image>
  <image>
...
  </image>
  <write>filename='testpic.png'</write>
</group>
is not tolerated and the last operationblock for <image> will overwrite the first one completely.
Also the order in which parameters are written are not the same order as i instruct the document creator to generate it.
So i'm trying to figure out how flexible MSL really is in interpreting the xml stuff and if parameters are also allowed to be served as nodes.

This snippet of Lua code:

Code: Select all

function document_test(width,height,wmargin,hmargin,fgc,bgc,bdc)
  local xstart = wmargin
  local xend = width - wmargin
  local ystart = hmargin
  local yend = height - hmargin
--  local image_file = os.tmpname(".png")
  
    local my_document = app.Document.create("group") {
      image={
        size = tostring(width).."x"..tostring(height),
        draw={
          primitive="line",
          xc=bgc,
          fill=fgc,
          stroke=bgc,
          points=tostring(xstart)..','..tostring(ystart)..','..tostring(xend)..','..tostring(yend),
          draw ={
            primitive = "path",
            stroke="red",
            fill="yellow",
            points = "M 70,10 l -15,-5  +5,+5  -5,+5  +15,-5 z"
          }      
       
        },
      },
      write="filename='testpic.png'"
    }
    my_document:save_as('test.msl')
    os.execute(IM_CONJURE..' test.msl -verbose -debug')

end
Generates this block of xml:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<group doc_version="0">
  <write>filename='testpic.png'</write>
  <image>
    <draw>
      <xc>white</xc>
      <draw>
        <primitive>path</primitive>
        <stroke>red</stroke>
        <points>M 70,10 l -15,-5  +5,+5  -5,+5  +15,-5 z</points>
        <fill>yellow</fill>
      </draw>
      <primitive>line</primitive>
      <stroke>white</stroke>
      <points>10,10,70,10</points>
      <fill>black</fill>
    </draw>
    <size>80x20</size>
  </image>
</group>
I have to create a group because the doc_version parameter is always submitted to the parent tag, i can't avoid the API from inserting it. (is there a way to allow Conjure to ignore unknown parameters for critical tags?)

What i'm trying to aim for here is that MSL has a great potential for usage in these kind of generic scripting languages (tool applications that use it, games that use a scripting language and allows third party tools to run) as a nice library add-on.
Are there any plans to make MSL more flexible, scan the code for tags and/or parameters regardless of their order yet ignore what it doesn't know?

The current way the XML document API in my tool works is, well unusable for MSL now, so i have to rewrite this XML document management myself to be able to circumvent the limitations and allow adding parameters inside the node tags.

The other thing i need to know is the minimum required files for conjure / convert to work on any platform. The Windows autonome zip package is a whopping 45MB, i doubt i need everything to make this work but i also don't know what i can exactly leave out.

Re: Embedding MSL into scripting languages Like Lua

Posted: 2012-12-27T05:24:58-07:00
by magick
Are there any plans to make MSL more flexible, scan the code for tags and/or parameters regardless of their order yet ignore what it doesn't know?
Order is important in MSL. It applies the image processing algorithms in the order it finds it in the XML script. You could read images out of order but in image processing performing operations in a prescribed order is important.
The other thing i need to know is the minimum required files for conjure / convert to work on any platform. The Windows autonome zip package is a whopping 45MB, i doubt i need everything to make this work but i also don't know what i can exactly leave out.
There are lots of files you could safely remove from the ImageMagick package depending on your requirements. If you don't need MPEG support, remove ffmpeg. For conjure only, you could remove the MagickWand and Magick++ API's. If you don't want camera support, remove dcraw, etc.

We suspect a better choice than MSL, might be to embed LUA directly in ImageMagick and use it instead of MSL. See http://lua-users.org/wiki/UserDataWithPointerExample.

Re: Embedding MSL into scripting languages Like Lua

Posted: 2012-12-27T08:08:25-07:00
by lbsl
magick wrote: There are lots of files you could safely remove from the ImageMagick package depending on your requirements. If you don't need MPEG support, remove ffmpeg. For conjure only, you could remove the MagickWand and Magick++ API's. If you don't want camera support, remove dcraw, etc.

We suspect a better choice than MSL, might be to embed LUA directly in ImageMagick and use it instead of MSL. See http://lua-users.org/wiki/UserDataWithPointerExample.
Thanks for the file hints.

If i had the power to embed Imagemagick into the Lua engine i would go that way, but the application serving the Lua engine is closed source, hence i attempt to acquire MSL and write wrappers for it.
Looks like i also have to rewrite the XML saving engine to preserve the order of key and parameter writing.
Well i can always attempt to convince the application developer to embed the ImageMagick API, looking at the license, embedding or allowing ImageMagick should not be a problem for a closed source project, be it that the readme should be included.