Skip to content

Commit

Permalink
refactore: add tile image resolution settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kfilippenok committed Jan 20, 2025
1 parent 004fa79 commit 3d6780a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/TilesManipulations/TilesManipulations.Base.pas
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,20 @@ TTilesManipulator = class
defPath = 'tiles/{p}/{z}/{x}/{y}';
defSkipMissing = False;
defShowFileType = False;
defUseOtherTileRes = False;
strict private
FLayers: TLayers;
FPath: String;
FShowFileType: Boolean;
FSkipMissing: Boolean;
FTileRes: Word;
FUseOtherTileRes: Boolean;
strict private
function ProcessPath(const AProviderName: String; const AZoom: Integer; const AX, AY: Integer): String;
procedure ResizeIfNeeded(var ATileImg: TBGRABitmap);
procedure SaveTile(const ATileImg: TBGRABitmap; AFilePath: String);
strict private // Getters and Setters
procedure SetTileRes(AValue: Word);
public // Calculations
class function CalcRowTilesCount(const AMinX, AMaxX: QWord): QWord; overload; static;
class function CalcColumnTilesCount(const AMinY, AMaxY: QWord): QWord; static;
Expand All @@ -186,6 +192,7 @@ TTilesManipulator = class
property Path : String read FPath write FPath;
property ShowFileType: Boolean read FShowFileType write FShowFileType default defShowFileType;
property SkipMissing : Boolean read FSkipMissing write FSkipMissing default defSkipMissing;
property TileRes : Word read FTileRes write SetTileRes;
end;

implementation
Expand Down Expand Up @@ -437,6 +444,17 @@ function TTilesManipulator.ProcessPath(const AProviderName: String;
Result := Result + IfThen(ShowFileType, '.png');
end;

procedure TTilesManipulator.ResizeIfNeeded(var ATileImg: TBGRABitmap);
var
OldTileImg: TBGRABitmap;
begin
if not FUseOtherTileRes then Exit;

OldTileImg := ATileImg;
ATileImg := ATileImg.Resample(TileRes, TileRes);
OldTileImg.Free;
end;

procedure TTilesManipulator.SaveTile(const ATileImg: TBGRABitmap;
AFilePath: String);
var
Expand All @@ -459,6 +477,13 @@ procedure TTilesManipulator.SaveTile(const ATileImg: TBGRABitmap;
end;
end;

procedure TTilesManipulator.SetTileRes(AValue: Word);
begin
FUseOtherTileRes := True;
if FTileRes = AValue then Exit;
FTileRes := AValue;
end;

class function TTilesManipulator.CalcRowTilesCount(const AMinX, AMaxX: QWord): QWord;
begin
Result := AMaxX - AMinX + 1;
Expand Down Expand Up @@ -496,6 +521,7 @@ constructor TTilesManipulator.Create;
inherited Create;

FLayers := TLayers.Create(True);
FUseOtherTileRes := defUseOtherTileRes;
FPath := defPath;
FShowFileType := defShowFileType;
FSkipMissing := defSkipMissing;
Expand Down Expand Up @@ -561,6 +587,7 @@ procedure TTilesManipulator.Download(const AMinZoom, AMaxZoom: Integer; const AM
LBuffer := Layers[il].Buffer.Duplicate(True);
Continue;
end;
ResizeIfNeeded(LBuffer);
Layers[il].ResampleAndPaintTo(LBuffer);
end;
SaveTile(LBuffer, ProcessPath(Layers[0].Provider.Name, iz, ix, iy));
Expand Down

0 comments on commit 3d6780a

Please sign in to comment.