Game Development Community

TGEA 1.7.1 - Screenshot saving format mismatch

by Fyodor -bank- Osokin · in Torque Game Engine Advanced · 06/23/2008 (4:18 pm) · 1 replies

If you set in Options JPEG as a file format for screenshots - you will still get .PNGs, though it will have .jpg extension.

The issue is in fact, that mFilename is UTF16, and we do compare with simple char type when choosing the bitmat format.

Here is my .patch
Index: engine/source/gfx/D3D/screenshotD3D.cpp
===================================================================
--- engine/source/gfx/D3D/screenshotD3D.cpp	(revision 1)
+++ engine/source/gfx/D3D/screenshotD3D.cpp	(working copy)
@@ -18,6 +18,8 @@
 #include "gui/core/guiCanvas.h"
 #include "gui/3d/guiTSControl.h"
 
+#include "core/unicode.h"
+
 //-----------------------------------------------------------------------------
 // Capture standard screenshot - read it from the back buffer
 //    This function jumps through some hoops copying surfaces around so that
@@ -66,7 +68,7 @@
    // save it off
    D3DXIMAGE_FILEFORMAT format;
    
-   if( dStrstr( (const char*)mFilename, ".jpg" ) )
+   if( dStrstr( (const char*)convertUTF16toUTF8(mFilename), ".jpg" ) )
    {
       format = D3DXIFF_JPG;
    }

After looking at consoleFunction screenShot we can see that second passed parameter never used (either "PNG" or "JPEG" string being passed in).
So, I someone thinks it's only "waste" of code, the patch below.
Keep in mind: if you want to have compatibility with "older" code, you don't need to apply next 2 "fixes".

Index: engine/source/gfx/screenshot.cpp
===================================================================
--- engine/source/gfx/screenshot.cpp	(revision 1)
+++ engine/source/gfx/screenshot.cpp	(working copy)
@@ -14,7 +14,7 @@
 //**************************************************************************
 // Console function
 //**************************************************************************
-ConsoleFunction(screenShot, void, 3, 3, "(string file, string format)"
+ConsoleFunction(screenShot, void, 2, 2, "(string file, string format)"
                 "Take a screenshot.\n\n"
                 "@param format One of JPEG or PNG.")
 {

And of course the script changes (removing passing second unneeded parameter):
Index: game/common/gameScripts/screenshot.cs
===================================================================
--- game/common/gameScripts/screenshot.cs	(revision 3)
+++ game/common/gameScripts/screenshot.cs	(working copy)
@@ -82,12 +82,12 @@
       
       if (($pref::Video::screenShotFormat $= "JPEG") ||
           ($pref::video::screenShotFormat $= "JPG"))
-         screenShot(%name @ ".jpg", "JPEG");
+         screenShot(%name @ ".jpg");
          
       else if($pref::Video::screenShotFormat $= "PNG")
-         screenShot(%name @ ".png", "PNG");
+         screenShot(%name @ ".png");
          
       else
-         screenShot(%name @ ".png", "PNG");
+         screenShot(%name @ ".png");
    }
 }

#1
07/01/2008 (6:28 am)
Good catch, banks. Be aware, though, that convertUTF16toUTF8 allocates a new buffer that has to be freed by the client in order to not create a memory leak.

A simpler solution is to use the TEXT macro:

const TCHAR* dotPos = dStrrchr( mFilename, TEXT( '.' ) );
   if( dotPos && dStrcmp( dotPos, TEXT( ".jpg" ) ) == 0 )
   {