tron@2186: /* $Id$ */ tron@2186: rubidium@9111: /** @file screenshot.cpp The creation of screenshots! */ rubidium@9111: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" tron@1299: #include "debug.h" rubidium@10039: #include "fileio_func.h" rubidium@8225: #include "viewport_func.h" rubidium@8225: #include "gfx_func.h" rubidium@8254: #include "core/math_func.hpp" tron@430: #include "screenshot.h" tron@2159: #include "variables.h" truelight@6937: #include "blitter/factory.hpp" rubidium@8114: #include "strings_func.h" rubidium@8123: #include "zoom_func.h" rubidium@8130: #include "core/alloc_func.hpp" rubidium@8132: #include "core/endian_func.hpp" rubidium@8139: #include "map_func.h" rubidium@8140: #include "date_func.h" rubidium@10208: #include "company_func.h" truelight@0: rubidium@8264: #include "table/strings.h" rubidium@8264: tron@2121: char _screenshot_format_name[8]; tron@2121: uint _num_screenshot_formats; tron@2121: uint _cur_screenshot_format; belugas@4184: ScreenshotType current_screenshot_type; tron@2121: belugas@6420: /* called by the ScreenShot proc to generate screenshot lines. */ truelight@6878: typedef void ScreenshotCallback(void *userdata, void *buf, uint y, uint pitch, uint n); tron@1991: typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette); truelight@0: rubidium@6248: struct ScreenshotFormat { truelight@0: const char *name; truelight@0: const char *extension; truelight@0: ScreenshotHandlerProc *proc; rubidium@6248: }; truelight@0: truelight@0: //************************************************ truelight@0: //*** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP) truelight@0: //************************************************ truelight@923: #if defined(_MSC_VER) || defined(__WATCOMC__) truelight@0: #pragma pack(push, 1) truelight@0: #endif truelight@0: rubidium@6248: struct BitmapFileHeader { truelight@0: uint16 type; truelight@0: uint32 size; truelight@0: uint32 reserved; truelight@0: uint32 off_bits; rubidium@6248: } GCC_PACK; truelight@0: assert_compile(sizeof(BitmapFileHeader) == 14); truelight@0: truelight@923: #if defined(_MSC_VER) || defined(__WATCOMC__) truelight@0: #pragma pack(pop) truelight@0: #endif truelight@0: rubidium@6248: struct BitmapInfoHeader { truelight@0: uint32 size; truelight@0: int32 width, height; truelight@0: uint16 planes, bitcount; truelight@0: uint32 compression, sizeimage, xpels, ypels, clrused, clrimp; rubidium@6248: }; truelight@0: assert_compile(sizeof(BitmapInfoHeader) == 40); truelight@0: rubidium@6248: struct RgbQuad { truelight@0: byte blue, green, red, reserved; rubidium@6248: }; truelight@0: assert_compile(sizeof(RgbQuad) == 4); truelight@0: belugas@6420: /* generic .BMP writer */ tron@1991: static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) truelight@0: { truelight@0: BitmapFileHeader bfh; truelight@0: BitmapInfoHeader bih; darkvater@318: RgbQuad rq[256]; truelight@0: FILE *f; truelight@0: uint i, padw; truelight@0: uint n, maxlines; truelight@6878: uint pal_size = 0; truelight@6878: uint bpp = pixelformat / 8; truelight@0: truelight@6878: /* only implemented for 8bit and 32bit images so far. */ truelight@6878: if (pixelformat != 8 && pixelformat != 32) return false; truelight@0: Darkvater@5167: f = fopen(name, "wb"); truelight@0: if (f == NULL) return false; truelight@0: belugas@6420: /* each scanline must be aligned on a 32bit boundary */ skidd13@7927: padw = Align(w, 4); truelight@0: truelight@6878: if (pixelformat == 8) pal_size = sizeof(RgbQuad) * 256; truelight@6878: belugas@6420: /* setup the file header */ truelight@0: bfh.type = TO_LE16('MB'); truelight@6878: bfh.size = TO_LE32(sizeof(bfh) + sizeof(bih) + pal_size + padw * h * bpp); truelight@0: bfh.reserved = 0; truelight@6878: bfh.off_bits = TO_LE32(sizeof(bfh) + sizeof(bih) + pal_size); truelight@0: belugas@6420: /* setup the info header */ truelight@0: bih.size = TO_LE32(sizeof(BitmapInfoHeader)); truelight@0: bih.width = TO_LE32(w); truelight@0: bih.height = TO_LE32(h); truelight@0: bih.planes = TO_LE16(1); truelight@6878: bih.bitcount = TO_LE16(pixelformat); truelight@0: bih.compression = 0; truelight@0: bih.sizeimage = 0; truelight@0: bih.xpels = 0; truelight@0: bih.ypels = 0; truelight@0: bih.clrused = 0; truelight@0: bih.clrimp = 0; truelight@0: truelight@6878: if (pixelformat == 8) { truelight@6878: /* convert the palette to the windows format */ truelight@6878: for (i = 0; i != 256; i++) { truelight@6878: rq[i].red = palette[i].r; truelight@6878: rq[i].green = palette[i].g; truelight@6878: rq[i].blue = palette[i].b; truelight@6878: rq[i].reserved = 0; truelight@6878: } truelight@0: } truelight@0: belugas@6420: /* write file header and info header and palette */ tron@430: if (fwrite(&bfh, sizeof(bfh), 1, f) != 1) return false; tron@430: if (fwrite(&bih, sizeof(bih), 1, f) != 1) return false; truelight@6878: if (pixelformat == 8) if (fwrite(rq, sizeof(rq), 1, f) != 1) return false; truelight@0: belugas@6420: /* use by default 64k temp memory */ skidd13@7922: maxlines = Clamp(65536 / padw, 16, 128); truelight@0: belugas@6420: /* now generate the bitmap bits */ truelight@6878: void *buff = MallocT(padw * maxlines * bpp); // by default generate 128 lines at a time. tron@430: if (buff == NULL) { tron@430: fclose(f); tron@430: return false; tron@430: } truelight@0: memset(buff, 0, padw * maxlines); // zero the buffer to have the padding bytes set to 0 truelight@0: belugas@6420: /* start at the bottom, since bitmaps are stored bottom up. */ truelight@0: do { belugas@6420: /* determine # lines */ truelight@0: n = min(h, maxlines); truelight@0: h -= n; truelight@193: belugas@6420: /* render the pixels */ truelight@0: callb(userdata, buff, h, padw, n); truelight@193: belugas@6420: /* write each line */ truelight@193: while (n) truelight@6878: if (fwrite((uint8 *)buff + (--n) * padw * bpp, padw * bpp, 1, f) != 1) { tron@430: free(buff); tron@430: fclose(f); tron@430: return false; tron@430: } tron@430: } while (h != 0); truelight@0: tron@430: free(buff); truelight@0: fclose(f); truelight@0: truelight@0: return true; truelight@0: } truelight@0: truelight@0: //******************************************************** truelight@0: //*** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG) truelight@0: //******************************************************** truelight@0: #if defined(WITH_PNG) truelight@0: #include truelight@0: truelight@0: static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message) truelight@0: { Darkvater@5380: DEBUG(misc, 0, "[libpng] error: %s - %s", message, (char *)png_get_error_ptr(png_ptr)); truelight@0: longjmp(png_ptr->jmpbuf, 1); truelight@0: } truelight@0: truelight@0: static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message) truelight@0: { Darkvater@5380: DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (char *)png_get_error_ptr(png_ptr)); truelight@0: } truelight@0: tron@1991: static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) truelight@0: { darkvater@318: png_color rq[256]; truelight@0: FILE *f; truelight@0: uint i, y, n; truelight@0: uint maxlines; truelight@6878: uint bpp = pixelformat / 8; truelight@0: png_structp png_ptr; truelight@0: png_infop info_ptr; truelight@0: truelight@6878: /* only implemented for 8bit and 32bit images so far. */ truelight@6878: if (pixelformat != 8 && pixelformat != 32) return false; truelight@0: Darkvater@5167: f = fopen(name, "wb"); truelight@0: if (f == NULL) return false; truelight@0: tron@430: png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (char *)name, png_my_error, png_my_warning); truelight@0: tron@430: if (png_ptr == NULL) { truelight@0: fclose(f); truelight@0: return false; truelight@0: } truelight@0: truelight@0: info_ptr = png_create_info_struct(png_ptr); tron@430: if (info_ptr == NULL) { truelight@0: png_destroy_write_struct(&png_ptr, (png_infopp)NULL); truelight@0: fclose(f); truelight@0: return false; truelight@0: } truelight@0: truelight@0: if (setjmp(png_jmpbuf(png_ptr))) { truelight@0: png_destroy_write_struct(&png_ptr, &info_ptr); truelight@0: fclose(f); truelight@0: return false; truelight@0: } truelight@0: truelight@0: png_init_io(png_ptr, f); truelight@193: truelight@0: png_set_filter(png_ptr, 0, PNG_FILTER_NONE); truelight@0: truelight@6878: png_set_IHDR(png_ptr, info_ptr, w, h, 8, pixelformat == 8 ? PNG_COLOR_TYPE_PALETTE : PNG_COLOR_TYPE_RGB, tron@430: PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); truelight@0: truelight@6878: if (pixelformat == 8) { truelight@6878: /* convert the palette to the .PNG format. */ truelight@6878: for (i = 0; i != 256; i++) { truelight@6878: rq[i].red = palette[i].r; truelight@6878: rq[i].green = palette[i].g; truelight@6878: rq[i].blue = palette[i].b; truelight@6878: } truelight@6878: truelight@6878: png_set_PLTE(png_ptr, info_ptr, rq, 256); truelight@0: } truelight@0: truelight@0: png_write_info(png_ptr, info_ptr); truelight@0: png_set_flush(png_ptr, 512); truelight@0: truelight@6878: if (pixelformat == 32) { truelight@6878: png_color_8 sig_bit; truelight@6878: truelight@6878: /* Save exact color/alpha resolution */ truelight@6878: sig_bit.alpha = 0; truelight@6878: sig_bit.blue = 8; truelight@6878: sig_bit.green = 8; truelight@6878: sig_bit.red = 8; truelight@6878: sig_bit.gray = 8; truelight@6878: png_set_sBIT(png_ptr, info_ptr, &sig_bit); truelight@6878: smatz@9543: #if TTD_ENDIAN == TTD_LITTLE_ENDIAN truelight@6878: png_set_bgr(png_ptr); truelight@6878: png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); truelight@6878: #else truelight@6878: png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); smatz@9543: #endif /* TTD_ENDIAN == TTD_LITTLE_ENDIAN */ truelight@6878: } truelight@6878: belugas@6420: /* use by default 64k temp memory */ skidd13@7922: maxlines = Clamp(65536 / w, 16, 128); truelight@0: belugas@6420: /* now generate the bitmap bits */ truelight@6878: void *buff = MallocT(w * maxlines * bpp); // by default generate 128 lines at a time. tron@430: if (buff == NULL) { tron@430: png_destroy_write_struct(&png_ptr, &info_ptr); tron@430: fclose(f); tron@430: return false; tron@430: } truelight@6878: memset(buff, 0, w * maxlines * bpp); truelight@0: truelight@0: y = 0; truelight@0: do { belugas@6420: /* determine # lines to write */ truelight@0: n = min(h - y, maxlines); truelight@193: belugas@6420: /* render the pixels into the buffer */ truelight@0: callb(userdata, buff, y, w, n); truelight@0: y += n; truelight@0: belugas@6420: /* write them to png */ tron@430: for (i = 0; i != n; i++) truelight@6878: png_write_row(png_ptr, (png_bytep)buff + i * w * bpp); truelight@0: } while (y != h); truelight@0: truelight@0: png_write_end(png_ptr, info_ptr); truelight@0: png_destroy_write_struct(&png_ptr, &info_ptr); truelight@0: tron@430: free(buff); truelight@0: fclose(f); truelight@0: return true; truelight@0: } truelight@4300: #endif /* WITH_PNG */ truelight@0: truelight@0: truelight@0: //************************************************ truelight@0: //*** SCREENSHOT CODE FOR ZSOFT PAINTBRUSH (.PCX) truelight@0: //************************************************ truelight@0: rubidium@6248: struct PcxHeader { truelight@0: byte manufacturer; truelight@0: byte version; truelight@0: byte rle; truelight@0: byte bpp; truelight@0: uint32 unused; truelight@0: uint16 xmax, ymax; truelight@0: uint16 hdpi, vdpi; rubidium@6491: byte pal_small[16 * 3]; truelight@0: byte reserved; truelight@0: byte planes; truelight@0: uint16 pitch; truelight@0: uint16 cpal; truelight@0: uint16 width; truelight@0: uint16 height; truelight@0: byte filler[54]; rubidium@6248: }; truelight@0: assert_compile(sizeof(PcxHeader) == 128); truelight@0: tron@1991: static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette) truelight@0: { truelight@0: FILE *f; truelight@0: uint maxlines; truelight@0: uint y; truelight@0: PcxHeader pcx; peter1138@4019: bool success; truelight@0: truelight@6878: if (pixelformat == 32) { truelight@6878: DEBUG(misc, 0, "Can't convert a 32bpp screenshot to PCX format. Please pick an other format."); truelight@6878: return false; truelight@6878: } truelight@0: if (pixelformat != 8 || w == 0) truelight@0: return false; truelight@0: Darkvater@5167: f = fopen(name, "wb"); truelight@0: if (f == NULL) return false; truelight@0: truelight@0: memset(&pcx, 0, sizeof(pcx)); truelight@193: belugas@6420: /* setup pcx header */ truelight@0: pcx.manufacturer = 10; truelight@0: pcx.version = 5; truelight@0: pcx.rle = 1; truelight@0: pcx.bpp = 8; tron@430: pcx.xmax = TO_LE16(w - 1); tron@430: pcx.ymax = TO_LE16(h - 1); truelight@0: pcx.hdpi = TO_LE16(320); truelight@0: pcx.vdpi = TO_LE16(320); truelight@0: truelight@0: pcx.planes = 1; truelight@0: pcx.cpal = TO_LE16(1); truelight@0: pcx.width = pcx.pitch = TO_LE16(w); truelight@0: pcx.height = TO_LE16(h); truelight@193: belugas@6420: /* write pcx header */ tron@430: if (fwrite(&pcx, sizeof(pcx), 1, f) != 1) { tron@430: fclose(f); tron@430: return false; tron@430: } truelight@0: belugas@6420: /* use by default 64k temp memory */ skidd13@7922: maxlines = Clamp(65536 / w, 16, 128); truelight@0: belugas@6420: /* now generate the bitmap bits */ truelight@6878: uint8 *buff = MallocT(w * maxlines); // by default generate 128 lines at a time. tron@430: if (buff == NULL) { tron@430: fclose(f); tron@430: return false; tron@430: } tron@430: memset(buff, 0, w * maxlines); // zero the buffer to have the padding bytes set to 0 truelight@0: truelight@0: y = 0; truelight@0: do { belugas@6420: /* determine # lines to write */ tron@430: uint n = min(h - y, maxlines); tron@430: uint i; truelight@193: belugas@6420: /* render the pixels into the buffer */ truelight@0: callb(userdata, buff, y, w, n); truelight@0: y += n; truelight@0: belugas@6420: /* write them to pcx */ tron@430: for (i = 0; i != n; i++) { truelight@6878: const uint8 *bufp = buff + i * w; tron@2004: byte runchar = bufp[0]; tron@2004: uint runcount = 1; tron@2004: uint j; truelight@0: belugas@6420: /* for each pixel... */ tron@2004: for (j = 1; j < w; j++) { truelight@6878: uint8 ch = bufp[j]; tron@2004: truelight@0: if (ch != runchar || runcount >= 0x3f) { tron@430: if (runcount > 1 || (runchar & 0xC0) == 0xC0) tron@430: if (fputc(0xC0 | runcount, f) == EOF) { tron@430: free(buff); tron@430: fclose(f); tron@430: return false; tron@430: } tron@430: if (fputc(runchar, f) == EOF) { tron@430: free(buff); tron@430: fclose(f); tron@430: return false; tron@430: } truelight@0: runcount = 0; truelight@0: runchar = ch; truelight@0: } truelight@0: runcount++; truelight@0: } truelight@0: belugas@6420: /* write remaining bytes.. */ tron@430: if (runcount > 1 || (runchar & 0xC0) == 0xC0) tron@430: if (fputc(0xC0 | runcount, f) == EOF) { tron@430: free(buff); tron@430: fclose(f); tron@430: return false; tron@430: } tron@430: if (fputc(runchar, f) == EOF) { tron@430: free(buff); tron@430: fclose(f); tron@430: return false; tron@430: } truelight@0: } truelight@0: } while (y != h); truelight@0: tron@430: free(buff); tron@430: belugas@6420: /* write 8-bit color palette */ tron@430: if (fputc(12, f) == EOF) { tron@430: fclose(f); tron@430: return false; tron@430: } tron@1991: smatz@9551: /* Palette is word-aligned, copy it to a temporary byte array */ smatz@9551: byte tmp[256 * 3]; tron@4079: smatz@9551: for (uint i = 0; i < 256; i++) { smatz@9551: tmp[i * 3 + 0] = palette[i].r; smatz@9551: tmp[i * 3 + 1] = palette[i].g; smatz@9551: tmp[i * 3 + 2] = palette[i].b; tron@430: } smatz@9551: success = fwrite(tmp, sizeof(tmp), 1, f) == 1; peter1138@4019: truelight@0: fclose(f); truelight@0: peter1138@4019: return success; truelight@0: } truelight@0: truelight@0: //************************************************ truelight@0: //*** GENERIC SCREENSHOT CODE truelight@0: //************************************************ truelight@0: truelight@0: static const ScreenshotFormat _screenshot_formats[] = { truelight@0: #if defined(WITH_PNG) truelight@0: {"PNG", "png", &MakePNGImage}, truelight@0: #endif matthijs@4360: {"BMP", "bmp", &MakeBmpImage}, truelight@0: {"PCX", "pcx", &MakePCXImage}, truelight@0: }; truelight@0: rubidium@6247: void InitializeScreenshotFormats() truelight@0: { tron@430: int i, j; tron@430: for (i = 0, j = 0; i != lengthof(_screenshot_formats); i++) tron@430: if (!strcmp(_screenshot_format_name, _screenshot_formats[i].extension)) { tron@430: j = i; tron@430: break; tron@430: } truelight@0: _cur_screenshot_format = j; truelight@0: _num_screenshot_formats = lengthof(_screenshot_formats); belugas@4185: current_screenshot_type = SC_NONE; truelight@0: } truelight@0: truelight@0: const char *GetScreenshotFormatDesc(int i) truelight@0: { truelight@0: return _screenshot_formats[i].name; truelight@0: } truelight@0: truelight@0: void SetScreenshotFormat(int i) truelight@0: { truelight@0: _cur_screenshot_format = i; truelight@0: strcpy(_screenshot_format_name, _screenshot_formats[i].extension); truelight@0: } truelight@0: belugas@6420: /* screenshot generator that dumps the current video buffer */ truelight@6878: static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n) truelight@0: { truelight@6937: Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); truelight@6937: void *src = blitter->MoveTo(_screen.dst_ptr, 0, y); truelight@6985: blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch); truelight@0: } truelight@0: frosch@8249: /** generate a large piece of the world frosch@8249: * @param userdata Viewport area to draw frosch@8249: * @param buf Videobuffer with same bitdepth as current blitter frosch@8249: * @param y First line to render frosch@8249: * @param pitch Pitch of the videobuffer frosch@8249: * @param n Number of lines to render frosch@8249: */ truelight@6878: static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n) truelight@0: { tron@4522: ViewPort *vp = (ViewPort *)userdata; truelight@0: DrawPixelInfo dpi, *old_dpi; truelight@0: int wx, left; truelight@0: frosch@8249: /* We are no longer rendering to the screen */ frosch@8249: DrawPixelInfo old_screen = _screen; frosch@8249: bool old_disable_anim = _screen_disable_anim; frosch@8249: frosch@8249: _screen.dst_ptr = buf; frosch@8249: _screen.width = pitch; frosch@8249: _screen.height = n; frosch@8249: _screen.pitch = pitch; frosch@8249: _screen_disable_anim = true; frosch@8249: truelight@0: old_dpi = _cur_dpi; truelight@0: _cur_dpi = &dpi; truelight@0: truelight@0: dpi.dst_ptr = buf; truelight@0: dpi.height = n; truelight@0: dpi.width = vp->width; truelight@0: dpi.pitch = pitch; truelight@6624: dpi.zoom = ZOOM_LVL_WORLD_SCREENSHOT; truelight@0: dpi.left = 0; truelight@0: dpi.top = y; truelight@0: frosch@8249: /* Render viewport in blocks of 1600 pixels width */ truelight@0: left = 0; truelight@0: while (vp->width - left != 0) { truelight@0: wx = min(vp->width - left, 1600); truelight@0: left += wx; truelight@193: truelight@193: ViewportDoDraw(vp, truelight@6626: ScaleByZoom(left - wx - vp->left, vp->zoom) + vp->virtual_left, truelight@6626: ScaleByZoom(y - vp->top, vp->zoom) + vp->virtual_top, truelight@6626: ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left, truelight@6626: ScaleByZoom((y + n) - vp->top, vp->zoom) + vp->virtual_top truelight@0: ); truelight@0: } truelight@0: truelight@0: _cur_dpi = old_dpi; frosch@8249: frosch@8249: /* Switch back to rendering to the screen */ frosch@8249: _screen = old_screen; frosch@8249: _screen_disable_anim = old_disable_anim; truelight@0: } truelight@0: truelight@0: static char *MakeScreenshotName(const char *ext) truelight@0: { rubidium@6929: static char filename[MAX_PATH]; truelight@0: int serial; rubidium@6929: size_t len; truelight@0: rubidium@10207: if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) { skidd13@10310: strecpy(_screenshot_name, "screenshot", lastof(_screenshot_name)); truelight@0: } else { rubidium@10207: SetDParam(0, _local_company); peter1138@7058: SetDParam(1, _date); Darkvater@4912: GetString(_screenshot_name, STR_4004, lastof(_screenshot_name)); truelight@0: } truelight@0: rubidium@6929: /* Add extension to screenshot file */ rubidium@6875: SanitizeFilename(_screenshot_name); rubidium@6929: len = strlen(_screenshot_name); rubidium@6929: snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext); truelight@0: rubidium@6929: for (serial = 1;; serial++) { rubidium@6929: snprintf(filename, lengthof(filename), "%s%s", _personal_dir, _screenshot_name); rubidium@6929: if (!FileExists(filename)) break; rubidium@6929: /* If file exists try another one with same name, but just with a higher index */ rubidium@6929: snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, "#%d.%s", serial, ext); truelight@0: } truelight@0: truelight@0: return filename; truelight@0: } truelight@0: belugas@4184: void SetScreenshotType(ScreenshotType t) belugas@4184: { belugas@4184: current_screenshot_type = t; belugas@4184: } belugas@4184: rubidium@6247: bool IsScreenshotRequested() belugas@4184: { belugas@4184: return (current_screenshot_type != SC_NONE); belugas@4184: } belugas@4184: rubidium@6247: static bool MakeSmallScreenshot() truelight@0: { truelight@0: const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; truelight@6878: return sf->proc(MakeScreenshotName(sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); truelight@0: } truelight@0: rubidium@6247: static bool MakeWorldScreenshot() truelight@0: { truelight@0: ViewPort vp; truelight@0: const ScreenshotFormat *sf; truelight@0: truelight@6624: vp.zoom = ZOOM_LVL_WORLD_SCREENSHOT; truelight@0: vp.left = 0; truelight@0: vp.top = 0; belugas@4184: vp.virtual_left = -(int)MapMaxX() * TILE_PIXELS; belugas@4184: vp.virtual_top = 0; belugas@4184: vp.virtual_width = (MapMaxX() + MapMaxY()) * TILE_PIXELS; belugas@4184: vp.width = vp.virtual_width; belugas@4184: vp.virtual_height = (MapMaxX() + MapMaxY()) * TILE_PIXELS >> 1; belugas@4184: vp.height = vp.virtual_height; truelight@0: truelight@0: sf = _screenshot_formats + _cur_screenshot_format; truelight@6878: return sf->proc(MakeScreenshotName(sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); truelight@0: } belugas@4184: rubidium@6247: bool MakeScreenshot() belugas@4184: { belugas@4184: switch (current_screenshot_type) { belugas@4184: case SC_VIEWPORT: belugas@4184: UndrawMouseCursor(); belugas@5371: DrawDirtyBlocks(); belugas@4184: current_screenshot_type = SC_NONE; belugas@4184: return MakeSmallScreenshot(); belugas@4184: case SC_WORLD: belugas@4184: current_screenshot_type = SC_NONE; belugas@4184: return MakeWorldScreenshot(); belugas@4184: default: return false; belugas@4184: } belugas@4184: } belugas@4184: Darkvater@5380: Darkvater@5380: