| 1 |
{ |
| 2 |
Copyright 2009-2022 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
|
| 16 |
{ Read KTX or DDS and decompose multiple images into a number of simple images. |
| 17 |
See README.md for details. } |
| 18 |
program image_decompose; |
| 19 |
|
| 20 |
uses SysUtils, CastleUtils, CastleImages, CastleInternalCompositeImage, CastleLog, |
| 21 |
CastleStringUtils, CastleParameters, CastleUriUtils, CastleApplicationProperties; |
| 22 |
|
| 23 |
var |
| 24 |
SaveDecomposed: boolean = true; |
| 25 |
|
| 26 |
const |
| 27 |
Options: array[0..0] of TOption = |
| 28 |
( (Short:'n'; Long:'no-save'; Argument: oaNone) ); |
| 29 |
|
| 30 |
procedure OptionProc(OptionNum: Integer; HasArgument: boolean; |
| 31 |
const Argument: string; const SeparateArgs: TSeparateArgs; Data: Pointer); |
| 32 |
begin |
| 33 |
case OptionNum of |
| 34 |
0: SaveDecomposed := false; |
| 35 |
else raise EInternalError.Create('option not impl'); |
| 36 |
end; |
| 37 |
end; |
| 38 |
|
| 39 |
var |
| 40 |
Composite: TCompositeImage; |
| 41 |
OutputName, OutputBaseName: string; |
| 42 |
I: Integer; |
| 43 |
begin |
| 44 |
ApplicationProperties.OnWarning.Add( |
| 45 |
{$ifdef FPC}@{$endif} ApplicationProperties.WriteWarningOnConsole); |
| 46 |
Parameters.Parse(Options, @OptionProc, nil); |
| 47 |
Parameters.CheckHigh(1); |
| 48 |
Composite := TCompositeImage.Create; |
| 49 |
try |
| 50 |
Composite.LoadFromFile(Parameters[1]); |
| 51 |
Composite.Flatten3d; |
| 52 |
Writeln('Composite image loaded:', nl, |
| 53 |
' Width x Height x Depth: ', Composite.Width, ' x ', Composite.Height, ' x ', Composite.Depth, nl, |
| 54 |
' Type: ', CompositeTypeToString[Composite.CompositeType], nl, |
| 55 |
' Mipmaps: ', Composite.Mipmaps, nl, |
| 56 |
' Simple 2D images inside: ', Composite.Images.Count); |
| 57 |
|
| 58 |
if SaveDecomposed then |
| 59 |
begin |
| 60 |
OutputBaseName := ExtractURIPath(Parameters[1]) + |
| 61 |
DeleteURIExt(ExtractURIName(Parameters[1])) + '_'; |
| 62 |
for I := 0 to Composite.Images.Count - 1 do |
| 63 |
begin |
| 64 |
OutputName := OutputBaseName + IntToStrZPad(I, 2) + '.png'; |
| 65 |
Writeln('Writing ', OutputName); |
| 66 |
SaveImage(Composite.Images[I], OutputName); |
| 67 |
end; |
| 68 |
end; |
| 69 |
|
| 70 |
finally FreeAndNil(Composite) end; |
| 71 |
end. |