PDA

View Full Version : How to copy image variables



Marquis
July 2nd, 2007, 02:14 AM
Hi folks,

I have two Girders running on seperate PCs. Both are sending image variables to my NR2 client. On the NR2 is a lua code that should copy one of these to a new one. This new one is displayed on the screen.

How to do this?

Best regards,
Marc

Rob H
July 2nd, 2007, 06:15 AM
I'm not sure that I understand what your question is

Marquis
July 2nd, 2007, 07:32 AM
sorry for not being clear...

Girder on PC1 is sending an image variable to netremote => cover1
Girder on PC2 is sending another image variable to netremote => cover2

in netremote a lua script is doing some decision which cover to pick. The selected cover should be copied to a new image variable => cover3

In my design the page is using the image variable "cover3" to display the proper coverart.

So my need is to copy "cover1" OR "cover2" into "cover3"

Hope this is more understandable...

BR/Marc

Rob H
July 2nd, 2007, 10:32 AM
Ah, I see - unfortunately I don't think that's directly possible. However, I think you should be able to use bind-at-load variables to achieve something similar, although I haven't done this specifically.

Suppose your image variables are Image1 and Image2 - your Lua code would set a NetRemote variable e.g. PickImage to the name of one of these variables, and you would then have a third image variable called <PickImage>. Once you've set the value of PickImage you would need to call NetRemote.Rebind() to force NR to reexamine the value of PickImage.

As I say, I haven't tried this for image variables, but I think it should work unless Ben says otherwise.

Marquis
July 2nd, 2007, 01:53 PM
Rob,

I have tried the following:



NetRemote.SetVariable('PickImage',NetRemote.GetVar iable('IMAGE1'))
NetRemote.Rebind()


This is not working, the display is empty. Also Netremote is crashing after a few minutes. Taking out this line is preventing the crash.

I also tried



NetRemote.SetImageVariable('PickImage','image/jpg',NetRemote.GetVariable('IMAGE1'))
NetRemote.Rebind()


This is also resulting in a crash, but immediately after execution. Also the NetRemote.Rebind() is causing an error: "attempt to call field 'Rebind' a nil value"

BR/Marc

Rob H
July 2nd, 2007, 03:16 PM
It may not work for image variables.

That's strange about NetRemote.Rebind() - that is the right function isn't it Ben? Or hasn't it made it into a released version yet?

Rob H
July 2nd, 2007, 03:17 PM
One other possibility is to have NR tell the relevant copy of Girder which variable name to send the image to.

Marquis
July 2nd, 2007, 03:24 PM
Something unexpected while I was playing around:


path1=NetRemote.GetVariable('IMAGE1')

fills the path1 lua variable with a path to a cached image, e.g. "c:\promixis\netremote\cache\img2_5.png"

This is true for NR on windows and I hope it's also true on my PPC. So my approach is to use the NetRemote.SetImageVariable() to set the variable. So far I have written the needed code to open the file in binary mode and read it into a lua table. Assigning this lua table to the NetRemote variable is working.

It's working for hardcoded filenames, but I am stuck in replacing single backslashes to double backslashes, e.g. convert the example above to "c:\\promixis\\netremote\\cache\img2_5.png"

I am playing with the string.gsub() function, but this is a book with seven seals to me.

BR/Marc

Marquis
July 2nd, 2007, 03:42 PM
OK, I got it...

There is no need to modify the path1 variable, because I figured out that the problem with the escape character (\) is only coming up if I use path names in the source code. But for variables beeing returned from a function the backslash is not interpreted as an escape character.

This means my code is now:


imgdata = {}
cachefile=NetRemote.GetVariable('imagevariable')
local fh = io.open(cachefile,"rb")
if (fh) then
imgdata = fh:read("*a");
fh:close()
end
NetRemote.SetImageVariable('PickImage','image/jpg',imgdata)


#1 create empty table for image data
#2 get the path and filename for the cache file of the imagevariable
#3 open file in binary read
#4-7 read data and store in table
#8 set image variable from binary data

This is maybe not the best solution and any other way is welcome.

It is working on Windows XP and also on my PPC handheld. But there seems to be one bug. When the loaded image is a png-file the screen layout is messed up. The display is not resized to fit the frame. However with jpeg-files everything is working fine.

BR/Marc

Rob H
July 3rd, 2007, 02:27 AM
Interesting, I didn't know you could do that!

