unit1.pas 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, FileUtil, strings, Forms, Controls, Graphics, Dialogs, StdCtrls,
  6. BGRABitmap, BGRABitmapTypes, BGRAVirtualScreen, dynlibs;
  7. const
  8. {$IFDEF WINDOWS}
  9. LIBRARYEXT = '*.dll';
  10. {$ENDIF}
  11. {$IFDEF LINUX}
  12. LIBRARYEXT = '*.so';
  13. {$ENDIF}
  14. {$IFDEF DARWIN}
  15. LIBRARYEXT = '*.dylib';
  16. {$ENDIF}
  17. type
  18. TFilterName = procedure(s: PChar); cdecl;
  19. TApplyFilter = procedure(BGRA: TBGRABitmap); cdecl;
  20. type
  21. { TForm1 }
  22. TForm1 = class(TForm)
  23. BGRAVirtualScreen1: TBGRAVirtualScreen;
  24. ComboBox1: TComboBox;
  25. procedure BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  26. procedure ComboBox1Select(Sender: TObject);
  27. procedure FormCreate(Sender: TObject);
  28. procedure FormDestroy(Sender: TObject);
  29. private
  30. { private declarations }
  31. DLLnames: TStringList;
  32. CurrentFilter: TApplyFilter;
  33. dll: TLibHandle;
  34. public
  35. { public declarations }
  36. end;
  37. var
  38. Form1: TForm1;
  39. implementation
  40. {$R *.lfm}
  41. { TForm1 }
  42. procedure TForm1.BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
  43. begin
  44. Bitmap.Fill(BGRA(255, 0, 0));
  45. if Assigned(CurrentFilter) then
  46. CurrentFilter(Bitmap);
  47. end;
  48. procedure TForm1.ComboBox1Select(Sender: TObject);
  49. begin
  50. if dll <> dynlibs.NilHandle then
  51. if FreeLibrary(dll) then
  52. dll := dynlibs.NilHandle;
  53. dll := LoadLibrary(DLLnames[ComboBox1.ItemIndex]);
  54. if dll <> dynlibs.NilHandle then
  55. begin
  56. CurrentFilter := TApplyFilter(GetProcAddress(dll, 'ApplyFilter'));
  57. end;
  58. BGRAVirtualScreen1.DiscardBitmap;
  59. end;
  60. procedure TForm1.FormCreate(Sender: TObject);
  61. var
  62. i: integer;
  63. GetName: TFilterName;
  64. s: PChar;
  65. begin
  66. DLLnames := FindAllFiles(ProgramDirectory, LIBRARYEXT, False);
  67. for i := 0 to DLLnames.Count - 1 do
  68. begin
  69. DLLnames[i] := ExtractFileName(DLLnames[i]);
  70. end;
  71. s := stralloc(50);
  72. for i := 0 to DLLnames.Count - 1 do
  73. begin
  74. dll := LoadLibrary(DLLnames[i]);
  75. if dll <> dynlibs.NilHandle then
  76. begin
  77. GetName := TFilterName(GetProcAddress(dll, 'FilterName'));
  78. if Assigned(GetName) then
  79. begin
  80. GetName(s);
  81. ComboBox1.Items.Add(string(s));
  82. end;
  83. if FreeLibrary(dll) then
  84. dll := dynlibs.NilHandle;
  85. end;
  86. end;
  87. strdispose(s);
  88. end;
  89. procedure TForm1.FormDestroy(Sender: TObject);
  90. begin
  91. DLLnames.Free;
  92. end;
  93. end.