From ced44c8be2f17ec01068367d0a68f6e173622123 Mon Sep 17 00:00:00 2001 From: Robert Gadzerfraud Date: Sun, 8 Dec 2013 12:16:12 -0700 Subject: [PATCH] Extend tpt.screenshot to return created filename and optionally, PPM format --- src/cat/LegacyLuaAPI.cpp | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/cat/LegacyLuaAPI.cpp b/src/cat/LegacyLuaAPI.cpp index c4034b8ba..100542a60 100644 --- a/src/cat/LegacyLuaAPI.cpp +++ b/src/cat/LegacyLuaAPI.cpp @@ -2021,22 +2021,40 @@ int screenshotIndex = 0; int luatpt_screenshot(lua_State* l) { int captureUI = luaL_optint(l, 1, 0); + int fileType = luaL_optint(l, 2, 0); std::vector data; - if(captureUI) - { - VideoBuffer screenshot(ui::Engine::Ref().g->DumpFrame()); - data = format::VideoBufferToPNG(screenshot); + if(fileType) { + if(captureUI) + { + VideoBuffer screenshot(ui::Engine::Ref().g->DumpFrame()); + data = format::VideoBufferToPPM(screenshot); + } + else + { + VideoBuffer screenshot(luacon_ren->DumpFrame()); + data = format::VideoBufferToPPM(screenshot); + } } else { - VideoBuffer screenshot(luacon_ren->DumpFrame()); - data = format::VideoBufferToPNG(screenshot); + if(captureUI) + { + VideoBuffer screenshot(ui::Engine::Ref().g->DumpFrame()); + data = format::VideoBufferToPNG(screenshot); + } + else + { + VideoBuffer screenshot(luacon_ren->DumpFrame()); + data = format::VideoBufferToPNG(screenshot); + } } std::stringstream filename; filename << "screenshot_"; filename << std::setfill('0') << std::setw(6) << (screenshotIndex++); - filename << ".png"; + if(fileType) { filename << ".ppm"; } + else { filename << ".png"; } Client::Ref().WriteFile(data, filename.str()); - return 0; + lua_pushstring(l, filename.str().c_str()); + return 1; } #endif