From 9c4d134ab304794b755139e90ca6da9de73a1e9a Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 24 Aug 2008 18:52:10 +0000 Subject: JPEG screenshots --- src/client/video.cc | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'src/client/video.cc') diff --git a/src/client/video.cc b/src/client/video.cc index 39e2c2a..ef1f82e 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -16,6 +16,7 @@ #include "render/render.h" #include "render/tga.h" #include "render/pngfile.h" +#include "render/jpgfile.h" #include "core/core.h" #include "filesystem/filesystem.h" #include "sys/sys.h" @@ -48,6 +49,7 @@ core::Cvar *r_height; core::Cvar *r_fullscreen; core::Cvar *screenshotformat; +core::Cvar *screenshotquality; void restart() { @@ -86,8 +88,11 @@ bool init() r_fullscreen = core::Cvar::get("r_fullscreen", "0", core::Cvar::Archive); r_fullscreen->set_info("[bool] enable or disable fullscreen video"); - screenshotformat = core::Cvar::get("screenshotformat", "tga", core::Cvar::Archive); - screenshotformat->set_info("[string] screenshot format: tga png"); + screenshotformat = core::Cvar::get("screenshotformat", "jpg", core::Cvar::Archive); + screenshotformat->set_info("[string] screenshot format: jpg png tga"); + + screenshotquality = core::Cvar::get("screenshotquality", "85", core::Cvar::Archive); + screenshotquality->set_info("[int] screenshot jpg quality"); int bpp = 0; int flags = 0; @@ -217,6 +222,7 @@ void screenshot() std::string filename; const int TYPETGA = 0; const int TYPEPNG = 1; + const int TYPEJPG = 2; int filetype = TYPETGA; // make sure the screenshots folder exists @@ -226,20 +232,32 @@ void screenshot() aux::lowercase(screenshotformat->str()); - if (screenshotformat->str().compare("png") == 0) { + if ((screenshotformat->str().compare("jpg") == 0) || (screenshotformat->str().compare("jpeg") == 0)) { + filetype = TYPEJPG; + if (screenshotquality->value() < 10) { + (*screenshotquality) = 10; + } else if (screenshotquality->value() > 100) { + (*screenshotquality) = 100; + } + + } else if (screenshotformat->str().compare("png") == 0) { filetype = TYPEPNG; + + } else if (screenshotformat->str().compare("tga") == 0) { + filetype = TYPETGA; + } else { filetype = TYPETGA; (*screenshotformat) = "tga"; } - // find the first available screenshotxxx.tga + // find the first available screenshotxxxx do { std::stringstream nstr; nstr << screenshot_number; shortname.assign(nstr.str()); - while(shortname.size() < 3) + while(shortname.size() < 4) shortname.insert(0, 1, '0'); shortname.insert(0, "screenshots/osirion"); @@ -267,6 +285,8 @@ void screenshot() if (filetype == TYPEPNG) { render::PNG::save(filename.c_str(), image); + } else if (filetype == TYPEJPG) { + render::JPG::save(filename.c_str(), image, (int) screenshotquality->value()); } else if (filetype == TYPETGA) { render::TGA::save(filename.c_str(), image); } -- cgit v1.2.3