Ben S
July 4th, 2007, 08:17 AM
NetRemote.SetVariable('PickImage',NetRemote.GetVar iable('IMAGE1'))
NetRemote.Rebind()



I think what Rob is suggesting is to change that to ...



NetRemote.SetVariable('PickImage','IMAGE1')
NetRemote.Rebind()


As PickImage should be the -name- of the variable, not the image itself.

But it sounds like your method works, also (except for PNGs, which sounds like a bug).

Poorman65
September 6th, 2007, 12:46 PM
Very cool trick. I needed to copy images too.

Marquis
July 6th, 2008, 02:13 AM
Unfortunately I figured out, that with the latest version of NR2 my code example is not working anymore.

NR2 is no longer returning the path to the cached image variable, but instead the variable name.

so the following code:


cachefile=NetRemote.GetVariable('imagevariable')

is not returning something like "c:\\promixis\\netremote\\cache\img2_5.png" but instead the variable name 'imagevariable'.

Also the .Rebind() function is not working for me. May I ask you to investigate about it. It would be great if my old code would work again without modifications.

Thanks in advance
Marc

Rob H
July 6th, 2008, 02:25 AM
I'm not surprised that no longer works - there is no image cache any more.

I'd suggest a change in approach, and use two separate frames of the same size at the same location and use a state rule to determine which one to display.

Apart from anything else it will be a lot quicker.

And in what way is .Rebind not working?

Marquis
July 6th, 2008, 08:51 AM
Hi Rob,

thanks for your answer.

I tried the .Rebind() code with the new NR2 version, because with the older version it produces an error. Now it runs through without any failure, but also without success.

The problem with frames is, that there is a n:1 connection, meaning there could be n numbers of images and only one of them should be displayed. That is why it would be best to have some kind of copy function.

I am curious... How is NR2 now handling Imagedata when it is not in a cache? I think a pure memory handling is consuming too much memory.

Best regards,
Marc

Rob H
July 6th, 2008, 09:55 AM
It is indeed in memory - it's not a huge consideration on most Win32 PCs. On the PPC the cache actually meant a mostly larger memory consumption since every image was in the cache and some were also displayed, resulting in nearly twice as much memory use for those images.

In case it wasn't clear earlier, what I would do is to have a frame with an image variable called <PickImage> (including the < > brackets).

Suppose Girder #1 sends the image to a variable called Image1 and Girder #2 to a variable called Image2

You might then have some code in NR as follows :-


if showImage1 then
NetRemote.SetVariable('PickImage', 'Image1')
else
NetRemote.SetVariable('PickImage', 'Image2')
end
NetRemote.Rebind()

After the Rebind call, the frame above will end up displaying on or other of the image variables Image1 or Image2.

Note the quotation marks in the above code, we're setting the variable PickImage to either 'Image1' or 'Image2', ie the literal strings.

Marquis
July 6th, 2008, 11:01 PM
Hi Rob,

thanks for your explanation. I think my code is already what you described. I inserted a frame now and posted the variablename with brackets to the image variable field, but it doesn't work. To make sure I put it also in the Element Name field, but I'm having no success.

I attached two screenshots and here is my code:


NetRemote.SetVariable('mc12.zone.coverimage','mc12 .'..client..'.playback.coverimage')
NetRemote.Rebind()


I have several clients who will send their coverimages to NR2 with the namesheme mc12.<client>.playback.coverimage, e.g.

mc12.studio.playback.coverimage
mc12.living.playback.coverimage
mc12.bedroom.playback.coverimage
...

the lua variable "client" in this case is set either to "studio", "living" or "beedroom" so that the above code will point to the right source image.

On the lua console in NR-Designer I see no error messages.

What am I doing wrong?
Marc

Rob H
July 7th, 2008, 01:58 AM
Can you send me the CCF? Or at least a sample CCF with just the relevant page.

Marquis
July 25th, 2008, 09:11 AM
Hi Rob,

sorry for my late reply, but I figured out that the Rebind is not working with variable-names having a "." in the name. So changing the line

NetRemote.SetVariable('mc12.zone.coverimage','mc12 .'..client..'.playback.coverimage')

to


NetRemote.SetVariable('cover','mc12 .'..client..'.playback.coverimage')

is now working as you described. I don't know if this is a bug, but I can live with it - however it should be a known limitation.

Thanks for your patience.
Marc

Rob H
July 25th, 2008, 02:46 PM
There's no code in the rebind that would care about non-alpha characters in variable names, apart from < and > so there must be something else going on here.