YOUR ACCOUNT

Login or Register to post new topics or replies
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
I'm getting some strange results with large tables. Do you have some limit to how large tables can be or memory usage in general for a script?
  Details E-Mail
Vladimir Golovin
Administrator
Posts: 3446
Filters: 55
Uh, no idea. We'll look into this.

Edit: Could you post the sample script here?
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
Yep - it may very well be errors in the script though smile;)

script:
Quote
function setPixRGBA(buf,cx,cy,r,g,b,a)
cx = math.floor(cx)
cy = math.floor(cy)
--zero indexed!
if (cx >= 0) and (cx < OUTPUT_WIDTH) and
(cy >= 0) and (cy < OUTPUT_HEIGHT)then
i = (cx + cy * OUTPUT_WIDTH) * 4 + 1
buf[i] = r
buf[i + 1] = g
buf[i + 2] = b
buf[i + 3] = a
end
end;

function getPixRGBA(buf,cx,cy)
cx = math.floor(cx)
cy = math.floor(cy)
--zero indexed!
if (cx >= 0) and (cx < OUTPUT_WIDTH) and
(cy >= 0) and (cy < OUTPUT_HEIGHT)then
local i = (cx + cy * OUTPUT_WIDTH) * 4 + 1
local r = buf[i]
local g = buf[i + 1]
local b = buf[i + 2]
local a = buf[i + 3]
return r,g,b,a
end
return {0,0,0,0}
end;

function createBitmap(buf, src)
local sx = 1 / OUTPUT_WIDTH
local sy = 1 / OUTPUT_HEIGHT

for j=0,OUTPUT_HEIGHT-1 do
for i=0,OUTPUT_WIDTH-1 do
local r,g,b,a = get_sample_map(i*sx, j*sy, src)
setPixRGBA(buf, i, j, r,g,b,a)
end
end
end

function prepare()
bitmap = {}
initialize = true
end;

function get_sample(x, y)
if (initialize == true) then
createBitmap(bitmap, SOURCE)
initialize = false
end

-- do not work:
--local r,g,b,a = getPixRGBA(bitmap, x * OUTPUT_WIDTH, y * OUTPUT_HEIGHT)

-- works, but with error:
local r,g,b,a = getPixRGBA(bitmap, 300, 300)

return r,g,b,a
end;


Bitmap Buffer.ffxml
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
Hmm, I think its something else that fails, even a very small bitmap buffer causes the same problem.. still learning this lua stuff
  Details E-Mail
Dmitry Sapelnikov
Filter Forge, Inc. AKA Egret
Posts: 76
Filters: 5
Heh, I've fixed this =)
Script code after bug fixing:

Quote
function setPixRGBA(buf, cx, cy, r, g, b, a)
local cx = math.floor(cx)
local cy = math.floor(cy)
--zero indexed!
if (cx >= 0) and (cx < OUTPUT_WIDTH) and
(cy >= 0) and (cy < OUTPUT_HEIGHT)then
local i = (cx + cy * OUTPUT_WIDTH) * 4 + 1
buf[i] = r
buf[i + 1] = g
buf[i + 2] = b
buf[i + 3] = a
end
end;

function getPixRGBA(buf,cx,cy)
local cx = math.floor(cx)
local cy = math.floor(cy)
--zero indexed!
if (cx >= 0) and (cx < OUTPUT_WIDTH) and
(cy >= 0) and (cy < OUTPUT_HEIGHT)then
local i = (cx + cy * OUTPUT_WIDTH) * 4 + 1
local r = buf[i]
local g = buf[i + 1]
local b = buf[i + 2]
local a = buf[i + 3]
return r, g, b, a
end
-- Fixed(Egret): return {0, 0, 0, 0} is incorrect here
return 0, 0, 0, 0
end;

function createBitmap(buf, src)
-- Fixed(Egret): it's a proper conversion from the filter coords to
-- the image coords
local scale = 1 / SIZE

for j=0, OUTPUT_HEIGHT-1 do
for i=0, OUTPUT_WIDTH-1 do
local r,g,b,a = get_sample_map(i*scale, j*scale, src)
setPixRGBA(buf, i, j, r, g, b, a)
end
end
end

function prepare()
bitmap = {}
initialize = true
end;

function get_sample(x, y)
if (initialize == true) then
createBitmap(bitmap, SOURCE)
initialize = false
end

-- Fixed(Egret): it's a proper conversion from the filter coords to
-- the image coords
local r,g,b,a = getPixRGBA(bitmap, x * SIZE, y * SIZE)
return r,g,b,a
end;
  Details E-Mail
