MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / screenshot

Method screenshot

src/Engine/Screen.cpp:495–523  ·  view source on GitHub ↗

* Saves a screenshot of the screen's contents. * @param filename Filename of the PNG file. */

Source from the content-addressed store, hash-verified

493 * @param filename Filename of the PNG file.
494 */
495void Screen::screenshot(const std::string &filename) const
496{
497 SDL_Surface *screenshot = SDL_AllocSurface(0, getWidth() - getWidth()%4, getHeight(), 24, 0xff, 0xff00, 0xff0000, 0);
498
499 if (isOpenGLEnabled())
500 {
501#ifndef __NO_OPENGL
502 GLenum format = GL_RGB;
503
504 for (int y = 0; y < getHeight(); ++y)
505 {
506 glReadPixels(0, getHeight()-(y+1), getWidth() - getWidth()%4, 1, format, GL_UNSIGNED_BYTE, ((Uint8*)screenshot->pixels) + y*screenshot->pitch);
507 }
508 glErrorCheck();
509#endif
510 }
511 else
512 {
513 SDL_BlitSurface(_screen, 0, screenshot, 0);
514 }
515
516 unsigned error = lodepng::encode(filename, (const unsigned char *)(screenshot->pixels), getWidth() - getWidth()%4, getHeight(), LCT_RGB);
517 if (error)
518 {
519 Log(LOG_ERROR) << "Saving to PNG failed: " << lodepng_error_text(error);
520 }
521
522 SDL_FreeSurface(screenshot);
523}
524
525
526/**

Callers

nothing calls this directly

Calls 2

encodeFunction · 0.85
lodepng_error_textFunction · 0.85

Tested by

no test coverage detected