imgcnv.dpr
资源名称:CAST2SDK.rar [点击查看]
上传用户:yj_qiu
上传日期:2022-08-08
资源大小:23636k
文件大小:2k
源码类别:
游戏引擎
开发平台:
Delphi
- program imgcnv;
- {$APPTYPE CONSOLE}
- uses
- SysUtils,
- Imaging, ImagingTypes;
- var
- Img: TImageData;
- DestFormat: TImageFormat;
- procedure HaltWithError(const Str: string; Code: Integer);
- begin
- Writeln(Str);
- FreeImage(Img);
- Halt(Code);
- end;
- function ChooseFormat(const FmtStr: string): TImageFormat;
- type TFmtRec = record Str: string[8]; Format: TImageFormat; end;
- const
- KnownFormats: array[0..9] of TFmtRec = (
- (Str: 'Gray8'; Format: ifGray8),
- (Str: 'Gray16'; Format: ifGray16),
- (Str: 'R5G6B5'; Format: ifR5G6B5),
- (Str: 'A1R5G5B5'; Format: ifA1R5G5B5),
- (Str: 'A4R4G4B4'; Format: ifA4R4G4B4),
- (Str: 'R8G8B8'; Format: ifR8G8B8),
- (Str: 'A8R8G8B8'; Format: ifA8R8G8B8),
- (Str: 'DXT1'; Format: ifDXT1),
- (Str: 'DXT3'; Format: ifDXT3),
- (Str: 'DXT5'; Format: ifDXT5)
- );
- var i: Integer;
- begin
- Result := ifUnknown;
- i := High(KnownFormats);
- while (i >= 0) and (KnownFormats[i].Str <> FmtStr) do Dec(i);
- if not (i >= 0) then begin
- Writeln('Invalid output format. Supported formats:');
- for i := 0 to High(KnownFormats) do Writeln(' ', KnownFormats[i].Str);
- HaltWithError('', 3);
- end else Result := KnownFormats[i].Format;
- end;
- begin
- if ParamCount < 2 then
- HaltWithError('Usage: imgcnv <input file> <output file> [<output format>]', 1);
- if ParamCount > 2 then
- DestFormat := ChooseFormat(ParamStr(3))
- else
- DestFormat := ifUnknown;
- Writeln('Loading image ', ParamStr(1), '...');
- if not LoadImageFromFile(ParamStr(1), Img) then
- HaltWithError('Error loading image ' + ParamStr(1) + '!', 2);
- if (DestFormat <> ifUnknown) and (DestFormat <> Img.Format) then begin
- Writeln('Converting to format ', ParamStr(3), '...');
- if not ConvertImage(Img, DestFormat) then HaltWithError('Conversion error', 3);
- end;
- Writeln('Saving image as ', ParamStr(2), '...');
- if not SaveImageToFile(ParamStr(2), Img) then
- HaltWithError('Error saving image as ' + ParamStr(2) + '!', 4);
- HaltWithError('Success!', 0);
- end.