| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- unit DemoUtils;
- {$I ImagingOptions.inc}
- interface
- uses
- SysUtils,
- Classes,
- ImagingTypes,
- Imaging,
- ImagingUtility;
- const
- SDataDir = 'Data';
- { }
- function ExpandFileTo(const FileName, BasePath: string): string;
- { }
- function SwapPathDelims(const FileName: string; const NewDelim: string = PathDelim): string;
- { }
- function GetDataDir: string;
- { }
- function GetRootDir: string;
- { Returns next valid image format.}
- function NextFormat(Format: TImageFormat): TImageFormat;
- implementation
- function ExpandFileTo(const FileName, BasePath: string): string;
- var
- OldPath: string;
- begin
- GetDir(0, OldPath);
- try
- if SysUtils.DirectoryExists(BasePath) then
- begin
- ChDir(BasePath);
- Result:= ExpandFileName(FileName);
- end
- else
- Result:=FileName;
- finally
- ChDir(OldPath);
- end;
- end;
- function SwapPathDelims(const FileName, NewDelim: string): string;
- begin
- Result := FileName;
- Result := StringReplace(Result, '\', NewDelim, [rfReplaceAll]);
- Result := StringReplace(Result, '/', NewDelim, [rfReplaceAll]);
- end;
- function GetDataDir: string;
- begin
- Result := GetAppDir + PathDelim + SDataDir;
- if not DirectoryExists(Result) then
- Result := ExtractFileDir(GetAppDir) + PathDelim + SDataDir;
- if not DirectoryExists(Result) then
- Result := ExtractFileDir(ExtractFileDir(GetAppDir)) + PathDelim + SDataDir;
- end;
- function GetRootDir: string;
- begin
- Result := ExtractFileDir(GetAppDir);
- if not DirectoryExists(Result + PathDelim + 'Source') then
- begin
- Result := ExtractFileDir(Result);
- if not DirectoryExists(Result + PathDelim + 'Source') then
- begin
- Result := ExtractFileDir(Result);
- if not DirectoryExists(Result + PathDelim + 'Source') then
- begin
- Result := ExtractFileDir(Result);
- if not DirectoryExists(Result + PathDelim + 'Source') then
- Result := ExtractFileDir(Result);
- end;
- end;
- end;
- end;
- function NextFormat(Format: TImageFormat): TImageFormat;
- var
- Info: TImageFormatInfo;
- begin
- repeat
- if Format < High(TImageFormat) then
- Format := Succ(Format)
- else
- Format := ifIndex8;
- until GetImageFormatInfo(Format, Info);
- Result := Format;
- end;
- end.
|