Extend tpt.screenshot to return created filename and optionally, PPM format

This commit is contained in:
Robert Gadzerfraud 2013-12-08 12:16:12 -07:00
parent f65ea547e7
commit ced44c8be2

View File

@ -2021,22 +2021,40 @@ int screenshotIndex = 0;
int luatpt_screenshot(lua_State* l) int luatpt_screenshot(lua_State* l)
{ {
int captureUI = luaL_optint(l, 1, 0); int captureUI = luaL_optint(l, 1, 0);
int fileType = luaL_optint(l, 2, 0);
std::vector<char> data; std::vector<char> data;
if(captureUI) if(fileType) {
{ if(captureUI)
VideoBuffer screenshot(ui::Engine::Ref().g->DumpFrame()); {
data = format::VideoBufferToPNG(screenshot); VideoBuffer screenshot(ui::Engine::Ref().g->DumpFrame());
data = format::VideoBufferToPPM(screenshot);
}
else
{
VideoBuffer screenshot(luacon_ren->DumpFrame());
data = format::VideoBufferToPPM(screenshot);
}
} }
else else
{ {
VideoBuffer screenshot(luacon_ren->DumpFrame()); if(captureUI)
data = format::VideoBufferToPNG(screenshot); {
VideoBuffer screenshot(ui::Engine::Ref().g->DumpFrame());
data = format::VideoBufferToPNG(screenshot);
}
else
{
VideoBuffer screenshot(luacon_ren->DumpFrame());
data = format::VideoBufferToPNG(screenshot);
}
} }
std::stringstream filename; std::stringstream filename;
filename << "screenshot_"; filename << "screenshot_";
filename << std::setfill('0') << std::setw(6) << (screenshotIndex++); filename << std::setfill('0') << std::setw(6) << (screenshotIndex++);
filename << ".png"; if(fileType) { filename << ".ppm"; }
else { filename << ".png"; }
Client::Ref().WriteFile(data, filename.str()); Client::Ref().WriteFile(data, filename.str());
return 0; lua_pushstring(l, filename.str().c_str());
return 1;
} }
#endif #endif