tron@2186: /* $Id$ */ tron@2186: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" tron@1299: #include "debug.h" rubidium@7425: #include "fileio.h" rubidium@8721: #include "viewport_func.h" rubidium@8721: #include "gfx_func.h" rubidium@8750: #include "core/math_func.hpp" tron@430: #include "screenshot.h" tron@2159: #include "variables.h" truelight@7433: #include "blitter/factory.hpp" rubidium@7371: #include "fileio.h" rubidium@8610: #include "strings_func.h" rubidium@8619: #include "zoom_func.h" rubidium@8626: #include "core/alloc_func.hpp" rubidium@8628: #include "core/endian_func.hpp" rubidium@8635: #include "map_func.h" rubidium@8636: #include "date_func.h" rubidium@8750: #include "player_func.h" truelight@0: rubidium@8760: #include "table/strings.h" rubidium@8760: 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@6916: /* called by the ScreenShot proc to generate screenshot lines. */ truelight@7374: 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@6574: struct ScreenshotFormat { truelight@0: const char *name; truelight@0: const char *extension; truelight@0: ScreenshotHandlerProc *proc; rubidium@6574: }; 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@6574: struct BitmapFileHeader { truelight@0: uint16 type; truelight@0: uint32 size; truelight@0: uint32 reserved; truelight@0: uint32 off_bits; rubidium@6574: } 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@6574: 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@6574: }; truelight@0: assert_compile(sizeof(BitmapInfoHeader) == 40); truelight@0: rubidium@6574: struct RgbQuad { truelight@0: byte blue, green, red, reserved; rubidium@6574: }; truelight@0: assert_compile(sizeof(RgbQuad) == 4); truelight@0: belugas@6916: /* 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@7374: uint pal_size = 0; truelight@7374: uint bpp = pixelformat / 8; truelight@0: truelight@7374: /* only implemented for 8bit and 32bit images so far. */ truelight@7374: 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@6916: /* each scanline must be aligned on a 32bit boundary */ skidd13@8423: padw = Align(w, 4); truelight@0: truelight@7374: if (pixelformat == 8) pal_size = sizeof(RgbQuad) * 256; truelight@7374: belugas@6916: /* setup the file header */ truelight@0: bfh.type = TO_LE16('MB'); truelight@7374: bfh.size = TO_LE32(sizeof(bfh) + sizeof(bih) + pal_size + padw * h * bpp); truelight@0: bfh.reserved = 0; truelight@7374: bfh.off_bits = TO_LE32(sizeof(bfh) + sizeof(bih) + pal_size); truelight@0: belugas@6916: /* 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@7374: 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@7374: if (pixelformat == 8) { truelight@7374: /* convert the palette to the windows format */ truelight@7374: for (i = 0; i != 256; i++) { truelight@7374: rq[i].red = palette[i].r; truelight@7374: rq[i].green = palette[i].g; truelight@7374: rq[i].blue = palette[i].b; truelight@7374: rq[i].reserved = 0; truelight@7374: } truelight@0: } truelight@0: belugas@6916: /* 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@7374: if (pixelformat == 8) if (fwrite(rq, sizeof(rq), 1, f) != 1) return false; truelight@0: belugas@6916: /* use by default 64k temp memory */ skidd13@8418: maxlines = Clamp(65536 / padw, 16, 128); truelight@0: belugas@6916: /* now generate the bitmap bits */ truelight@7374: 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@6916: /* start at the bottom, since bitmaps are stored bottom up. */ truelight@0: do { belugas@6916: /* determine # lines */ truelight@0: n = min(h, maxlines); truelight@0: h -= n; truelight@193: belugas@6916: /* render the pixels */ truelight@0: callb(userdata, buff, h, padw, n); truelight@193: belugas@6916: /* write each line */ truelight@193: while (n) truelight@7374: 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@5568: 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@5568: 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@7374: uint bpp = pixelformat / 8; truelight@0: png_structp png_ptr; truelight@0: png_infop info_ptr; truelight@0: truelight@7374: /* only implemented for 8bit and 32bit images so far. */ truelight@7374: 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@7374: 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@7374: if (pixelformat == 8) { truelight@7374: /* convert the palette to the .PNG format. */ truelight@7374: for (i = 0; i != 256; i++) { truelight@7374: rq[i].red = palette[i].r; truelight@7374: rq[i].green = palette[i].g; truelight@7374: rq[i].blue = palette[i].b; truelight@7374: } truelight@7374: truelight@7374: 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@7374: if (pixelformat == 32) { truelight@7374: png_color_8 sig_bit; truelight@7374: truelight@7374: /* Save exact color/alpha resolution */ truelight@7374: sig_bit.alpha = 0; truelight@7374: sig_bit.blue = 8; truelight@7374: sig_bit.green = 8; truelight@7374: sig_bit.red = 8; truelight@7374: sig_bit.gray = 8; truelight@7374: png_set_sBIT(png_ptr, info_ptr, &sig_bit); truelight@7374: truelight@7374: #ifdef TTD_LITTLE_ENDIAN truelight@7374: png_set_bgr(png_ptr); truelight@7374: png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); truelight@7374: #else truelight@7374: png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); truelight@7374: #endif truelight@7374: } truelight@7374: belugas@6916: /* use by default 64k temp memory */ skidd13@8418: maxlines = Clamp(65536 / w, 16, 128); truelight@0: belugas@6916: /* now generate the bitmap bits */ truelight@7374: 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@7374: memset(buff, 0, w * maxlines * bpp); truelight@0: truelight@0: y = 0; truelight@0: do { belugas@6916: /* determine # lines to write */ truelight@0: n = min(h - y, maxlines); truelight@193: belugas@6916: /* render the pixels into the buffer */ truelight@0: callb(userdata, buff, y, w, n); truelight@0: y += n; truelight@0: belugas@6916: /* write them to png */ tron@430: for (i = 0; i != n; i++) truelight@7374: 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@6574: 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@6987: 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@6574: }; 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@7374: if (pixelformat == 32) { truelight@7374: DEBUG(misc, 0, "Can't convert a 32bpp screenshot to PCX format. Please pick an other format."); truelight@7374: return false; truelight@7374: } 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@6916: /* 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@6916: /* 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@6916: /* use by default 64k temp memory */ skidd13@8418: maxlines = Clamp(65536 / w, 16, 128); truelight@0: belugas@6916: /* now generate the bitmap bits */ truelight@7374: 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@6916: /* determine # lines to write */ tron@430: uint n = min(h - y, maxlines); tron@430: uint i; truelight@193: belugas@6916: /* render the pixels into the buffer */ truelight@0: callb(userdata, buff, y, w, n); truelight@0: y += n; truelight@0: belugas@6916: /* write them to pcx */ tron@430: for (i = 0; i != n; i++) { truelight@7374: const uint8 *bufp = buff + i * w; tron@2004: byte runchar = bufp[0]; tron@2004: uint runcount = 1; tron@2004: uint j; truelight@0: belugas@6916: /* for each pixel... */ tron@2004: for (j = 1; j < w; j++) { truelight@7374: 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@6916: /* 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@6916: /* write 8-bit color palette */ tron@430: if (fputc(12, f) == EOF) { tron@430: fclose(f); tron@430: return false; tron@430: } tron@1991: peter1138@4019: if (sizeof(*palette) == 3) { peter1138@4019: success = fwrite(palette, 256 * sizeof(*palette), 1, f) == 1; peter1138@4019: } else { peter1138@4019: /* If the palette is word-aligned, copy it to a temporary byte array */ tron@4079: byte tmp[256 * 3]; peter1138@4019: uint i; tron@4079: peter1138@4019: for (i = 0; i < 256; i++) { peter1138@4019: tmp[i * 3 + 0] = palette[i].r; peter1138@4019: tmp[i * 3 + 1] = palette[i].g; peter1138@4019: tmp[i * 3 + 2] = palette[i].b; peter1138@4019: } tron@4079: success = fwrite(tmp, sizeof(tmp), 1, f) == 1; tron@430: } 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@6573: 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@6916: /* screenshot generator that dumps the current video buffer */ truelight@7374: static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n) truelight@0: { truelight@7433: Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); truelight@7433: void *src = blitter->MoveTo(_screen.dst_ptr, 0, y); truelight@7481: blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch); truelight@0: } truelight@0: frosch@8745: /** generate a large piece of the world frosch@8745: * @param userdata Viewport area to draw frosch@8745: * @param buf Videobuffer with same bitdepth as current blitter frosch@8745: * @param y First line to render frosch@8745: * @param pitch Pitch of the videobuffer frosch@8745: * @param n Number of lines to render frosch@8745: */ truelight@7374: 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@8745: /* We are no longer rendering to the screen */ frosch@8745: DrawPixelInfo old_screen = _screen; frosch@8745: bool old_disable_anim = _screen_disable_anim; frosch@8745: frosch@8745: _screen.dst_ptr = buf; frosch@8745: _screen.width = pitch; frosch@8745: _screen.height = n; frosch@8745: _screen.pitch = pitch; frosch@8745: _screen_disable_anim = true; frosch@8745: 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@7120: dpi.zoom = ZOOM_LVL_WORLD_SCREENSHOT; truelight@0: dpi.left = 0; truelight@0: dpi.top = y; truelight@0: frosch@8745: /* 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@7122: ScaleByZoom(left - wx - vp->left, vp->zoom) + vp->virtual_left, truelight@7122: ScaleByZoom(y - vp->top, vp->zoom) + vp->virtual_top, truelight@7122: ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left, truelight@7122: ScaleByZoom((y + n) - vp->top, vp->zoom) + vp->virtual_top truelight@0: ); truelight@0: } truelight@0: truelight@0: _cur_dpi = old_dpi; frosch@8745: frosch@8745: /* Switch back to rendering to the screen */ frosch@8745: _screen = old_screen; frosch@8745: _screen_disable_anim = old_disable_anim; truelight@0: } truelight@0: truelight@0: static char *MakeScreenshotName(const char *ext) truelight@0: { rubidium@7425: static char filename[MAX_PATH]; truelight@0: int serial; rubidium@7425: size_t len; truelight@0: Darkvater@4848: if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_player == PLAYER_SPECTATOR) { rubidium@7425: ttd_strlcpy(_screenshot_name, "screenshot", lengthof(_screenshot_name)); truelight@0: } else { peter1138@7554: SetDParam(0, _local_player); peter1138@7554: SetDParam(1, _date); Darkvater@4912: GetString(_screenshot_name, STR_4004, lastof(_screenshot_name)); truelight@0: } truelight@0: rubidium@7425: /* Add extension to screenshot file */ rubidium@7371: SanitizeFilename(_screenshot_name); rubidium@7425: len = strlen(_screenshot_name); rubidium@7425: snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext); truelight@0: rubidium@7425: for (serial = 1;; serial++) { rubidium@7425: snprintf(filename, lengthof(filename), "%s%s", _personal_dir, _screenshot_name); rubidium@7425: if (!FileExists(filename)) break; rubidium@7425: /* If file exists try another one with same name, but just with a higher index */ rubidium@7425: 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@6573: bool IsScreenshotRequested() belugas@4184: { belugas@4184: return (current_screenshot_type != SC_NONE); belugas@4184: } belugas@4184: rubidium@6573: static bool MakeSmallScreenshot() truelight@0: { truelight@0: const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; truelight@7374: return sf->proc(MakeScreenshotName(sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); truelight@0: } truelight@0: rubidium@6573: static bool MakeWorldScreenshot() truelight@0: { truelight@0: ViewPort vp; truelight@0: const ScreenshotFormat *sf; truelight@0: truelight@7120: 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@7374: return sf->proc(MakeScreenshotName(sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette); truelight@0: } belugas@4184: rubidium@6573: bool MakeScreenshot() belugas@4184: { belugas@4184: switch (current_screenshot_type) { belugas@4184: case SC_VIEWPORT: belugas@4184: UndrawMouseCursor(); belugas@5559: 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@5568: Darkvater@5568: