fSplitterD.pas 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // The graphics rendering engine GLScene http://glscene.org
  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. type
  17. TForm1 = class(TForm)
  18. EDFile: TEdit;
  19. Button1: TButton;
  20. EDTileSize: TEdit;
  21. EDMask: TEdit;
  22. ProgressBar: TProgressBar;
  23. Label1: TLabel;
  24. LAAction: TLabel;
  25. RBFull: TRadioButton;
  26. RBHalf: TRadioButton;
  27. RBLow: TRadioButton;
  28. procedure Button1Click(Sender: TObject);
  29. private
  30. public
  31. end;
  32. var
  33. Form1: TForm1;
  34. implementation
  35. {$R *.dfm}
  36. uses
  37. GLS.VectorLists;
  38. procedure TForm1.Button1Click(Sender: TObject);
  39. var
  40. pic: TPicture;
  41. bmp, bmp2: TBitmap;
  42. s, sd, f: Integer;
  43. x, y: Integer;
  44. begin
  45. SetCurrentDir(ExtractFilePath(ParamStr(0)));
  46. s := StrToInt(EDTileSize.Text);
  47. pic := TPicture.Create;
  48. if RBHalf.Checked then
  49. f := 2
  50. else if RBLow.Checked then
  51. f := 4
  52. else
  53. f := 1;
  54. sd := s div f;
  55. ProgressBar.Position := 0;
  56. Screen.Cursor := crHourGlass;
  57. bmp := TBitmap.Create;
  58. bmp.PixelFormat := pf24bit;
  59. bmp.Width := sd;
  60. bmp.Height := sd;
  61. if f <> 1 then
  62. begin
  63. bmp2 := TBitmap.Create;
  64. bmp2.PixelFormat := pf24bit;
  65. bmp2.Width := s;
  66. bmp2.Height := s;
  67. end
  68. else
  69. bmp2 := nil;
  70. LAAction.Caption := 'Loading Jpeg texture...';
  71. LAAction.Visible := True;
  72. Refresh;
  73. pic.LoadFromFile(EDFile.Text);
  74. x := 0;
  75. while x < pic.Width do
  76. begin
  77. y := 0;
  78. while y < pic.Height do
  79. begin
  80. if sd <> s then
  81. begin
  82. bmp2.Canvas.Draw(-x, -y, pic.Graphic);
  83. bmp.Canvas.StretchDraw(Rect(0, 0, sd, sd), bmp2);
  84. end
  85. else
  86. bmp.Canvas.Draw(-x, -y, pic.Graphic);
  87. LAAction.Caption := Format('Generating tile %d-%d...', [x div s, y div s]);
  88. Refresh;
  89. bmp.SaveToFile(Format(EDMask.Text, [x div s, y div s]));
  90. ProgressBar.StepBy(1);
  91. Inc(y, s);
  92. end;
  93. Inc(x, s);
  94. end;
  95. bmp2.Free;
  96. bmp.Free;
  97. pic.Free;
  98. Screen.Cursor := crDefault;
  99. LAAction.Caption := 'Completed';
  100. ShowMessage('Done!');
  101. Application.Terminate;
  102. end;
  103. end.