User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: Lua help needed

  1. #1
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module
    Tiles's Avatar
    Join Date
    Jun 2006
    Posts
    1,359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lua help needed

    I found a Lua code snippet for bicubic interpolation. Now i want it to use. And am lost. How do i connect this Lua code with my graphic? From which object to work? Is it even possible to use this code snippet from the internet to use with the Lua object so that it resizes a graphic? If so, how?

    Code:
    function get_rgb_cubic_row(x,y,offset)
      local r0,g0,b0, r1,g1,b1, r2,g2,b2, r3,g3,b3
      r0,g0,b0 = get_rgb(x,y)
      r1,g1,b1 = get_rgb(x+1,y)
      r2,g2,b2 = get_rgb(x+2,y)
      r3,g3,b3 = get_rgb(x+3,y)
      return cubic(offset,r0,r1,r2,r3), cubic(offset,g0,g1,g2,g3), cubic(offset,b0,b1,b2,b3)
    end
    
    function get_rgb_bicubic (x,y)
      local xi,yi -- integer coordinates
      local dx,dy -- offset from coordinates
      local r,g,b
    
      xi=math.floor(x)
      yi=math.floor(y)
      dx=x-xi
      dy=y-yi
    
      r0,g0,b0 = get_rgb_cubic_row(xi-1,yi-1,dx)
      r1,g1,b1 = get_rgb_cubic_row(xi-1,yi,  dx)
      r2,g2,b2 = get_rgb_cubic_row(xi-1,yi+1,dx)
      r3,g3,b3 = get_rgb_cubic_row(xi-1,yi+2,dx)
    
      return cubic(dy,r0,r1,r2,r3),
             cubic(dy,g0,g1,g2,g3),
             cubic(dy,b0,b1,b2,b3)
    end
    
    function scale(ratio)
      for y=0, height-1 do
        for x=0, width-1 do
          -- calculate the source coordinates (u,v)
          u = x * (1.0/ratio)
          v = y * (1.0/ratio)
          r,g,b=get_rgb_bicubic(u,v)
          set_rgb(x,y,r,g,b)
        end
        progress (y/height)
      end
      flush()
    end
    
    function cubic(offset,v0,v1,v2,v3)
      -- offset is the offset of the sampled value between v1 and v2
       return   (((( -7 * v0 + 21 * v1 - 21 * v2 + 7 * v3 ) * offset +
                   ( 15 * v0 - 36 * v1 + 27 * v2 - 6 * v3 ) ) * offset +
                   ( -9 * v0 + 9 * v2 ) ) * offset + (v0 + 16 * v1 + v2) ) / 18.0;
    end
    
    scale(3)

  2. #2
    Forum Moderator Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Jun 2006
    Location
    England
    Posts
    3,546
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)

    Re: Lua help needed

    Quick and messy implementation proof of concept: http://x.jflom.com/files/klik/interpolation.mfa
    .:::.Joshtek.:::.

  3. #3
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module
    Tiles's Avatar
    Join Date
    Jun 2006
    Posts
    1,359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Lua help needed

    Amazing. Works like charm. This teaches me also alot about LUA. Very useful. Many thanks

  4. #4
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module
    Tiles's Avatar
    Join Date
    Jun 2006
    Posts
    1,359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Lua help needed

    Hmm, there is a functioncall when clicking the button. And here you can set the scale factor, right? Call Function scale with 7 with 0 result.

    Increasing the number 7 leads to a greater scaled result. But i cannot enter a counter value here nor a string from a value. Only choice is to change the value in the expression itself. Which i cannot do at runtime.

    How can i influence the scalefactor at runtime?

  5. #5
    Forum Moderator Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Jun 2006
    Location
    England
    Posts
    3,546
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)

    Re: Lua help needed

    In the Call Function expression replace 7 with str$(value( "Counter" ))
    .:::.Joshtek.:::.

  6. #6
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module
    Tiles's Avatar
    Join Date
    Jun 2006
    Posts
    1,359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Lua help needed

    Ah that's strange. I could have sworn that i had tried this before ... :whistle:

    Works. Many thanks

  7. #7
    Forum Moderator Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Jun 2006
    Location
    England
    Posts
    3,546
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)

    Re: Lua help needed

    If you get it working well then please post your progress.
    .:::.Joshtek.:::.

  8. #8
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module
    Tiles's Avatar
    Join Date
    Jun 2006
    Posts
    1,359
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Lua help needed

    Progress is so far that i have implemented the counter now. Not really worth posting it

    Well, it works like charm, but is unfortunately unbelievable slow because it works with fastloop and Overlay. I would need it to resize to 512 three times at once( the perlin noise layers) and to 4096 or even to 8192 in the maximum case. Which needs several minutes then. I need around 2 minutes for resizing a single picture to 512. And my PC is a dual core one. That's simply too much. Even when i get out the best quality :/

    And that's why i cannot use it. I cannot bother my users with enough free time to go shopping just to resize a picture :grin:

    The example is not worthless though. I enjoy studying it. Trying to understand what's going on. Is a great example what can be done with LUA. Again many thanks for this




  9. #9
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Jun 2006
    Posts
    6,773
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: Lua help needed

    MMF2 doesn't use both cores anyway.

  10. #10
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Jul 2006
    Posts
    2,023
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Lua help needed

    Quote Originally Posted by Jamie
    MMF2 doesn't use both cores anyway.
    AFAIK the only real game that does is supreme commander, server apps do as well

Page 1 of 2 1 2 LastLast

Similar Threads

  1. HELP NEEDED! Rockman X [Megaman X] Dashing Help needed.
    By Rockman in forum Multimedia Fusion 2 - Technical Support
    Replies: 22
    Last Post: 30th July 2013, 07:05 AM
  2. Lil help needed please
    By Shim in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 20th February 2011, 12:21 AM
  3. Help needed!
    By Keli in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 16th July 2009, 08:43 PM
  4. Help needed!
    By billyandrocky in forum File Archive
    Replies: 2
    Last Post: 1st June 2008, 08:33 PM
  5. RTS ... Help needed!
    By uprize in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 30th March 2007, 06:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •