From 9c4d134ab304794b755139e90ca6da9de73a1e9a Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 24 Aug 2008 18:52:10 +0000 Subject: JPEG screenshots --- configure.in | 19 +++++++---- doc/installation.html | 9 ++--- src/Makefile.am | 3 +- src/client/video.cc | 30 ++++++++++++++--- src/render/Makefile.am | 5 +-- src/render/jpgfile.cc | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/render/jpgfile.h | 34 +++++++++++++++++++ src/render/pngfile.cc | 5 +-- src/render/pngfile.h | 2 +- 9 files changed, 175 insertions(+), 21 deletions(-) create mode 100644 src/render/jpgfile.cc create mode 100644 src/render/jpgfile.h diff --git a/configure.in b/configure.in index 3c6db7a..380569d 100644 --- a/configure.in +++ b/configure.in @@ -179,7 +179,7 @@ else AC_CHECK_HEADER(GL/gl.h, HAVE_OPENGL=yes AC_DEFINE(HAVE_OPENGL, 1, [Define this if you have OpenGL]), - AC_MSG_WARN([OpenGL include file GL/gl.h not found]) + AC_MSG_ERROR([OpenGL include file GL/gl.h not found]) ) AC_CHECK_HEADER(GL/glext.h, @@ -194,14 +194,21 @@ else AC_SUBST(GL_CFLAGS) AC_CHECK_HEADER(png.h, - HAVE_OPENGL=yes - AC_DEFINE(HAVE_PNG, 1, [Define this if you have libpng]), - AC_MSG_WARN([libpng include file png.h not found]) + HAVE_LIBPNG=yes + AC_DEFINE(HAVE_LIBPNG, 1, [Define this if you have libpng]), + AC_MSG_ERROR([libpng include file png.h not found]) ) - LIBPNG_LIBS="-lpng" AC_SUBST(LIBPNG_LIBS) + AC_CHECK_HEADER(jpeglib.h, + HAVE_LIBJPEG=yes + AC_DEFINE(HAVE_LIBJPEG, 1, [Define this if you have libjpeg]), + AC_MSG_ERROR([libjpeg include file jpeglib.h not found]) + ) + LIBJPG_LIBS="-ljpeg" + AC_SUBST(LIBJPG_LIBS) + AC_CHECK_HEADER(AL/al.h, HAVE_OPENGL=yes AC_DEFINE(HAVE_OPENAL, 1, [Define this if you have OpenAL]), @@ -293,7 +300,7 @@ The Osirion Project $VERSION Configuration summary: platform ........... $host flags .............. $CXXFLAGS - libraries .......... $HOST_LIBS + libraries .......... $HOST_LIBS $LIBJPG_LIBS $LIBPNG_LIBS ncurses ............ $HAVE_CURSES build client ....... $BUILD_CLIENT opengl ............. $GL_LIBS diff --git a/doc/installation.html b/doc/installation.html index 545aff7..e9a075f 100644 --- a/doc/installation.html +++ b/doc/installation.html @@ -80,10 +80,11 @@ cd osirion-0.1_258-linux

To build the client: - - - - + + + + +
SDLversion 1.2 or newer
OpenGLversion 1.1 or newer
OpenALversion 1.1 or newer
libpngversion 1.2 or newer
libSDL 1.2
libpng
libjpeg-6b
OpenGL
OpenAL 1.1

You will also need a recent version of gcc, GNU make, automake and libtool. diff --git a/src/Makefile.am b/src/Makefile.am index a3a5c03..494e50b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -40,5 +40,6 @@ osirion_LDADD = $(top_builddir)/src/game/libgame.la \ $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/model/libmodel.la \ $(top_builddir)/src/math/libmath.la $(top_builddir)/src/auxiliary/libauxiliary.la \ $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/sys/libsys.la \ - $(top_builddir)/src/auxiliary/libauxiliary.la $(AL_LIBS) $(GL_LIBS) $(HOST_LIBS) $(LIBPNG_LIBS) $(ICON_CLIENT) + $(top_builddir)/src/auxiliary/libauxiliary.la \ + $(AL_LIBS) $(GL_LIBS) $(HOST_LIBS) $(LIBPNG_LIBS) $(LIBJPG_LIBS) $(ICON_CLIENT) osirion_LDFLAGS = $(LIBSDL_LIBS) 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); } diff --git a/src/render/Makefile.am b/src/render/Makefile.am index 99b1847..3e3c0c8 100644 --- a/src/render/Makefile.am +++ b/src/render/Makefile.am @@ -9,8 +9,9 @@ endif librender_la_LDFLAGS = -avoid-version -no-undefined @GL_LIBS@ librender_la_LIBADD = $(top_builddir)/src/math/libmath.la -librender_la_SOURCES = camera.cc draw.cc dust.cc gl.cc image.cc pngfile.cc \ - render.cc text.cc textures.cc tga.cc +librender_la_SOURCES = camera.cc draw.cc dust.cc gl.cc image.cc jpgfile.cc \ + pngfile.cc render.cc text.cc textures.cc tga.cc noinst_HEADERS = camera.h draw.h dust.h gl.h image.h render.h text.h textures.h \ tga.h _SOURCES = pngfile.h +_SOURCES = jpgfile.h diff --git a/src/render/jpgfile.cc b/src/render/jpgfile.cc new file mode 100644 index 0000000..74cdea9 --- /dev/null +++ b/src/render/jpgfile.cc @@ -0,0 +1,89 @@ +/* + render/jpgfile.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +/* +Notes: + +http://www.zarb.org/~gc/html/libpng.html + +*/ + +#include +#include + +#include "filesystem/filesystem.h" +#include "render/jpgfile.h" +#include "sys/sys.h" + +extern "C" { + #include "jpeglib.h" +} + +namespace render { + +Image *JPG::load(const char *filename) +{ + Image *image = 0; + + if (!filename) + return 0; + + filesystem::File *jpg_file = filesystem::open(filename); + if (!jpg_file) { + //con_warn << "Could not open " << filename << std::endl; + return 0; + } + + + filesystem::close(jpg_file); + +// con_debug << " " << filename << " " << png_width << "x" << png_height << "x" << channels * png_depth << "bpp" << std::endl; + + return image; +} + +void JPG::save(const char *filename, Image & image, int jpeg_quality) +{ + struct jpeg_compress_struct jpeg_compression_info; + struct jpeg_error_mgr jerr; + + JSAMPROW row_pointer[1]; + int row_stride; + + FILE *jpg_file = fopen(filename, "wb"); + if (!jpg_file) { + con_warn << "Could not write " << filename << std::endl; + return; + } + + jpeg_compression_info.err = jpeg_std_error(&jerr); + jpeg_create_compress(&jpeg_compression_info); + jpeg_stdio_dest(&jpeg_compression_info, jpg_file); + + jpeg_compression_info.image_width = image.width(); + jpeg_compression_info.image_height = image.height(); + jpeg_compression_info.input_components = image.channels(); + jpeg_compression_info.in_color_space = JCS_RGB; + + jpeg_set_defaults(&jpeg_compression_info); + jpeg_set_quality(&jpeg_compression_info, jpeg_quality, TRUE); + jpeg_start_compress(&jpeg_compression_info, TRUE); + row_stride = image.width() * image.channels(); + + while (jpeg_compression_info.next_scanline < jpeg_compression_info.image_height) { + row_pointer[0] = image[jpeg_compression_info.next_scanline * row_stride]; + jpeg_write_scanlines(&jpeg_compression_info, row_pointer, 1); + } + + jpeg_finish_compress(&jpeg_compression_info); + fclose(jpg_file); + + jpeg_destroy_compress(&jpeg_compression_info); + + con_print << "Wrote " << filename << std::endl; +} + +} diff --git a/src/render/jpgfile.h b/src/render/jpgfile.h new file mode 100644 index 0000000..858a8a3 --- /dev/null +++ b/src/render/jpgfile.h @@ -0,0 +1,34 @@ +/* + render/jpgfile.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + + +#ifndef _INCLUDED_RENDER_JPGFILE_H_ +#define _INCLUDED_RENDER_JPGFILE_H_ + +#include "render/image.h" + +namespace render +{ + +/// a class for loading and saving .jpg files +class JPG { + +public: + /// load a JPG image file from disk + /** @param filename short path to the filename to be loaded + */ + static Image *load(const char * filename); + + /// write an image to a JPG file + /** @param filename short path to the file to write the image data to + */ + static void save(const char *filename, Image & image, int jpeg_quality); +}; + +} + +#endif //_INCLUDED_RENDER_JPGFILE_H_ + diff --git a/src/render/pngfile.cc b/src/render/pngfile.cc index 8038d22..bff6a54 100644 --- a/src/render/pngfile.cc +++ b/src/render/pngfile.cc @@ -1,5 +1,5 @@ /* - render/png.cc + render/pngfile.cc This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ @@ -11,8 +11,9 @@ http://www.zarb.org/~gc/html/libpng.html */ +#include "png.h" + #include -#include #include diff --git a/src/render/pngfile.h b/src/render/pngfile.h index a7beb7c..4559f70 100644 --- a/src/render/pngfile.h +++ b/src/render/pngfile.h @@ -1,5 +1,5 @@ /* - render/png.h + render/pngfile.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ -- cgit v1.2.3