Dmitry Sapelnikov
Filter Forge, Inc. AKA Egret
Posts: 76
Filters: 5
The problem which caused nils was tiny.

But an approach used in the script makes it good "don't do it!" example (Sphinx, I'm sorry smile:( Of course it's not your fault, just lack of info about scripting)

For all FF script programmers:
Never create tables or another kind of caches without really serious purpose. Caches in scripts consumes memory really hard because caches are independently created for each rendering thread. (For exapmle, if you've got double-core processor and "use all CPU(s)" option is enabled in FF options, script component creates at least 3 copies of one cache: 2 for filter preview rendering threads, and 1 for component thumbnail rendering.
BTW, I've got independent infrastructure for components which need caching. And we haven't implemented it in script components yet.
  Details E-Mail
Dmitry Sapelnikov
Filter Forge, Inc. AKA Egret
Posts: 76
Filters: 5
Another point of discussion is coordinate systems used in FF.
We are going to post an wiki article about it this week.
  Details E-Mail
Vladimir Golovin
Administrator
Posts: 3446
Filters: 55
Egret, good point -- we should mention per-thread Lua state duplication in the help articles.
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
Ah, of course! Remains of my first implementation where I tried to store channels in a small table for each rgba pixel/sample, but that didn't work out (maan I wish I could drag off the script tab and maximize it smile;) hint hint)

About the memory consumption - yes I did notice things got slow with the "large" table. I am really just testing/learning things by trying out familiar concepts from earlier projects.

Are you saying that the complete script is copied for each thread or what is going on? It would be quite useful if you somehow could declare a shared variable cross threads and script components, perhaps in some sort of read only state to avoid changing data problems. Or the other way around: declare that a script is not suitable for multithreaded processing.

I think that you will see several attempts to implement bitmap filters, perhaps something can be done in this regard (some sort of bitmap filter script component which is wrapped by your general bitmap filter framework, with cache tiles etc).
  Details E-Mail
Igor Lorents
Filter Forge, Inc.
Posts: 39
Also, I'd like to mention an important thing about component sampling.

Filter Forge core can take samples not only in [0..Size-1] bounds. We have to take some samples outside this area to make the proper supersampling of border pixels.
That's why, your execution path went through the line I marked with bold below.

Quote
function getPixRGBA(buf,cx,cy)
local cx = math.floor(cx)
local cy = math.floor(cy)
--zero indexed!
if (cx >= 0) and (cx < OUTPUT_WIDTH) and
(cy >= 0) and (cy < OUTPUT_HEIGHT)then
-- skipped....
return r, g, b, a
end
return 0, 0, 0, 0
end;


You can easily check that by adding the following line before the second return statement:

Quote
error (string.format("%d, %d", cx, cy))


After that, you'll see something like this in the log window:

Quote
Script error (line 28): -1, -1.


Generally, I agree with Vladimir and Egret. Thanks for your post, Sphinx. Your code sample uncovers a lot of things which must be thoroughly explained in our help articles.

  Details E-Mail
Vladimir Golovin
Administrator
Posts: 3446
Filters: 55
Quote
Sphinx. wrote:
(some sort of bitmap filter script component which is wrapped by your general bitmap filter framework, with cache tiles etc


This is planned, but it won't make it into the official release of 2.0.
  Details E-Mail
xirja
Idididoll Forcabbage

Posts: 1698
Filters: 8
smile:cry: Perhaps with the official release of version 4.0?
_____________________________________________________

http://web.archive.org/web/2021062908...rjadesign/
_____________________________________________________
  Details E-Mail
Crapadilla
lvl 52 Filter Weaver and Official "Filter Forge Seer"

Posts: 4365
Filters: 65
smile:cry: Perhaps with the official release of version 5.0, then?
--- Crapadilla says: "Damn you, stupid redundant feature requests!" ;)
  Details E-Mail
Rachel Duim
So Called Tortured Artist

Posts: 2498
Filters: 188
Add my vote. I get very slow rendering if I use the FXAA map script component in a filter with a bomber. It has no arrays, but a lot of variables (over 50, necessary given the complexity of the script). Please come up with some way to deal with these memory issues.
Math meets art meets psychedelia.
  Details E-Mail
xirja
Idididoll Forcabbage

Posts: 1698
Filters: 8
Does version 6 help this by eliminating the 32 bit 3 GB limit?
_____________________________________________________

http://web.archive.org/web/2021062908...rjadesign/
_____________________________________________________
  Details E-Mail

Join Our Community!

Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!

33,712 Registered Users
+19 new in 30 days!

153,534 Posts
+31 new in 30 days!

15,348 Topics
+72 new in year!

Create an Account

Online Users Last minute:

7 unregistered users.