gui.gdoverlay([int dx=0, int dy=0,] string str [, sx=0, sy=0, sw, sh] [, float alphamul=1.0]) Overlays the given image on the screen. example: gui.gdoverlay(gd.createFromPng("myimage.png"):gdStr())
| 4679 | // Overlays the given image on the screen. |
| 4680 | // example: gui.gdoverlay(gd.createFromPng("myimage.png"):gdStr()) |
| 4681 | static int gui_gdoverlay(lua_State *L) { |
| 4682 | |
| 4683 | int argCount = lua_gettop(L); |
| 4684 | |
| 4685 | int xStartDst = 0; |
| 4686 | int yStartDst = 0; |
| 4687 | int xStartSrc = 0; |
| 4688 | int yStartSrc = 0; |
| 4689 | |
| 4690 | int index = 1; |
| 4691 | if(lua_type(L,index) == LUA_TNUMBER) |
| 4692 | { |
| 4693 | xStartDst = lua_tointeger(L,index++); |
| 4694 | if(lua_type(L,index) == LUA_TNUMBER) |
| 4695 | yStartDst = lua_tointeger(L,index++); |
| 4696 | } |
| 4697 | |
| 4698 | luaL_checktype(L,index,LUA_TSTRING); |
| 4699 | const unsigned char* ptr = (const unsigned char*)lua_tostring(L,index++); |
| 4700 | |
| 4701 | if (ptr[0] != 255 || (ptr[1] != 254 && ptr[1] != 255)) |
| 4702 | luaL_error(L, "bad image data"); |
| 4703 | bool trueColor = (ptr[1] == 254); |
| 4704 | ptr += 2; |
| 4705 | int imgwidth = *ptr++ << 8; |
| 4706 | imgwidth |= *ptr++; |
| 4707 | int width = imgwidth; |
| 4708 | int imgheight = *ptr++ << 8; |
| 4709 | imgheight |= *ptr++; |
| 4710 | int height = imgheight; |
| 4711 | if ((!trueColor && *ptr) || (trueColor && !*ptr)) |
| 4712 | luaL_error(L, "bad image data"); |
| 4713 | ptr++; |
| 4714 | int pitch = imgwidth * (trueColor?4:1); |
| 4715 | |
| 4716 | if ((argCount - index + 1) >= 4) { |
| 4717 | xStartSrc = luaL_checkinteger(L,index++); |
| 4718 | yStartSrc = luaL_checkinteger(L,index++); |
| 4719 | width = luaL_checkinteger(L,index++); |
| 4720 | height = luaL_checkinteger(L,index++); |
| 4721 | } |
| 4722 | |
| 4723 | int alphaMul = transparencyModifier; |
| 4724 | if(lua_isnumber(L, index)) |
| 4725 | alphaMul = (int)(alphaMul * lua_tonumber(L, index++)); |
| 4726 | if(alphaMul <= 0) |
| 4727 | return 0; |
| 4728 | |
| 4729 | // since there aren't that many possible opacity levels, |
| 4730 | // do the opacity modification calculations beforehand instead of per pixel |
| 4731 | int opacMap[256]; |
| 4732 | for(int i = 0; i < 128; i++) |
| 4733 | { |
| 4734 | int opac = 255 - ((i << 1) | (i & 1)); // gdAlphaMax = 127, not 255 |
| 4735 | opac = (opac * alphaMul) / 255; |
| 4736 | if(opac < 0) opac = 0; |
| 4737 | if(opac > 255) opac = 255; |
| 4738 | opacMap[i] = opac; |
nothing calls this directly
no test coverage detected