hedgewars/uMisc.pas
changeset 15335 fe705efbfc52
parent 14910 9b292184d793
child 15356 f9f34158ef72
--- a/hedgewars/uMisc.pas	Tue Aug 13 13:20:28 2019 -0600
+++ b/hedgewars/uMisc.pas	Wed Aug 14 22:27:01 2019 +0300
@@ -99,8 +99,41 @@
 SaveScreenshot:= 0;
 end;
 
-{$ELSE} // no PNG_SCREENSHOTS
+{$ELSE} //PNG_SCREENSHOTS
+{$IFDEF WINDOWS}
+function SaveScreenshot(screenshot: pointer): LongInt; cdecl; export;
+var
+    surface: PSDL_Surface;
+    image: PScreenshot;
+    mirror: PByte;
+    row, stride: LongInt;
+begin
+    image:= PScreenshot(screenshot);
+    mirror:= PByte(GetMem(image^.size));
+    stride:= image^.width * 4;
+
+    for row:= 0 to image^.height - 1 do
+        Move((image^.buffer + row * stride)^,
+             (mirror + (image^.height - row - 1) * stride)^,
+             stride);
 
+    surface:= SDL_CreateRGBSurfaceFrom(
+        mirror,
+        image^.width, image^.height, 32, image^.width * 4,
+        $000000FF, $0000FF00, $00FF0000, $FF000000);
+
+    if surface <> nil then
+        begin
+        IMG_SavePNG(surface, Str2PChar(image^.filename));
+        SDL_FreeSurface(surface);
+        end;
+
+    FreeMem(mirror, image^.size);
+    FreeMem(image^.buffer, image^.size);
+    Dispose(image);
+    SaveScreenshot:= 0;
+end;
+{$ELSE} //WINDOWS
 // this funtion will be executed in separate thread
 function SaveScreenshot(screenshot: pointer): LongInt; cdecl; export;
 var f: file;
@@ -169,7 +202,8 @@
 SaveScreenshot:= 0;
 end;
 
-{$ENDIF} // no PNG_SCREENSHOTS
+{$ENDIF} // WINDOWS
+{$ENDIF} // PNG_SCREENSHOTS
 
 {$IFDEF USE_VIDEO_RECORDING}
 // make image k times smaller (useful for saving thumbnails)
@@ -218,9 +252,14 @@
 format:= GL_RGBA;
 ext:= '.png';
 {$ELSE}
+{$IFDEF WINDOWS}
+format:= GL_RGBA;
+ext:= '.png';
+{$ELSE}
 format:= GL_BGRA;
 ext:= '.bmp';
 {$ENDIF}
+{$ENDIF}
 
 if dump > 0 then
      size:= LAND_WIDTH*LAND_HEIGHT*4