DEADSOFTWARE

added license info
[d2df-sdl.git] / src / sfs / wadcvt.dpr
index af1f8d527845c68afde2fd687790a7c8e8f9bdf6..8d02803a8f82b23e903da72fc57113ffe7fda427 100644 (file)
@@ -1,3 +1,18 @@
+(* Copyright (C)  DooM 2D:Forever Developers
+ *
+ * This program 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *)
 {$MODE OBJFPC}
 {$IFDEF WINDOWS}
   {$APPTYPE CONSOLE}
@@ -38,6 +53,8 @@ var
   optConvertATX: Boolean = false;
   optConvertTGA: Boolean = false;
   optLoCaseNames: Boolean = false;
+  optAggressivePng: Boolean = false;
+  optRecompress: Boolean = false;
 
 
 function convertAnimTexture (wadSt: TStream; wadName: AnsiString): TMemoryStream;
@@ -179,6 +196,8 @@ begin
 
       sto := TMemoryStream.Create();
       //writeln(' ... [', ChangeFileExt(wadName, '.png'), '] (', length(ia), ') ');
+      Imaging.SetOption(ImagingPNGCompressLevel, 9);
+      if optAggressivePng then Imaging.SetOption(ImagingPNGPreFilter, 6);
       if SaveMultiImageToStream('png', sto, ia) then
       begin
         sto.position := 0;
@@ -219,6 +238,8 @@ begin
   try
     GlobalMetadata.CopyLoadedMetaItemsForSaving;
     sto := TMemoryStream.Create();
+    Imaging.SetOption(ImagingPNGCompressLevel, 9);
+    if optAggressivePng then Imaging.SetOption(ImagingPNGPreFilter, 6);
     if SaveMultiImageToStream('png', sto, ia) then
     begin
       sto.position := 0;
@@ -765,6 +786,10 @@ begin
     Halt(1);
   end;
 
+  Imaging.SetOption(ImagingPNGCompressLevel, 9);
+  Imaging.SetOption(ImagingPNGLoadAnimated, 1);
+  Imaging.SetOption(ImagingGIFLoadAnimated, 1);
+
   for f := 1 to ParamCount() do
   begin
     arg := ParamStr(f);
@@ -775,6 +800,8 @@ begin
       else if arg = '--tga' then optConvertTGA := true
       else if arg = '--locase' then optLoCaseNames := true
       else if arg = '--nocase' then optLoCaseNames := false
+      else if arg = '--aggressive' then begin optAggressivePng := true; Imaging.SetOption(ImagingPNGPreFilter, 6); end
+      else if arg = '--recompress' then optRecompress := true
       else if (arg = '--help') or (arg = '-h') then
       begin
         writeln('usage: wadcvt [options] file.wad');
@@ -825,10 +852,6 @@ begin
     Halt(1);
   end;
 
-  Imaging.SetOption(ImagingPNGCompressLevel, 9);
-  Imaging.SetOption(ImagingPNGLoadAnimated, 1);
-  Imaging.SetOption(ImagingGIFLoadAnimated, 1);
-
 {$IFNDEF WINDOWS}
   optLoCaseNames := true;
 {$ENDIF}
@@ -863,7 +886,7 @@ begin
 {$ENDIF}
         end;
       end
-      else if optConvertTGA and (StrEquCI1251(ExtractFileExt(newname), '.tga') or StrEquCI1251(ExtractFileExt(newname), '.bmp')) then
+      else if optRecompress or (optConvertTGA and (StrEquCI1251(ExtractFileExt(newname), '.tga') or StrEquCI1251(ExtractFileExt(newname), '.bmp'))) then
       begin
         ast := recompressImageToPng(fs);
         if ast <> nil then
@@ -880,7 +903,7 @@ begin
       newname := fl[f].fPath+newname;
       if optLoCaseNames then for c := 1 to length(newname) do newname[c] := LoCase1251(newname[c]);
       nfo := ZipOne(fo, newname, fs);
-      write('DONE');
+      write(nfo.pksize, ' DONE');
 {$IFNDEF ONELINELOG}
       writeln;
 {$ENDIF}