UsingDll.xml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <?xml-stylesheet type="text/xsl" href="../../Xsl/doc2html.xsl"?>
  3. <doc>
  4. <title>Using dll/so Access</title>
  5. <chapter>
  6. <title>Using dll/so Access</title>
  7. <par>You can use Imaging library directly from your <b>Object Pascal</b>
  8. project by means of <icode>uses</icode> clause.
  9. This kind of usage is recommended but you can also use Imaging library
  10. in the form of external library - dynamic link library (Windows <keyword>
  11. dll</keyword> file) or shared objects (Linux <keyword>SO</keyword> file).
  12. Using external library can be useful if you have have more executables
  13. using Imaging which will be distributed together (so you can have
  14. smaller executables). This is also only way how to use Imaging from
  15. programming languages other than <b>Object Pascal</b>.</par>
  16. <par>First you need Imaging compiled to external library. Projects
  17. for building external library can be found in
  18. <keyword>Source/Projects</keyword> directory.
  19. You can also use build scripts named <keyword>BuildLibrary*.bat</keyword>
  20. and <keyword>BuildLibrary*.sh</keyword>. They are located in
  21. <keyword>Scripts</keyword> directory and compiled library will be placed
  22. in <keyword>Bin</keyword> directory. In order to successfully use
  23. these scripts you must have paths to compilers properly set.
  24. When you have compiled library you must assure that operating system is
  25. be able to find it at your application's startup.
  26. Windows library is named <keyword>VampyreImaging.dll</keyword> and
  27. Linux version has name <keyword>libVampyreImaging.so</keyword>.
  28. </par>
  29. <par>
  30. Next thing you need is wrapper for programming language you want to use.
  31. Now there are wrappers for <b>Object Pascal</b>, <b>C/C++</b>
  32. and <b>Delphi.NET</b>. Wrappers are located in
  33. <keyword>Source/Wrappers</keyword> directory.
  34. </par>
  35. <note>
  36. Some types of function parameters differ between dll/so usage and
  37. direct usage. <icode>string</icode> types are changed to <icode>PChar</icode>
  38. types, dynamic arrays are not used at all - wrapper type
  39. <ref>TImageDataList</ref> is used instead.
  40. Also all function names have <icode>Im</icode> prefix.
  41. </note>
  42. <par>
  43. Here you can find some code fragments which will show you how
  44. to use dll/so access to Imaging library.
  45. If you want samples in language other than <b>Object Pascal</b> look
  46. at <link url="../Demos/Demos.xml">Demos</link>.
  47. </par>
  48. <code>
  49. uses
  50. ImagingTypes, ImagingImport;
  51. var
  52. Img: <ref>TImageData</ref>
  53. begin
  54. // this call loads external Imaging library, you should check if it was successful
  55. if not <ref>ImLoadLibrary</ref> then
  56. WriteLn('Imaging library dll was not loaded successfully, program will crash soon!');
  57. // call this before any access to TImageData is made
  58. <ref>ImInitImage</ref>(Img);
  59. // load some image
  60. <ref>ImLoadImageFromFile</ref>('/home/galfar/images/jaguar.jpg', Img);
  61. // compress it to DXT1 format
  62. <ref>ImConvertImage</ref>(Img, ifDXT1);
  63. // and save it in DDS file format
  64. <ref>ImSaveImageToFile</ref>('/home/galfar/images/jaguar.dds', Img);
  65. // free memory occupied by image
  66. <ref>ImFreeImage</ref>(Img);
  67. // unload Imaging library
  68. <ref>ImFreeLibrary</ref>;
  69. end.
  70. </code>
  71. <par>Since <ref>TDynImageDataArray</ref> is <b>Object Pascal</b> dynamic array,
  72. which can not be used from other languages, all parameters of this
  73. type are replaced with <ref>TImageDataList</ref> typed parameters.
  74. Some new functions are introduced for accessing list's items and properties.
  75. You can see them all in action in the next code listing.
  76. </par>
  77. <code>
  78. uses
  79. ImagingTypes, ImagingImport;
  80. var
  81. ImgList: <ref>TImageDataList</ref>;
  82. Img: <ref>TImageData</ref>;
  83. I, Size: LongInt;
  84. begin
  85. // this call loads external Imaging library, you should check if it was successful
  86. if not <ref>ImLoadLibrary</ref> then
  87. WriteLn('Imaging library dll was not loaded successfully, program will crash soon!');
  88. // make sure list pointer doesn't point to invalid memory address
  89. ImgList := nil;
  90. // load some images, list's size is changed during loading
  91. <ref>ImLoadMultiImageFromFile</ref>('/home/galfar/images/jaguar_with_mipmaps.jpg', Img);
  92. // get the actual list's size
  93. Size := <ref>ImGetImageListSize</ref>(ImgList);
  94. for I := 0 to Size - 1 do
  95. begin
  96. // get list's element
  97. <ref>ImGetImageListElement</ref>(ImgList, Img, I);
  98. // resize element
  99. <ref>ImResizeImage</ref>(Img, Img.Width / 2, Img.Height / 2, rfBicubic);
  100. // set list's element
  101. <ref>ImSetImageListElement</ref>(ImgList, Img, I);
  102. end;
  103. // create space for new image in the list
  104. <ref>ImSetImageListSize</ref>(ImgList, Size + 1);
  105. // create new image
  106. <ref>ImNewImage</ref>(256, 256, ifDXT1, Img);
  107. // put this new image into the list
  108. <ref>ImSetImageListElement</ref>(ImgList, Img, Size);
  109. // save halved images to file
  110. <ref>ImSaveMultiImageToFile</ref>('/home/galfar/images/jaguar_smaller.dds', Img);
  111. // free all images in list and list itself
  112. <ref>ImFreeImageList</ref>(ImgList);
  113. // unload Imaging library
  114. <ref>ImFreeLibrary</ref>;
  115. end.
  116. </code>
  117. </chapter>
  118. </doc>