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

22
LINES

< > BotCompany Repo | #1004899 // markImageThroughLua

JavaX fragment (include)

static bool[] markImageThroughLua(final RGBImage img, S lua) {
  Sandbox s = luaSandbox();
  final int w = img.getWidth(), h = img.getHeight();
  final bool[] mark = new bool[w*h];
  s.setOuter("w", Lua.value(w));
  s.setOuter("h", Lua.value(h));
  s.setOuter("getInt", new TwoArgFunction {
    public LuaValue call(LuaValue x, LuaValue y) {
      ret LuaValue.valueOf(img.getInt(x.toint(), y.toint()));
    }
  });
  s.setOuter("markPixel", new TwoArgFunction {
    public LuaValue call(LuaValue _x, LuaValue _y) {
      int x = _x.toint(), y = _y.toint();
      if (x >= 0 && x < w && y >= 0 && y < h)
        mark[y*w+x] = true;
      ret Lua.NIL;
    }
  });
  luaEval(s, lua);
  ret mark;
}

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: 464 / 469
Referenced in: [show references]