diff --git a/src/sfs/wadcvt.dpr b/src/sfs/wadcvt.dpr
index 5d1c1f1100afe4689e2c9bd4ccd377a6c90f925c..8d02803a8f82b23e903da72fc57113ffe7fda427 100644 (file)
--- a/src/sfs/wadcvt.dpr
+++ b/src/sfs/wadcvt.dpr
+(* 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}
{$ENDIF}
{$DEFINE UTFEXTRA}
+{.$DEFINE ONELINELOG}
+
+{$IFDEF WINDOWS}
+ {$UNDEF ONELINELOG}
+{$ENDIF}
program __wadcvt__;
uses
var
optConvertATX: Boolean = false;
+ optConvertTGA: Boolean = false;
+ optLoCaseNames: Boolean = false;
+ optAggressivePng: Boolean = false;
+ optRecompress: Boolean = false;
-function LoadAnimTexture (wadSt: TStream; wadName: AnsiString): TMemoryStream;
+function convertAnimTexture (wadSt: TStream; wadName: AnsiString): TMemoryStream;
var
WAD: TWADFile = nil;
TextureWAD: PChar = nil;
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;
end;
-{
-procedure processed (count: Cardinal);
+function recompressImageToPng (ist: TStream): TStream;
+var
+ ia: TDynImageDataArray = nil;
+ sto: TMemoryStream = nil;
+ f: Integer;
begin
- //writeln(' read ', count, ' bytes');
+ result := nil;
+ ist.position := 0;
+ GlobalMetadata.ClearMetaItems();
+ GlobalMetadata.ClearMetaItemsForSaving();
+ if not LoadMultiImageFromStream(ist, ia) then exit;
+ 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;
+ result := sto;
+ sto := nil;
+ end;
+ finally
+ sto.Free();
+ for f := 0 to High(ia) do FreeImage(ia[f]);
+ end;
end;
-}
// returs crc
var
fs, fo, ast: TStream;
fl: TSFSFileList;
- f: Integer;
+ f, c: Integer;
infname: AnsiString = '';
outfname: AnsiString = '';
dvfn: AnsiString;
newname: AnsiString;
files: array of TFileInfo;
nfo: TFileInfo;
+ nomoreopts: Boolean;
+ arg: AnsiString;
begin
if ParamCount() < 1 then
begin
Halt(1);
end;
+ Imaging.SetOption(ImagingPNGCompressLevel, 9);
+ Imaging.SetOption(ImagingPNGLoadAnimated, 1);
+ Imaging.SetOption(ImagingGIFLoadAnimated, 1);
+
for f := 1 to ParamCount() do
begin
- if ParamStr(f) = '--apng' then optConvertATX := true
+ arg := ParamStr(f);
+ if length(arg) = 0 then continue;
+ if not nomoreopts and (arg[1] = '-') then
+ begin
+ if arg = '--apng' then optConvertATX := true
+ 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');
+ writeln('options:');
+ writeln(' --apng convert animated textures to APNG format');
+ writeln(' --tga convert Targa images to PNG format');
+{$IFNDEF WINDOWS}
+ writeln(' --locase convert file names to lower case');
+{$ENDIF}
+ Halt(1);
+ end
+ else if arg = '--' then nomoreopts := true
+ else
+ begin
+ writeln('unknown option: "', arg, '"');
+ Halt(1);
+ end;
+ end
else
begin
- if length(infname) = 0 then infname := ParamStr(f)
- else if length(outfname) = 0 then outfname := ParamStr(f)
+ if length(infname) = 0 then infname := arg
+ else if length(outfname) = 0 then outfname := arg
else
begin
writeln('FATAL: too many arguments!');
Halt(1);
end;
- Imaging.SetOption(ImagingPNGCompressLevel, 9);
- Imaging.SetOption(ImagingPNGLoadAnimated, 1);
- Imaging.SetOption(ImagingGIFLoadAnimated, 1);
+{$IFNDEF WINDOWS}
+ optLoCaseNames := true;
+{$ENDIF}
fo := TFileStream.Create(outfname, fmCreate);
try
//fs.Free();
//fs := SFSFileOpen(dvfn+'::'+fl[f].fPath+fl[f].fName);
fs.position := 0;
-{$IFNDEF WINDOWS}
+{$IFNDEF ONELINELOG}
write(#13'[', f+1, '/', fl.Count, ']: ', fl[f].fPath, newname, ' ', fs.size, ' ... '#27'[K');
{$ELSE}
write('[', f+1, '/', fl.Count, ']: ', fl[f].fPath, newname, ' ', fs.size, ' ... ');
if optConvertATX and (StrEquCI1251(ExtractFileExt(newname), '.dfwad') or StrEquCI1251(ExtractFileExt(newname), '.wad')) then
begin
//writeln(' ANIMTEXT!');
- ast := LoadAnimTexture(fs, newname);
+ ast := convertAnimTexture(fs, newname);
if ast <> nil then
begin
fs.Free();
fs := ast;
newname := ChangeFileExt(newname, '.png');
- //writeln(' ANIMTEXT! [', newname, ']');
+{$IFNDEF ONELINELOG}
+ write('APNG ');
+{$ENDIF}
end;
+ end
+ else if optRecompress or (optConvertTGA and (StrEquCI1251(ExtractFileExt(newname), '.tga') or StrEquCI1251(ExtractFileExt(newname), '.bmp'))) then
+ begin
+ ast := recompressImageToPng(fs);
+ if ast <> nil then
+ begin
+ fs.Free();
+ fs := ast;
+ newname := ChangeFileExt(newname, '.png');
+{$IFNDEF ONELINELOG}
+ write('PNG ');
+{$ENDIF}
+ end;
+ fs.position := 0;
end;
- nfo := ZipOne(fo, fl[f].fPath+newname, fs);
- write('DONE');
-{$IFDEF WINDOWS}
+ 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(nfo.pksize, ' DONE');
+{$IFNDEF ONELINELOG}
writeln;
{$ENDIF}
SetLength(files, length(files)+1);
files[high(files)] := nfo;
end;
-{$IFNDEF WINDOWS}
- writeln(#13, fl.Count, ' files processed'#27'[K');
+{$IFNDEF ONELINELOG}
+ writeln(fl.Count, ' files processed.');
+{$ELSE}
+ writeln(#13, fl.Count, ' files processed.'#27'[K');
{$ENDIF}
writeCentralDir(fo, files);
except