MCPcopy Create free account
hub / github.com/TASEmulators/fceux / gui_getpixel

Function gui_getpixel

src/lua-engine.cpp:3939–3971  ·  view source on GitHub ↗

Usage: local r,g,b,a = gui.getpixel(255, 223) Gets the LUA set pixel color

Source from the content-addressed store, hash-verified

3937// local r,g,b,a = gui.getpixel(255, 223)
3938// Gets the LUA set pixel color
3939static int gui_getpixel(lua_State *L) {
3940
3941 int x = luaL_checkinteger(L, 1);
3942 int y = luaL_checkinteger(L,2);
3943
3944 int r, g, b, a;
3945
3946 if (!gui_check_boundary(x, y))
3947 luaL_error(L,"bad coordinates. Use 0-%d x 0-%d", LUA_SCREEN_WIDTH - 1, LUA_SCREEN_HEIGHT - 1);
3948
3949 if (!gui_data) {
3950 // Return all 0s, including for alpha.
3951 // If alpha == 0, there was no color data for that spot
3952 lua_pushinteger(L, 0);
3953 lua_pushinteger(L, 0);
3954 lua_pushinteger(L, 0);
3955 lua_pushinteger(L, 0);
3956 return 4;
3957 }
3958
3959 //uint8 *dst = (uint8*) &gui_data[(y*LUA_SCREEN_WIDTH+x)*4];
3960
3961 //uint32 color = *(uint32*) &gui_data[(y*LUA_SCREEN_WIDTH+x)*4];
3962
3963 LUA_DECOMPOSE_PIXEL(*(uint32*) &gui_data[(y*LUA_SCREEN_WIDTH+x)*4], a, r, g, b);
3964
3965 lua_pushinteger(L, r);
3966 lua_pushinteger(L, g);
3967 lua_pushinteger(L, b);
3968 lua_pushinteger(L, a);
3969 return 4;
3970
3971}
3972
3973// Usage:
3974// local r,g,b,palette = gui.getpixel(255, 255)

Callers

nothing calls this directly

Calls 4

luaL_checkintegerFunction · 0.85
gui_check_boundaryFunction · 0.85
luaL_errorFunction · 0.85
lua_pushintegerFunction · 0.85

Tested by

no test coverage detected