fSplitterD.pas 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // The graphics engine GLScene https://github.com/glscene
  3. //
  4. unit fSplitterD;
  5. interface
  6. uses
  7. System.SysUtils,
  8. System.Classes,
  9. Vcl.Graphics,
  10. Vcl.Controls,
  11. Vcl.Forms,
  12. Vcl.Dialogs,
  13. Vcl.Imaging.Jpeg,
  14. Vcl.StdCtrls,
  15. Vcl.ComCtrls,
  16. GLScene.Utils;
  17. type
  18. TForm1 = class(TForm)
  19. EditFile: TEdit;
  20. Button1: TButton;
  21. EDTileSize: TEdit;
  22. EditMask: TEdit;
  23. ProgressBar: TProgressBar;
  24. Label1: TLabel;
  25. LAAction: TLabel;
  26. RBFull: TRadioButton;
  27. RBHalf: TRadioButton;
  28. RBLow: TRadioButton;
  29. procedure Button1Click(Sender: TObject);
  30. private
  31. PathJpgIn, PathJpgOut: TFileName;
  32. public
  33. end;
  34. var
  35. Form1: TForm1;
  36. implementation
  37. {$R *.dfm}
  38. uses
  39. GLS.VectorLists;
  40. procedure TForm1.Button1Click(Sender: TObject);
  41. var
  42. pic: TPicture;
  43. bmp, bmp2: TBitmap;
  44. s, sd, f: Integer;
  45. x, y: Integer;
  46. begin
  47. PathJpgIn := GetCurrentAssetPath() + '\map';
  48. SetCurrentDir(PathJpgIn);
  49. s := StrToInt(EDTileSize.Text);
  50. pic := TPicture.Create;
  51. if RBHalf.Checked then
  52. f := 2
  53. else if RBLow.Checked then
  54. f := 4
  55. else
  56. f := 1;
  57. sd := s div f;
  58. ProgressBar.Position := 0;
  59. Screen.Cursor := crHourGlass;
  60. bmp := TBitmap.Create;
  61. bmp.PixelFormat := pf24bit;
  62. bmp.Width := sd;
  63. bmp.Height := sd;
  64. if f <> 1 then
  65. begin
  66. bmp2 := TBitmap.Create;
  67. bmp2.PixelFormat := pf24bit;
  68. bmp2.Width := s;
  69. bmp2.Height := s;
  70. end
  71. else
  72. bmp2 := nil;
  73. LAAction.Caption := 'Loading Jpeg texture...';
  74. LAAction.Visible := True;
  75. Refresh;
  76. pic.LoadFromFile(EditFile.Text);
  77. x := 0;
  78. while x < pic.Width do
  79. begin
  80. y := 0;
  81. while y < pic.Height do
  82. begin
  83. if sd <> s then
  84. begin
  85. bmp2.Canvas.Draw(-x, -y, pic.Graphic);
  86. bmp.Canvas.StretchDraw(Rect(0, 0, sd, sd), bmp2);
  87. end
  88. else
  89. bmp.Canvas.Draw(-x, -y, pic.Graphic);
  90. LAAction.Caption := Format('Generating tile %d-%d...', [x div s, y div s]);
  91. Refresh;
  92. PathJpgOut := ExtractFilePath(ParamStr(0));
  93. SetCurrentDir(PathJpgOut);
  94. bmp.SaveToFile(Format(EditMask.Text, [x div s, y div s]));
  95. ProgressBar.StepBy(1);
  96. Inc(y, s);
  97. end;
  98. Inc(x, s);
  99. end;
  100. bmp2.Free;
  101. bmp.Free;
  102. pic.Free;
  103. Screen.Cursor := crDefault;
  104. LAAction.Caption := 'Completed';
  105. ShowMessage('Done!');
  106. Application.Terminate;
  107. end;
  108. end.