Ticket #7996: screenshot4.diff
File screenshot4.diff, 7.6 KB (added by , 22 years ago) |
---|
-
scummvm/Makefile
diff -ur ScummVM-cvs20021001/scummvm/Makefile ScummVM-cvs20021001+hack/scummvm/Makefile
old new 31 31 DEFINES += -DCOMPRESSED_SOUND_FILE 32 32 LIBS += -lmad 33 33 34 # Uncomment this to activate the PNG lib for screenshots 35 # DEFINES += -DHAVE_LIBPNG 36 # LIBS += -lpng 37 34 38 # Uncomment this to activate the ALSA lib for midi 35 39 # DEFINES += -DUSE_ALSA 36 40 # LIBS += -lasound -
scummvm/README
diff -ur ScummVM-cvs20021001/scummvm/README ScummVM-cvs20021001+hack/scummvm/README
old new 264 264 Ctrl-g - runs in really REALLY fast mode. 265 265 Ctrl-d - starts the debugger. 266 266 Ctrl-s - shows memory consumption. 267 Alt-s - save a screenshot 267 268 [ and ] - master volume, down/up 268 269 - and + - text speed, slower / faster 269 270 F5 - displays a save/load box. -
scummvm/backends/sdl/sdl-common.cpp
diff -ur ScummVM-cvs20021001/scummvm/backends/sdl/sdl-common.cpp ScummVM-cvs20021001+hack/scummvm/backends/sdl/sdl-common.cpp
old new 23 23 #include "sound/mididrv.h" 24 24 #include "common/scaler.h" 25 25 #include "common/engine.h" // Only #included for error() and warning() 26 #include "common/util.h" 26 27 27 28 #include "scummvm.xpm" 28 29 … … 449 450 b |= KBD_ALT; 450 451 event->kbd.flags = b; 451 452 453 // Alt-S makes a screenshot 454 if (b == KBD_ALT && ev.key.keysym.sym=='s') 455 saveScreenshot(this); 456 452 457 // Alt-Return toggles full screen mode 453 458 if (b == KBD_ALT && ev.key.keysym.sym==SDLK_RETURN) { 454 459 property(PROP_TOGGLE_FULLSCREEN, NULL); -
scummvm/backends/sdl/sdl.cpp
diff -ur ScummVM-cvs20021001/scummvm/backends/sdl/sdl.cpp ScummVM-cvs20021001+hack/scummvm/backends/sdl/sdl.cpp
old new 39 39 uint32 property(int param, Property *value); 40 40 41 41 // Overlay 42 virtual bool is_overlay_visible(); 42 43 virtual void show_overlay(); 43 44 virtual void hide_overlay(); 44 45 virtual void clear_overlay(); … … 441 442 return OSystem_SDL_Common::property(param, value); 442 443 } 443 444 445 bool OSystem_SDL_Normal::is_overlay_visible() 446 { 447 return _overlay_visible; 448 } 444 449 445 450 void OSystem_SDL_Normal::show_overlay() 446 451 { -
scummvm/common/system.h
diff -ur ScummVM-cvs20021001/scummvm/common/system.h ScummVM-cvs20021001+hack/scummvm/common/system.h
old new 160 160 virtual void quit() = 0; 161 161 162 162 // Overlay 163 virtual bool is_overlay_visible() = 0; 163 164 virtual void show_overlay() = 0; 164 165 virtual void hide_overlay() = 0; 165 166 virtual void clear_overlay() = 0; -
scummvm/common/util.cpp
diff -ur ScummVM-cvs20021001/scummvm/common/util.cpp ScummVM-cvs20021001+hack/scummvm/common/util.cpp
old new 20 20 21 21 #include "stdafx.h" 22 22 #include "util.h" 23 #include "engine.h" // For debug/warning/error 24 25 #ifdef HAVE_LIBPNG 26 #include <png.h> 27 28 #ifndef png_jmpbuf 29 #define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) 30 #endif 31 #endif 23 32 24 33 // 25 34 // 8-bit alpha blending routines … … 157 166 } 158 167 return num; 159 168 } 169 170 // Global to avoid scary GCC warning 171 static FILE *_fp; 172 173 void saveScreenshot(OSystem *syst) 174 { 175 #ifdef HAVE_LIBPNG 176 png_structp png_ptr; 177 png_infop info_ptr; 178 char filename[255]; 179 int16 *buf; 180 png_byte *image; 181 int i, j; 182 183 // FIXME: Is there a better way of making a temporary filename? Should 184 // it be made into a separate function? 185 186 for (i = 0; i < 1000; i++) { 187 sprintf(filename, "scr%03d.png", i); 188 _fp = fopen(filename, "rb"); 189 if (!_fp) 190 break; 191 } 192 193 if (_fp) { 194 warning("Could not create temporary filename for screenshot"); 195 fclose(_fp); 196 return; 197 } 198 199 _fp = fopen(filename, "wb"); 200 if (!_fp) { 201 warning("Could not create temporary file for screenshot"); 202 return; 203 } 204 205 // FIXME: We need a way to get the correct screen size. For now, use 206 // the same dirty hack assumptions as newgui.cpp 207 208 int screen_height = 240; 209 int screen_width = 320; 210 int screen_pitch = 320; 211 212 // Apparently it's possible to slim down libpng quite a bit, but I'm 213 // going to assume that all the basic features are still there. 214 215 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 216 (png_voidp) NULL, (png_error_ptr) NULL, (png_error_ptr) NULL); 217 218 if (!png_ptr) { 219 warning("Could not create PNG write struct"); 220 fclose(_fp); 221 return; 222 } 223 224 info_ptr = png_create_info_struct(png_ptr); 225 if (!info_ptr) { 226 warning("Could not create PNG info struct"); 227 fclose(_fp); 228 png_destroy_write_struct(&png_ptr, (png_infopp) NULL); 229 return; 230 } 231 232 #ifndef PNG_SETJMP_NOT_SUPPORTED 233 if (setjmp(png_jmpbuf(png_ptr))) { 234 warning("Internal libpng error"); 235 fclose(_fp); 236 png_destroy_write_struct(&png_ptr, &info_ptr); 237 return; 238 } 239 #endif 240 241 png_init_io(png_ptr, _fp); 242 243 buf = (int16 *) malloc(screen_width * screen_height * sizeof(int16)); 244 if (!buf) { 245 warning("Could not allocate memory for screen buffer"); 246 fclose(_fp); 247 png_destroy_write_struct(&png_ptr, &info_ptr); 248 return; 249 } 250 251 image = (png_byte *) calloc(screen_width, 3 * sizeof(png_byte)); 252 if (!image) { 253 warning("Could not allocate memory for PNG image"); 254 free(buf); 255 fclose(_fp); 256 png_destroy_write_struct(&png_ptr, &info_ptr); 257 return; 258 } 259 260 // Grab a screenshot 261 262 // FIXME: I'd really like some way of getting the image that is 263 // actually being displayed instead. 264 265 if (!syst->is_overlay_visible()) { 266 syst->show_overlay(); 267 syst->grab_overlay(buf, screen_pitch); 268 syst->hide_overlay(); 269 } else 270 syst->grab_overlay(buf, screen_pitch); 271 272 png_set_IHDR(png_ptr, info_ptr, screen_width, screen_height, 8, 273 PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, 274 PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); 275 276 png_write_info(png_ptr, info_ptr); 277 278 for (i = 0; i < screen_height; i++) { 279 for (j = 0; j < screen_width; j++) { 280 image[j * 3 + 0] = RED_FROM_16(buf[i * screen_width + j]); 281 image[j * 3 + 1] = GREEN_FROM_16(buf[i * screen_width + j]); 282 image[j * 3 + 2] = BLUE_FROM_16(buf[i * screen_width + j]); 283 } 284 285 png_write_rows(png_ptr, &image, 1); 286 } 287 288 png_write_end(png_ptr, info_ptr); 289 png_destroy_write_struct(&png_ptr, &info_ptr); 290 291 free(buf); 292 free(image); 293 fclose(_fp); 294 295 debug(1, "Saved screenshot as %s", filename); 296 #else 297 // FIXME: Should we have a BMP writer as a fallback here? 298 warning("No PNG support! Screenshot feature disabled"); 299 #endif 300 } 301 -
scummvm/common/util.h
diff -ur ScummVM-cvs20021001/scummvm/common/util.h ScummVM-cvs20021001+hack/scummvm/common/util.h
old new 21 21 #ifndef COMMON_UTIL_H 22 22 #define COMMON_UTIL_H 23 23 24 #include "system.h" 24 25 #include "scummsys.h" 25 26 26 27 #ifndef ABS … … 65 66 // Resource string length 66 67 int resStrLen(const char *src); 67 68 69 void saveScreenshot(OSystem *system); 70 68 71 #endif