diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-04-04 18:00:31 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-04-04 18:00:31 +0400 |
commit | d579ea2901084f20407b1834a2d36445aba687b4 (patch) | |
tree | cee582dea06163d2fcaf0db75255cf3f6dcdcd40 /source/gameengine/BlenderRoutines | |
parent | 3c5c4fb4f6725e7fcb480d619905446c28fa6e69 (diff) |
Fix #34863: bge.render.makeScreenshot from Blender was only saving PNG files,
while the docs said it followed the settings in the Output panel, other file
formats work now.
Benderplayer still only saves PNG now as documented, but I cleaned up the code
there to reuse existing imbuf functions rather than using own libpng code.
Diffstat (limited to 'source/gameengine/BlenderRoutines')
-rw-r--r-- | source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp | 3 | ||||
-rw-r--r-- | source/gameengine/BlenderRoutines/KX_BlenderGL.cpp | 39 | ||||
-rw-r--r-- | source/gameengine/BlenderRoutines/KX_BlenderGL.h | 3 |
3 files changed, 28 insertions, 17 deletions
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp index e51daf615b8..e15b8ac942f 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp @@ -32,6 +32,7 @@ #include "KX_BlenderCanvas.h" #include "DNA_screen_types.h" +#include "DNA_windowmanager_types.h" #include <stdio.h> #include <assert.h> @@ -256,5 +257,5 @@ void KX_BlenderCanvas::MakeScreenShot(const char *filename) area_dummy.totrct.ymin = m_frame_rect.GetBottom(); area_dummy.totrct.ymax = m_frame_rect.GetTop(); - BL_MakeScreenShot(&area_dummy, filename); + BL_MakeScreenShot(m_win->screen, &area_dummy, filename); } diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp index f808b1b7272..ebf788024c5 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp @@ -60,6 +60,7 @@ #include "DNA_image_types.h" #include "DNA_view3d_types.h" #include "DNA_material_types.h" +#include "DNA_space_types.h" #include "DNA_windowmanager_types.h" #include "BKE_global.h" @@ -68,6 +69,7 @@ #include "BKE_image.h" #include "BLI_path_util.h" +#include "BLI_string.h" extern "C" { #include "IMB_imbuf_types.h" @@ -270,8 +272,6 @@ void BL_NormalMouse(wmWindow *win) { WM_cursor_set(win, CURSOR_STD); } -#define MAX_FILE_LENGTH 512 - /* get shot from frontbuffer sort of a copy from screendump.c */ static unsigned int *screenshot(ScrArea *curarea, int *dumpsx, int *dumpsy) { @@ -296,27 +296,36 @@ static unsigned int *screenshot(ScrArea *curarea, int *dumpsx, int *dumpsy) } /* based on screendump.c::screenshot_exec */ -void BL_MakeScreenShot(ScrArea *curarea, const char *filename) +void BL_MakeScreenShot(bScreen *screen, ScrArea *curarea, const char *filename) { - char path[MAX_FILE_LENGTH]; - strcpy(path,filename); - unsigned int *dumprect; int dumpsx, dumpsy; - dumprect= screenshot(curarea, &dumpsx, &dumpsy); + dumprect = screenshot(curarea, &dumpsx, &dumpsy); + if (dumprect) { - ImBuf *ibuf; + /* initialize image file format data */ + Scene *scene = (screen)? screen->scene: NULL; + ImageFormatData im_format; + + if(scene) + im_format = scene->r.im_format; + else + BKE_imformat_defaults(&im_format); + + /* create file path */ + char path[FILE_MAX]; + BLI_strncpy(path, filename, sizeof(path)); BLI_path_abs(path, G.main->name); - /* BKE_add_image_extension() checks for if extension was already set */ - BKE_add_image_extension_from_type(path, R_IMF_IMTYPE_PNG); /* scene->r.im_format.imtype */ - ibuf= IMB_allocImBuf(dumpsx, dumpsy, 24, 0); - ibuf->rect= dumprect; - ibuf->ftype= PNG; + BKE_add_image_extension_from_type(path, im_format.imtype); + + /* create and save imbuf */ + ImBuf *ibuf = IMB_allocImBuf(dumpsx, dumpsy, 24, 0); + ibuf->rect = dumprect; - IMB_saveiff(ibuf, path, IB_rect); + BKE_imbuf_write_as(ibuf, path, &im_format, false); - ibuf->rect= NULL; + ibuf->rect = NULL; IMB_freeImBuf(ibuf); MEM_freeN(dumprect); } diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.h b/source/gameengine/BlenderRoutines/KX_BlenderGL.h index 2545cd34acb..0f35494c73a 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderGL.h +++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.h @@ -38,13 +38,14 @@ extern "C" { struct wmWindow; struct ARegion; +struct bScreen; // special swapbuffers, that takes care of which area (viewport) needs to be swapped void BL_SwapBuffers(struct wmWindow *win); void BL_warp_pointer(struct wmWindow *win,int x,int y); -void BL_MakeScreenShot(struct ScrArea *curarea, const char *filename); +void BL_MakeScreenShot(struct bScreen *screen, struct ScrArea *curarea, const char *filename); void BL_HideMouse(struct wmWindow *win); void BL_NormalMouse(struct wmWindow *win); |