Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

22
LINES

< > BotCompany Repo | #1004899 // markImageThroughLua

JavaX fragment (include)

1  
static bool[] markImageThroughLua(final RGBImage img, S lua) {
2  
  Sandbox s = luaSandbox();
3  
  final int w = img.getWidth(), h = img.getHeight();
4  
  final bool[] mark = new bool[w*h];
5  
  s.setOuter("w", Lua.value(w));
6  
  s.setOuter("h", Lua.value(h));
7  
  s.setOuter("getInt", new TwoArgFunction {
8  
    public LuaValue call(LuaValue x, LuaValue y) {
9  
      ret LuaValue.valueOf(img.getInt(x.toint(), y.toint()));
10  
    }
11  
  });
12  
  s.setOuter("markPixel", new TwoArgFunction {
13  
    public LuaValue call(LuaValue _x, LuaValue _y) {
14  
      int x = _x.toint(), y = _y.toint();
15  
      if (x >= 0 && x < w && y >= 0 && y < h)
16  
        mark[y*w+x] = true;
17  
      ret Lua.NIL;
18  
    }
19  
  });
20  
  luaEval(s, lua);
21  
  ret mark;
22  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004899
Snippet name: markImageThroughLua
Eternal ID of this version: #1004899/1
Text MD5: 993dc7e700c392f7ce021aa5e337b9c2
Author: stefan
Category: javax / lua
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-09-15 23:05:45
Source code size: 716 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 565 / 570
Referenced in: [show references]