int Surface::setFormat(State & state, SDL_Surface * surface){ PixelFormat * interfacePixelFormat = state.getInterface<PixelFormat>("LuaSDL_PixelFormat"); SDL_PixelFormat * format = interfacePixelFormat->get(1); if (format){ surface->format->format = format->format; surface->format->palette = format->palette; surface->format->BitsPerPixel = format->BitsPerPixel; surface->format->BytesPerPixel = format->BytesPerPixel; surface->format->Rmask = format->Rmask; surface->format->Gmask = format->Gmask; surface->format->Bmask = format->Bmask; surface->format->Amask = format->Amask; surface->format->Rloss = format->Rloss; surface->format->Gloss = format->Gloss; surface->format->Bloss = format->Bloss; surface->format->Aloss = format->Aloss; surface->format->Rshift = format->Rshift; surface->format->Gshift = format->Gshift; surface->format->Bshift = format->Bshift; surface->format->Ashift = format->Ashift; } return 0; }
int Surface::convert(State & state, SDL_Surface * surface){ Stack * stack = state.stack; PixelFormat * interfacePixelFormat = state.getInterface<PixelFormat>("LuaSDL_PixelFormat"); Surface * interfaceSurface = state.getInterface<Surface>("LuaSDL_Surface"); Uint32 flags; if (stack->is<LUA_TNUMBER>(2)){ flags = stack->to<int>(2); }else{ flags = 0; } SDL_PixelFormat * pf = interfacePixelFormat->get(1); if (pf){ SDL_Surface * newSurface = SDL_ConvertSurface(surface, pf, flags); if (newSurface){ interfaceSurface->push(newSurface, true); return 1; } } return 0; }