# screenshot.cpp

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #include "stdafx.h"
    00013 #include "openttd.h"
    00014 #include "fileio_func.h"
    00015 #include "viewport_func.h"
    00016 #include "gfx_func.h"
    00017 #include "screenshot.h"
    00018 #include "blitter/factory.hpp"
    00019 #include "zoom_func.h"
    00020 #include "core/endian_func.hpp"
    00021 #include "map_func.h"
    00022 #include "saveload/saveload.h"
    00023 #include "company_func.h"
    00024 #include "strings_func.h"
    00025 #include "gui.h"
    00026
    00027 #include "table/strings.h"
    00028
    00029
    00030 char _screenshot_format_name[8];
    00031 uint _num_screenshot_formats;
    00032 uint _cur_screenshot_format;
    00033 static char _screenshot_name[128];
    00034 char _full_screenshot_name[MAX_PATH];
    00035
    00036 /* called by the ScreenShot proc to generate screenshot lines. */
    00037 typedef void ScreenshotCallback(void *userdata, void *buf, uint y, uint pitch, uint n);
    00038 typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette);
    00039
    00040 struct ScreenshotFormat {
    00041   const char *name;
    00042   const char *extension;
    00043   ScreenshotHandlerProc *proc;
    00044 };
    00045
    00046 /*************************************************
    00047  **** SCREENSHOT CODE FOR WINDOWS BITMAP (.BMP)
    00048  *************************************************/
    00049 #if defined(_MSC_VER) || defined(__WATCOMC__)
    00050 #pragma pack(push, 1)
    00051 #endif
    00052
    00054 struct BitmapFileHeader {
    00055   uint16 type;
    00056   uint32 size;
    00057   uint32 reserved;
    00058   uint32 off_bits;
    00059 } GCC_PACK;
    00060 assert_compile(sizeof(BitmapFileHeader) == 14);
    00061
    00062 #if defined(_MSC_VER) || defined(__WATCOMC__)
    00063 #pragma pack(pop)
    00064 #endif
    00065
    00067 struct BitmapInfoHeader {
    00068   uint32 size;
    00069   int32 width, height;
    00070   uint16 planes, bitcount;
    00071   uint32 compression, sizeimage, xpels, ypels, clrused, clrimp;
    00072 };
    00073 assert_compile(sizeof(BitmapInfoHeader) == 40);
    00074
    00076 struct RgbQuad {
    00077   byte blue, green, red, reserved;
    00078 };
    00079 assert_compile(sizeof(RgbQuad) == 4);
    00080
    00082 struct RgbTriplet {
    00083   byte b, g, r;
    00084 };
    00085 assert_compile(sizeof(RgbTriplet) == 3);
    00086
    00098 static bool MakeBMPImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
    00099 {
    00100   uint bpp; // bytes per pixel
    00101   switch (pixelformat) {
    00102     case 8:  bpp = 1; break;
    00103     /* 32bpp mode is saved as 24bpp BMP */
    00104     case 32: bpp = 3; break;
    00105     /* Only implemented for 8bit and 32bit images so far */
    00106     default: return false;
    00107   }
    00108
    00109   FILE *f = fopen(name, "wb");
    00110   if (f == NULL) return false;
    00111
    00112   /* Each scanline must be aligned on a 32bit boundary */
    00113   uint bytewidth = Align(w * bpp, 4); // bytes per line in file
    00114
    00115   /* Size of palette. Only present for 8bpp mode */
    00116   uint pal_size = pixelformat == 8 ? sizeof(RgbQuad) * 256 : 0;
    00117
    00118   /* Setup the file header */
    00119   BitmapFileHeader bfh;
    00120   bfh.type = TO_LE16('MB');
    00121   bfh.size = TO_LE32(sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + pal_size + bytewidth * h);
    00122   bfh.reserved = 0;
    00123   bfh.off_bits = TO_LE32(sizeof(BitmapFileHeader) + sizeof(BitmapInfoHeader) + pal_size);
    00124
    00125   /* Setup the info header */
    00126   BitmapInfoHeader bih;
    00127   bih.size = TO_LE32(sizeof(BitmapInfoHeader));
    00128   bih.width = TO_LE32(w);
    00129   bih.height = TO_LE32(h);
    00130   bih.planes = TO_LE16(1);
    00131   bih.bitcount = TO_LE16(bpp * 8);
    00132   bih.compression = 0;
    00133   bih.sizeimage = 0;
    00134   bih.xpels = 0;
    00135   bih.ypels = 0;
    00136   bih.clrused = 0;
    00137   bih.clrimp = 0;
    00138
    00139   /* Write file header and info header */
    00140   if (fwrite(&bfh, sizeof(bfh), 1, f) != 1 || fwrite(&bih, sizeof(bih), 1, f) != 1) {
    00141     fclose(f);
    00142     return false;
    00143   }
    00144
    00145   if (pixelformat == 8) {
    00146     /* Convert the palette to the windows format */
    00147     RgbQuad rq[256];
    00148     for (uint i = 0; i < 256; i++) {
    00149       rq[i].red   = palette[i].r;
    00150       rq[i].green = palette[i].g;
    00151       rq[i].blue  = palette[i].b;
    00152       rq[i].reserved = 0;
    00153     }
    00154     /* Write the palette */
    00155     if (fwrite(rq, sizeof(rq), 1, f) != 1) {
    00156       fclose(f);
    00157       return false;
    00158     }
    00159   }
    00160
    00161   /* Try to use 64k of memory, store between 16 and 128 lines */
    00162   uint maxlines = Clamp(65536 / (w * pixelformat / 8), 16, 128); // number of lines per iteration
    00163
    00164   uint8 *buff = MallocT<uint8>(maxlines * w * pixelformat / 8); // buffer which is rendered to
    00165   uint8 *line = AllocaM(uint8, bytewidth); // one line, stored to file
    00166   memset(line, 0, bytewidth);
    00167
    00168   /* Start at the bottom, since bitmaps are stored bottom up */
    00169   do {
    00170     uint n = min(h, maxlines);
    00171     h -= n;
    00172
    00173     /* Render the pixels */
    00174     callb(userdata, buff, h, w, n);
    00175
    00176     /* Write each line */
    00177     while (n-- != 0) {
    00178       if (pixelformat == 8) {
    00179         /* Move to 'line', leave last few pixels in line zeroed */
    00180         memcpy(line, buff + n * w, w);
    00181       } else {
    00182         /* Convert from 'native' 32bpp to BMP-like 24bpp.
    00183          * Works for both big and little endian machines */
    00184         Colour *src = ((Colour *)buff) + n * w;
    00185         RgbTriplet *dst = (RgbTriplet *)line;
    00186         for (uint i = 0; i < w; i++) {
    00187           dst[i].r = src[i].r;
    00188           dst[i].g = src[i].g;
    00189           dst[i].b = src[i].b;
    00190         }
    00191       }
    00192       /* Write to file */
    00193       if (fwrite(line, bytewidth, 1, f) != 1) {
    00194         free(buff);
    00195         fclose(f);
    00196         return false;
    00197       }
    00198     }
    00199   } while (h != 0);
    00200
    00201   free(buff);
    00202   fclose(f);
    00203
    00204   return true;
    00205 }
    00206
    00207 /*********************************************************
    00208  **** SCREENSHOT CODE FOR PORTABLE NETWORK GRAPHICS (.PNG)
    00209  *********************************************************/
    00210 #if defined(WITH_PNG)
    00211 #include <png.h>
    00212
    00213 static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message)
    00214 {
    00215   DEBUG(misc, 0, "[libpng] error: %s - %s", message, (const char *)png_get_error_ptr(png_ptr));
    00216   longjmp(png_ptr->jmpbuf, 1);
    00217 }
    00218
    00219 static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message)
    00220 {
    00221   DEBUG(misc, 1, "[libpng] warning: %s - %s", message, (const char *)png_get_error_ptr(png_ptr));
    00222 }
    00223
    00224 static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
    00225 {
    00226   png_color rq[256];
    00227   FILE *f;
    00228   uint i, y, n;
    00229   uint maxlines;
    00230   uint bpp = pixelformat / 8;
    00231   png_structp png_ptr;
    00232   png_infop info_ptr;
    00233
    00234   /* only implemented for 8bit and 32bit images so far. */
    00235   if (pixelformat != 8 && pixelformat != 32) return false;
    00236
    00237   f = fopen(name, "wb");
    00238   if (f == NULL) return false;
    00239
    00240   png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (void *)name, png_my_error, png_my_warning);
    00241
    00242   if (png_ptr == NULL) {
    00243     fclose(f);
    00244     return false;
    00245   }
    00246
    00247   info_ptr = png_create_info_struct(png_ptr);
    00248   if (info_ptr == NULL) {
    00249     png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
    00250     fclose(f);
    00251     return false;
    00252   }
    00253
    00254   if (setjmp(png_jmpbuf(png_ptr))) {
    00255     png_destroy_write_struct(&png_ptr, &info_ptr);
    00256     fclose(f);
    00257     return false;
    00258   }
    00259
    00260   png_init_io(png_ptr, f);
    00261
    00262   png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
    00263
    00264   png_set_IHDR(png_ptr, info_ptr, w, h, 8, pixelformat == 8 ? PNG_COLOR_TYPE_PALETTE : PNG_COLOR_TYPE_RGB,
    00265     PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
    00266
    00267   if (pixelformat == 8) {
    00268     /* convert the palette to the .PNG format. */
    00269     for (i = 0; i != 256; i++) {
    00270       rq[i].red   = palette[i].r;
    00271       rq[i].green = palette[i].g;
    00272       rq[i].blue  = palette[i].b;
    00273     }
    00274
    00275     png_set_PLTE(png_ptr, info_ptr, rq, 256);
    00276   }
    00277
    00278   png_write_info(png_ptr, info_ptr);
    00279   png_set_flush(png_ptr, 512);
    00280
    00281   if (pixelformat == 32) {
    00282     png_color_8 sig_bit;
    00283
    00284     /* Save exact colour/alpha resolution */
    00285     sig_bit.alpha = 0;
    00286     sig_bit.blue  = 8;
    00287     sig_bit.green = 8;
    00288     sig_bit.red   = 8;
    00289     sig_bit.gray  = 8;
    00290     png_set_sBIT(png_ptr, info_ptr, &sig_bit);
    00291
    00292 #if TTD_ENDIAN == TTD_LITTLE_ENDIAN
    00293     png_set_bgr(png_ptr);
    00294     png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
    00295 #else
    00296     png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
    00297 #endif /* TTD_ENDIAN == TTD_LITTLE_ENDIAN */
    00298   }
    00299
    00300   /* use by default 64k temp memory */
    00301   maxlines = Clamp(65536 / w, 16, 128);
    00302
    00303   /* now generate the bitmap bits */
    00304   void *buff = CallocT<uint8>(w * maxlines * bpp); // by default generate 128 lines at a time.
    00305
    00306   y = 0;
    00307   do {
    00308     /* determine # lines to write */
    00309     n = min(h - y, maxlines);
    00310
    00311     /* render the pixels into the buffer */
    00312     callb(userdata, buff, y, w, n);
    00313     y += n;
    00314
    00315     /* write them to png */
    00316     for (i = 0; i != n; i++)
    00317       png_write_row(png_ptr, (png_bytep)buff + i * w * bpp);
    00318   } while (y != h);
    00319
    00320   png_write_end(png_ptr, info_ptr);
    00321   png_destroy_write_struct(&png_ptr, &info_ptr);
    00322
    00323   free(buff);
    00324   fclose(f);
    00325   return true;
    00326 }
    00327 #endif /* WITH_PNG */
    00328
    00329
    00330 /*************************************************
    00331  **** SCREENSHOT CODE FOR ZSOFT PAINTBRUSH (.PCX)
    00332  *************************************************/
    00333
    00334 struct PcxHeader {
    00335   byte manufacturer;
    00336   byte version;
    00337   byte rle;
    00338   byte bpp;
    00339   uint32 unused;
    00340   uint16 xmax, ymax;
    00341   uint16 hdpi, vdpi;
    00342   byte pal_small[16 * 3];
    00343   byte reserved;
    00344   byte planes;
    00345   uint16 pitch;
    00346   uint16 cpal;
    00347   uint16 width;
    00348   uint16 height;
    00349   byte filler[54];
    00350 };
    00351 assert_compile(sizeof(PcxHeader) == 128);
    00352
    00353 static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette)
    00354 {
    00355   FILE *f;
    00356   uint maxlines;
    00357   uint y;
    00358   PcxHeader pcx;
    00359   bool success;
    00360
    00361   if (pixelformat == 32) {
    00362     DEBUG(misc, 0, "Can't convert a 32bpp screenshot to PCX format. Please pick an other format.");
    00363     return false;
    00364   }
    00365   if (pixelformat != 8 || w == 0)
    00366     return false;
    00367
    00368   f = fopen(name, "wb");
    00369   if (f == NULL) return false;
    00370
    00371   memset(&pcx, 0, sizeof(pcx));
    00372
    00373   /* setup pcx header */
    00374   pcx.manufacturer = 10;
    00375   pcx.version = 5;
    00376   pcx.rle = 1;
    00377   pcx.bpp = 8;
    00378   pcx.xmax = TO_LE16(w - 1);
    00379   pcx.ymax = TO_LE16(h - 1);
    00380   pcx.hdpi = TO_LE16(320);
    00381   pcx.vdpi = TO_LE16(320);
    00382
    00383   pcx.planes = 1;
    00384   pcx.cpal = TO_LE16(1);
    00385   pcx.width = pcx.pitch = TO_LE16(w);
    00386   pcx.height = TO_LE16(h);
    00387
    00388   /* write pcx header */
    00389   if (fwrite(&pcx, sizeof(pcx), 1, f) != 1) {
    00390     fclose(f);
    00391     return false;
    00392   }
    00393
    00394   /* use by default 64k temp memory */
    00395   maxlines = Clamp(65536 / w, 16, 128);
    00396
    00397   /* now generate the bitmap bits */
    00398   uint8 *buff = CallocT<uint8>(w * maxlines); // by default generate 128 lines at a time.
    00399
    00400   y = 0;
    00401   do {
    00402     /* determine # lines to write */
    00403     uint n = min(h - y, maxlines);
    00404     uint i;
    00405
    00406     /* render the pixels into the buffer */
    00407     callb(userdata, buff, y, w, n);
    00408     y += n;
    00409
    00410     /* write them to pcx */
    00411     for (i = 0; i != n; i++) {
    00412       const uint8 *bufp = buff + i * w;
    00413       byte runchar = bufp[0];
    00414       uint runcount = 1;
    00415       uint j;
    00416
    00417       /* for each pixel... */
    00418       for (j = 1; j < w; j++) {
    00419         uint8 ch = bufp[j];
    00420
    00421         if (ch != runchar || runcount >= 0x3f) {
    00422           if (runcount > 1 || (runchar & 0xC0) == 0xC0)
    00423             if (fputc(0xC0 | runcount, f) == EOF) {
    00424               free(buff);
    00425               fclose(f);
    00426               return false;
    00427             }
    00428           if (fputc(runchar, f) == EOF) {
    00429             free(buff);
    00430             fclose(f);
    00431             return false;
    00432           }
    00433           runcount = 0;
    00434           runchar = ch;
    00435         }
    00436         runcount++;
    00437       }
    00438
    00439       /* write remaining bytes.. */
    00440       if (runcount > 1 || (runchar & 0xC0) == 0xC0)
    00441         if (fputc(0xC0 | runcount, f) == EOF) {
    00442           free(buff);
    00443           fclose(f);
    00444           return false;
    00445         }
    00446       if (fputc(runchar, f) == EOF) {
    00447         free(buff);
    00448         fclose(f);
    00449         return false;
    00450       }
    00451     }
    00452   } while (y != h);
    00453
    00454   free(buff);
    00455
    00456   /* write 8-bit colour palette */
    00457   if (fputc(12, f) == EOF) {
    00458     fclose(f);
    00459     return false;
    00460   }
    00461
    00462   /* Palette is word-aligned, copy it to a temporary byte array */
    00463   byte tmp[256 * 3];
    00464
    00465   for (uint i = 0; i < 256; i++) {
    00466     tmp[i * 3 + 0] = palette[i].r;
    00467     tmp[i * 3 + 1] = palette[i].g;
    00468     tmp[i * 3 + 2] = palette[i].b;
    00469   }
    00470   success = fwrite(tmp, sizeof(tmp), 1, f) == 1;
    00471
    00472   fclose(f);
    00473
    00474   return success;
    00475 }
    00476
    00477 /*************************************************
    00478  **** GENERIC SCREENSHOT CODE
    00479  *************************************************/
    00480
    00481 static const ScreenshotFormat _screenshot_formats[] = {
    00482 #if defined(WITH_PNG)
    00483   {"PNG", "png", &MakePNGImage},
    00484 #endif
    00485   {"BMP", "bmp", &MakeBMPImage},
    00486   {"PCX", "pcx", &MakePCXImage},
    00487 };
    00488
    00489 void InitializeScreenshotFormats()
    00490 {
    00491   int i, j;
    00492   for (i = 0, j = 0; i != lengthof(_screenshot_formats); i++)
    00493     if (!strcmp(_screenshot_format_name, _screenshot_formats[i].extension)) {
    00494       j = i;
    00495       break;
    00496     }
    00497   _cur_screenshot_format = j;
    00498   _num_screenshot_formats = lengthof(_screenshot_formats);
    00499 }
    00500
    00501 const char *GetScreenshotFormatDesc(int i)
    00502 {
    00503   return _screenshot_formats[i].name;
    00504 }
    00505
    00506 void SetScreenshotFormat(int i)
    00507 {
    00508   _cur_screenshot_format = i;
    00509   strecpy(_screenshot_format_name, _screenshot_formats[i].extension, lastof(_screenshot_format_name));
    00510 }
    00511
    00512 /* screenshot generator that dumps the current video buffer */
    00513 static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
    00514 {
    00515   Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
    00516   void *src = blitter->MoveTo(_screen.dst_ptr, 0, y);
    00517   blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch);
    00518 }
    00519
    00527 static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
    00528 {
    00529   ViewPort *vp = (ViewPort *)userdata;
    00530   DrawPixelInfo dpi, *old_dpi;
    00531   int wx, left;
    00532
    00533   /* We are no longer rendering to the screen */
    00534   DrawPixelInfo old_screen = _screen;
    00535   bool old_disable_anim = _screen_disable_anim;
    00536
    00537   _screen.dst_ptr = buf;
    00538   _screen.width = pitch;
    00539   _screen.height = n;
    00540   _screen.pitch = pitch;
    00541   _screen_disable_anim = true;
    00542
    00543   old_dpi = _cur_dpi;
    00544   _cur_dpi = &dpi;
    00545
    00546   dpi.dst_ptr = buf;
    00547   dpi.height = n;
    00548   dpi.width = vp->width;
    00549   dpi.pitch = pitch;
    00550   dpi.zoom = ZOOM_LVL_WORLD_SCREENSHOT;
    00551   dpi.left = 0;
    00552   dpi.top = y;
    00553
    00554   /* Render viewport in blocks of 1600 pixels width */
    00555   left = 0;
    00556   while (vp->width - left != 0) {
    00557     wx = min(vp->width - left, 1600);
    00558     left += wx;
    00559
    00560     ViewportDoDraw(vp,
    00561       ScaleByZoom(left - wx - vp->left, vp->zoom) + vp->virtual_left,
    00562       ScaleByZoom(y - vp->top, vp->zoom) + vp->virtual_top,
    00563       ScaleByZoom(left - vp->left, vp->zoom) + vp->virtual_left,
    00564       ScaleByZoom((y + n) - vp->top, vp->zoom) + vp->virtual_top
    00565     );
    00566   }
    00567
    00568   _cur_dpi = old_dpi;
    00569
    00570   /* Switch back to rendering to the screen */
    00571   _screen = old_screen;
    00572   _screen_disable_anim = old_disable_anim;
    00573 }
    00574
    00575 static const char *MakeScreenshotName(const char *ext)
    00576 {
    00577   bool generate = StrEmpty(_screenshot_name);
    00578
    00579   if (generate) {
    00580     if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
    00581       strecpy(_screenshot_name, "screenshot", lastof(_screenshot_name));
    00582     } else {
    00583       GenerateDefaultSaveName(_screenshot_name, lastof(_screenshot_name));
    00584     }
    00585   }
    00586
    00587   /* Add extension to screenshot file */
    00588   size_t len = strlen(_screenshot_name);
    00589   snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext);
    00590
    00591   for (uint serial = 1;; serial++) {
    00592     if (snprintf(_full_screenshot_name, lengthof(_full_screenshot_name), "%s%s", _personal_dir, _screenshot_name) >= (int)lengthof(_full_screenshot_name)) {
    00593       /* We need more characters than MAX_PATH -> end with error */
    00594       _full_screenshot_name[0] = '\0';
    00595       break;
    00596     }
    00597     if (!generate) break; // allow overwriting of non-automatic filenames
    00598     if (!FileExists(_full_screenshot_name)) break;
    00599     /* If file exists try another one with same name, but just with a higher index */
    00600     snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, "#%u.%s", serial, ext);
    00601   }
    00602
    00603   return _full_screenshot_name;
    00604 }
    00605
    00606 static bool MakeSmallScreenshot()
    00607 {
    00608   const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
    00609   return sf->proc(MakeScreenshotName(sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette);
    00610 }
    00611
    00612 static bool MakeWorldScreenshot()
    00613 {
    00614   ViewPort vp;
    00615   const ScreenshotFormat *sf;
    00616
    00617   vp.zoom = ZOOM_LVL_WORLD_SCREENSHOT;
    00618   vp.left = 0;
    00619   vp.top = 0;
    00620   vp.virtual_left = -(int)MapMaxX() * TILE_PIXELS;
    00621   vp.virtual_top = 0;
    00622   vp.virtual_width = (MapMaxX() + MapMaxY()) * TILE_PIXELS;
    00623   vp.width = vp.virtual_width;
    00624   vp.virtual_height = (MapMaxX() + MapMaxY()) * TILE_PIXELS >> 1;
    00625   vp.height = vp.virtual_height;
    00626
    00627   sf = _screenshot_formats + _cur_screenshot_format;
    00628   return sf->proc(MakeScreenshotName(sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette);
    00629 }
    00630
    00637 bool MakeScreenshot(ScreenshotType t, const char *name)
    00638 {
    00639   if (t == SC_VIEWPORT) {
    00640     /* First draw the dirty parts of the screen and only then change the name
    00641      * of the screenshot. This way the screenshot will always show the name
    00642      * of the previous screenshot in the 'succesful' message instead of the
    00643      * name of the new screenshot (or an empty name). */
    00644     UndrawMouseCursor();
    00645     DrawDirtyBlocks();
    00646   }
    00647
    00648   _screenshot_name[0] = '\0';
    00649   if (name != NULL) strecpy(_screenshot_name, name, lastof(_screenshot_name));
    00650
    00651   bool ret;
    00652   switch (t) {
    00653     case SC_VIEWPORT:
    00654     case SC_RAW:
    00655       ret = MakeSmallScreenshot();
    00656       break;
    00657
    00658     case SC_WORLD:
    00659       ret = MakeWorldScreenshot();
    00660       break;
    00661
    00662     default:
    00663       NOT_REACHED();
    00664   }
    00665
    00666   if (ret) {
    00667     SetDParamStr(0, _screenshot_name);
    00668     ShowErrorMessage(STR_MESSAGE_SCREENSHOT_SUCCESSFULLY, INVALID_STRING_ID, 0, 0);
    00669   } else {
    00670     ShowErrorMessage(STR_ERROR_SCREENSHOT_FAILED, INVALID_STRING_ID, 0, 0);
    00671   }
    00672
    00673   return ret;
    00674 }