remove direct libpng dependency on windows
authoralfadur
Wed, 14 Aug 2019 22:27:01 +0300
changeset 15314 fe705efbfc52
parent 15313 7e3bd4030aa5
child 15315 90f9a0eac3ae
remove direct libpng dependency on windows
CMakeLists.txt
hedgewars/CMakeLists.txt
hedgewars/SDLh.pas
hedgewars/uMisc.pas
--- a/CMakeLists.txt	Tue Aug 13 13:20:28 2019 -0600
+++ b/CMakeLists.txt	Wed Aug 14 22:27:01 2019 +0300
@@ -20,7 +20,9 @@
 
 #possible cmake configuration
 option(NOSERVER "Disable gameServer build (off)" OFF)
-option(NOPNG "Disable screenshoot compression (off)" OFF)
+if(NOT WIN32)
+    option(NOPNG "Disable screenshoot compression (off)" OFF)
+endif()
 option(NOVIDEOREC "Disable video recording (off)" OFF)
 
 #libraries are built shared unless explicitly added as a static
--- a/hedgewars/CMakeLists.txt	Tue Aug 13 13:20:28 2019 -0600
+++ b/hedgewars/CMakeLists.txt	Wed Aug 14 22:27:01 2019 +0300
@@ -144,13 +144,15 @@
     add_definitions(-dUSE_VIDEO_RECORDING)
 endif()
 
-find_package_or_disable_msg(PNG NOPNG "Screenshots will be saved in BMP")
-if(PNG_FOUND)
-    list(INSERT engine_sources 0 PNGh.pas)
-    list(REMOVE_AT PNG_LIBRARIES 1) #removing the zlib library path
-    get_filename_component(PNG_LIBRARY_DIR ${PNG_LIBRARIES} PATH)
-    add_flag_append(CMAKE_Pascal_FLAGS "-k-L${PNG_LIBRARY_DIR} -Fl${PNG_LIBRARY_DIR}")
-    add_definitions(-dPNG_SCREENSHOTS)
+if(NOT WIN32)
+    find_package_or_disable_msg(PNG NOPNG "Screenshots will be saved in BMP")
+    if(PNG_FOUND)
+        list(INSERT engine_sources 0 PNGh.pas)
+        list(REMOVE_AT PNG_LIBRARIES 1) #removing the zlib library path
+        get_filename_component(PNG_LIBRARY_DIR ${PNG_LIBRARIES} PATH)
+        add_flag_append(CMAKE_Pascal_FLAGS "-k-L${PNG_LIBRARY_DIR} -Fl${PNG_LIBRARY_DIR}")
+        add_definitions(-dPNG_SCREENSHOTS)
+    endif()
 endif()
 
 if(LUA_SYSTEM)
--- a/hedgewars/SDLh.pas	Tue Aug 13 13:20:28 2019 -0600
+++ b/hedgewars/SDLh.pas	Wed Aug 14 22:27:01 2019 +0300
@@ -1254,6 +1254,7 @@
 function  IMG_Load_RW(rwop: PSDL_RWops; freesrc: LongBool): PSDL_Surface; cdecl; external SDL_ImageLibName;
 function  IMG_LoadPNG_RW(rwop: PSDL_RWops): PSDL_Surface; cdecl; external SDL_ImageLibName;
 function  IMG_LoadTyped_RW(rwop: PSDL_RWops; freesrc: LongBool; type_: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
+function IMG_SavePNG(surface: PSDL_Surface; const _file: PChar): LongInt; cdecl; external SDL_ImageLibName;
 
 (*  SDL_net  *)
 function  SDLNet_Init: LongInt; cdecl; external SDL_NetLibName;
--- 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