ImagingExport.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. {
  2. $Id$
  3. Vampyre Imaging Library
  4. by Marek Mauder
  5. http://imaginglib.sourceforge.net
  6. The contents of this file are used with permission, subject to the Mozilla
  7. Public License Version 1.1 (the "License"); you may not use this file except
  8. in compliance with the License. You may obtain a copy of the License at
  9. http://www.mozilla.org/MPL/MPL-1.1.html
  10. Software distributed under the License is distributed on an "AS IS" basis,
  11. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  12. the specific language governing rights and limitations under the License.
  13. Alternatively, the contents of this file may be used under the terms of the
  14. GNU Lesser General Public License (the "LGPL License"), in which case the
  15. provisions of the LGPL License are applicable instead of those above.
  16. If you wish to allow use of your version of this file only under the terms
  17. of the LGPL License and not to allow others to use your version of this file
  18. under the MPL, indicate your decision by deleting the provisions above and
  19. replace them with the notice and other provisions required by the LGPL
  20. License. If you do not delete the provisions above, a recipient may use
  21. your version of this file under either the MPL or the LGPL License.
  22. For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html
  23. }
  24. { This function contains functions exported from Imaging dynamic link library.
  25. All string are exported as PChars and all var parameters are exported
  26. as pointers. All posible exceptions getting out of dll are catched.}
  27. unit ImagingExport;
  28. {$I ImagingOptions.inc}
  29. interface
  30. uses
  31. ImagingTypes,
  32. Imaging;
  33. { Returns version of Imaging library. }
  34. procedure ImGetVersion(var Major, Minor, Patch: LongInt); cdecl;
  35. { Look at InitImage for details.}
  36. procedure ImInitImage(var Image: TImageData); cdecl;
  37. { Look at NewImage for details.}
  38. function ImNewImage(Width, Height: LongInt; Format: TImageFormat;
  39. var Image: TImageData): Boolean; cdecl;
  40. { Look at TestImage for details.}
  41. function ImTestImage(var Image: TImageData): Boolean; cdecl;
  42. { Look at FreeImage for details.}
  43. function ImFreeImage(var Image: TImageData): Boolean; cdecl;
  44. { Look at DetermineFileFormat for details. Ext should have enough space for
  45. result file extension.}
  46. function ImDetermineFileFormat(FileName, Ext: PChar): Boolean; cdecl;
  47. { Look at DetermineMemoryFormat for details. Ext should have enough space for
  48. result file extension.}
  49. function ImDetermineMemoryFormat(Data: Pointer; Size: LongInt; Ext: PChar): Boolean; cdecl;
  50. { Look at IsFileFormatSupported for details.}
  51. function ImIsFileFormatSupported(FileName: PChar): Boolean; cdecl;
  52. { Look at EnumFileFormats for details.}
  53. function ImEnumFileFormats(var Index: LongInt; Name, DefaultExt, Masks: PChar;
  54. var CanSave, IsMultiImageFormat: Boolean): Boolean; cdecl;
  55. { Inits image list.}
  56. function ImInitImageList(Size: LongInt; var ImageList: TImageDataList): Boolean; cdecl;
  57. { Returns size of image list.}
  58. function ImGetImageListSize(ImageList: TImageDataList): LongInt; cdecl;
  59. { Returns image list's element at given index. Output image is not cloned it's
  60. Bits point to Bits in list => do not free OutImage.}
  61. function ImGetImageListElement(ImageList: TImageDataList; Index: LongInt;
  62. var OutImage: TImageData): Boolean; cdecl;
  63. { Sets size of image list.}
  64. function ImSetImageListSize(ImageList: TImageDataList; NewSize: LongInt): Boolean; cdecl;
  65. { Sets image list element at given index. Input image is not cloned - image in
  66. list will point to InImage's Bits.}
  67. function ImSetImageListElement(ImageList: TImageDataList; Index: LongInt;
  68. const InImage: TImageData): Boolean; cdecl;
  69. { Returns True if all images in list pass ImTestImage test. }
  70. function ImTestImagesInList(ImageList: TImageDataList): Boolean; cdecl;
  71. { Frees image list and all images in it.}
  72. function ImFreeImageList(var ImageList: TImageDataList): Boolean; cdecl;
  73. { Look at LoadImageFromFile for details.}
  74. function ImLoadImageFromFile(FileName: PChar; var Image: TImageData): Boolean; cdecl;
  75. { Look at LoadImageFromMemory for details.}
  76. function ImLoadImageFromMemory(Data: Pointer; Size: LongInt; var Image: TImageData): Boolean; cdecl;
  77. { Look at LoadMultiImageFromFile for details.}
  78. function ImLoadMultiImageFromFile(FileName: PChar; var ImageList: TImageDataList): Boolean; cdecl;
  79. { Look at LoadMultiImageFromMemory for details.}
  80. function ImLoadMultiImageFromMemory(Data: Pointer; Size: LongInt;
  81. var ImageList: TImageDataList): Boolean; cdecl;
  82. { Look at SaveImageToFile for details.}
  83. function ImSaveImageToFile(FileName: PChar; const Image: TImageData): Boolean; cdecl;
  84. { Look at SaveImageToMemory for details.}
  85. function ImSaveImageToMemory(Ext: PChar; Data: Pointer; var Size: LongInt;
  86. const Image: TImageData): Boolean; cdecl;
  87. { Look at SaveMultiImageToFile for details.}
  88. function ImSaveMultiImageToFile(FileName: PChar; ImageList: TImageDataList): Boolean; cdecl;
  89. { Look at SaveMultiImageToMemory for details.}
  90. function ImSaveMultiImageToMemory(Ext: PChar; Data: Pointer; Size: PLongInt;
  91. ImageList: TImageDataList): Boolean; cdecl;
  92. { Look at CloneImage for details.}
  93. function ImCloneImage(const Image: TImageData; var Clone: TImageData): Boolean; cdecl;
  94. { Look at ConvertImage for details.}
  95. function ImConvertImage(var Image: TImageData; DestFormat: TImageFormat): Boolean; cdecl;
  96. { Look at FlipImage for details.}
  97. function ImFlipImage(var Image: TImageData): Boolean; cdecl;
  98. { Look at MirrorImage for details.}
  99. function ImMirrorImage(var Image: TImageData): Boolean; cdecl;
  100. { Look at ResizeImage for details.}
  101. function ImResizeImage(var Image: TImageData; NewWidth, NewHeight: LongInt;
  102. Filter: TResizeFilter): Boolean; cdecl;
  103. { Look at SwapChannels for details.}
  104. function ImSwapChannels(var Image: TImageData; SrcChannel, DstChannel: LongInt): Boolean; cdecl;
  105. { Look at ReduceColors for details.}
  106. function ImReduceColors(var Image: TImageData; MaxColors: LongInt): Boolean; cdecl;
  107. { Look at GenerateMipMaps for details.}
  108. function ImGenerateMipMaps(const Image: TImageData; Levels: LongInt;
  109. var MipMaps: TImageDataList): Boolean; cdecl;
  110. { Look at MapImageToPalette for details.}
  111. function ImMapImageToPalette(var Image: TImageData; Pal: PPalette32;
  112. Entries: LongInt): Boolean; cdecl;
  113. { Look at SplitImage for details.}
  114. function ImSplitImage(var Image: TImageData; var Chunks: TImageDataList;
  115. ChunkWidth, ChunkHeight: LongInt; var XChunks, YChunks: LongInt;
  116. PreserveSize: Boolean; Fill: Pointer): Boolean; cdecl;
  117. { Look at MakePaletteForImages for details.}
  118. function ImMakePaletteForImages(Images: TImageDataList; Pal: PPalette32;
  119. MaxColors: LongInt; ConvertImages: Boolean): Boolean; cdecl;
  120. { Look at RotateImage for details.}
  121. function ImRotateImage(var Image: TImageData; Angle: LongInt): Boolean; cdecl;
  122. { Look at CopyRect for details.}
  123. function ImCopyRect(const SrcImage: TImageData; SrcX, SrcY, Width, Height: LongInt;
  124. var DstImage: TImageData; DstX, DstY: LongInt): Boolean; cdecl;
  125. { Look at FillRect for details.}
  126. function ImFillRect(var Image: TImageData; X, Y, Width, Height: LongInt;
  127. Fill: Pointer): Boolean; cdecl;
  128. { Look at ReplaceColor for details.}
  129. function ImReplaceColor(var Image: TImageData; X, Y, Width, Height: LongInt;
  130. OldPixel, NewPixel: Pointer): Boolean; cdecl;
  131. { Look at StretchRect for details.}
  132. function ImStretchRect(const SrcImage: TImageData; SrcX, SrcY, SrcWidth,
  133. SrcHeight: LongInt; var DstImage: TImageData; DstX, DstY, DstWidth,
  134. DstHeight: LongInt; Filter: TResizeFilter): Boolean; cdecl;
  135. { Look at GetPixelDirect for details.}
  136. procedure ImGetPixelDirect(const Image: TImageData; X, Y: LongInt; Pixel: Pointer); cdecl;
  137. { Look at SetPixelDirect for details.}
  138. procedure ImSetPixelDirect(const Image: TImageData; X, Y: LongInt; Pixel: Pointer); cdecl;
  139. { Look at GetPixel32 for details.}
  140. function ImGetPixel32(const Image: TImageData; X, Y: LongInt): TColor32Rec; cdecl;
  141. { Look at SetPixel32 for details.}
  142. procedure ImSetPixel32(const Image: TImageData; X, Y: LongInt; const Color: TColor32Rec); cdecl;
  143. { Look at GetPixelFP for details.}
  144. function ImGetPixelFP(const Image: TImageData; X, Y: LongInt): TColorFPRec; cdecl;
  145. { Look at SetPixelFP for details.}
  146. procedure ImSetPixelFP(const Image: TImageData; X, Y: LongInt; const Color: TColorFPRec); cdecl;
  147. { Look at NewPalette for details.}
  148. function ImNewPalette(Entries: LongInt; var Pal: PPalette32): Boolean; cdecl;
  149. { Look at FreePalette for details.}
  150. function ImFreePalette(var Pal: PPalette32): Boolean; cdecl;
  151. { Look at CopyPalette for details.}
  152. function ImCopyPalette(SrcPal, DstPal: PPalette32; SrcIdx, DstIdx, Count: LongInt): Boolean; cdecl;
  153. { Look at FindColor for details.}
  154. function ImFindColor(Pal: PPalette32; Entries: LongInt; Color: TColor32): LongInt; cdecl;
  155. { Look at FillGrayscalePalette for details.}
  156. function ImFillGrayscalePalette(Pal: PPalette32; Entries: LongInt): Boolean; cdecl;
  157. { Look at FillCustomPalette for details.}
  158. function ImFillCustomPalette(Pal: PPalette32; Entries: LongInt; RBits, GBits,
  159. BBits: Byte; Alpha: Byte): Boolean; cdecl;
  160. { Look at SwapChannelsOfPalette for details.}
  161. function ImSwapChannelsOfPalette(Pal: PPalette32; Entries, SrcChannel,
  162. DstChannel: LongInt): Boolean; cdecl;
  163. { Look at SetOption for details.}
  164. function ImSetOption(OptionId, Value: LongInt): Boolean; cdecl;
  165. { Look at GetOption for details.}
  166. function ImGetOption(OptionId: LongInt): LongInt; cdecl;
  167. { Look at PushOptions for details.}
  168. function ImPushOptions: Boolean; cdecl;
  169. { Look at PopOptions for details.}
  170. function ImPopOptions: Boolean; cdecl;
  171. { Look at GetImageFormatInfo for details.}
  172. function ImGetImageFormatInfo(Format: TImageFormat; var Info: TImageFormatInfo): Boolean; cdecl;
  173. { Look at GetPixelsSize for details.}
  174. function ImGetPixelsSize(Format: TImageFormat; Width, Height: LongInt): LongInt; cdecl;
  175. { Look at SetUserFileIO for details.}
  176. procedure ImSetUserFileIO(OpenReadProc: TOpenReadProc; OpenWriteProc:
  177. TOpenWriteProc; CloseProc: TCloseProc; EofProc: TEofProc; SeekProc: TSeekProc;
  178. TellProc: TTellProc; ReadProc: TReadProc; WriteProc: TWriteProc); cdecl;
  179. { Look at ResetFileIO for details.}
  180. procedure ImResetFileIO; cdecl;
  181. { These are only for documentation generation reasons.}
  182. { Loads Imaging functions from dll/so library.}
  183. function ImLoadLibrary: Boolean;
  184. { Frees Imaging functions loaded from dll/so and releases library.}
  185. function ImFreeLibrary: Boolean;
  186. implementation
  187. uses
  188. SysUtils,
  189. ImagingUtility;
  190. function ImLoadLibrary: Boolean; begin Result := True; end;
  191. function ImFreeLibrary: Boolean; begin Result := True; end;
  192. type
  193. TInternalList = record
  194. List: TDynImageDataArray;
  195. end;
  196. PInternalList = ^TInternalList;
  197. procedure ImGetVersion(var Major, Minor, Patch: LongInt);
  198. begin
  199. Major := ImagingVersionMajor;
  200. Minor := ImagingVersionMinor;
  201. Patch := ImagingVersionPatch;
  202. end;
  203. procedure ImInitImage(var Image: TImageData);
  204. begin
  205. try
  206. Imaging.InitImage(Image);
  207. except
  208. end;
  209. end;
  210. function ImNewImage(Width, Height: LongInt; Format: TImageFormat;
  211. var Image: TImageData): Boolean;
  212. begin
  213. try
  214. Result := Imaging.NewImage(Width, Height, Format, Image);
  215. except
  216. Result := False;
  217. end;
  218. end;
  219. function ImTestImage(var Image: TImageData): Boolean;
  220. begin
  221. try
  222. Result := Imaging.TestImage(Image);
  223. except
  224. Result := False;
  225. end;
  226. end;
  227. function ImFreeImage(var Image: TImageData): Boolean;
  228. begin
  229. try
  230. Result := Imaging.FreeImage(Image);
  231. except
  232. Result := False;
  233. end;
  234. end;
  235. function ImDetermineFileFormat(FileName, Ext: PChar): Boolean;
  236. var
  237. S: string;
  238. begin
  239. try
  240. S := Imaging.DetermineFileFormat(FileName);
  241. Result := S <> '';
  242. StrCopy(Ext, PChar(S));
  243. except
  244. Result := False;
  245. end;
  246. end;
  247. function ImDetermineMemoryFormat(Data: Pointer; Size: LongInt; Ext: PChar): Boolean;
  248. var
  249. S: string;
  250. begin
  251. try
  252. S := Imaging.DetermineMemoryFormat(Data, Size);
  253. Result := S <> '';
  254. StrCopy(Ext, PChar(S));
  255. except
  256. Result := False;
  257. end;
  258. end;
  259. function ImIsFileFormatSupported(FileName: PChar): Boolean;
  260. begin
  261. try
  262. Result := Imaging.IsFileFormatSupported(FileName);
  263. except
  264. Result := False;
  265. end;
  266. end;
  267. function ImEnumFileFormats(var Index: LongInt; Name, DefaultExt, Masks: PChar;
  268. var CanSave, IsMultiImageFormat: Boolean): Boolean;
  269. var
  270. StrName, StrDefaultExt, StrMasks: string;
  271. begin
  272. try
  273. Result := Imaging.EnumFileFormats(Index, StrName, StrDefaultExt, StrMasks, CanSave,
  274. IsMultiImageFormat);
  275. StrCopy(Name, PChar(StrName));
  276. StrCopy(DefaultExt, PChar(StrDefaultExt));
  277. StrCopy(Masks, PChar(StrMasks));
  278. except
  279. Result := False;
  280. end;
  281. end;
  282. function ImInitImageList(Size: LongInt; var ImageList: TImageDataList): Boolean;
  283. var
  284. Int: PInternalList;
  285. begin
  286. try
  287. try
  288. ImFreeImageList(ImageList);
  289. except
  290. end;
  291. New(Int);
  292. SetLength(Int.List, Size);
  293. ImageList := TImageDataList(Int);
  294. Result := True;
  295. except
  296. Result := False;
  297. ImageList := nil;
  298. end;
  299. end;
  300. function ImGetImageListSize(ImageList: TImageDataList): LongInt;
  301. begin
  302. try
  303. Result := Length(PInternalList(ImageList).List);
  304. except
  305. Result := -1;
  306. end;
  307. end;
  308. function ImGetImageListElement(ImageList: TImageDataList; Index: LongInt;
  309. var OutImage: TImageData): Boolean;
  310. begin
  311. try
  312. Index := ClampInt(Index, 0, Length(PInternalList(ImageList).List) - 1);
  313. ImCloneImage(PInternalList(ImageList).List[Index], OutImage);
  314. Result := True;
  315. except
  316. Result := False;
  317. end;
  318. end;
  319. function ImSetImageListSize(ImageList: TImageDataList; NewSize: LongInt):
  320. Boolean;
  321. var
  322. I, OldSize: LongInt;
  323. begin
  324. try
  325. OldSize := Length(PInternalList(ImageList).List);
  326. if NewSize < OldSize then
  327. for I := NewSize to OldSize - 1 do
  328. Imaging.FreeImage(PInternalList(ImageList).List[I]);
  329. SetLength(PInternalList(ImageList).List, NewSize);
  330. Result := True;
  331. except
  332. Result := False;
  333. end;
  334. end;
  335. function ImSetImageListElement(ImageList: TImageDataList; Index: LongInt;
  336. const InImage: TImageData): Boolean;
  337. begin
  338. try
  339. Index := ClampInt(Index, 0, Length(PInternalList(ImageList).List) - 1);
  340. ImCloneImage(InImage, PInternalList(ImageList).List[Index]);
  341. Result := True;
  342. except
  343. Result := False;
  344. end;
  345. end;
  346. function ImTestImagesInList(ImageList: TImageDataList): Boolean;
  347. var
  348. I: LongInt;
  349. Arr: TDynImageDataArray;
  350. begin
  351. Arr := nil;
  352. try
  353. Arr := PInternalList(ImageList).List;
  354. Result := True;
  355. for I := 0 to Length(Arr) - 1 do
  356. begin
  357. Result := Result and Imaging.TestImage(Arr[I]);
  358. if not Result then Break;
  359. end;
  360. except
  361. Result := False;
  362. end;
  363. end;
  364. function ImFreeImageList(var ImageList: TImageDataList): Boolean;
  365. var
  366. Int: PInternalList;
  367. I: LongInt;
  368. begin
  369. try
  370. if ImageList <> nil then
  371. begin
  372. Int := PInternalList(ImageList);
  373. for I := 0 to Length(Int.List) - 1 do
  374. Imaging.FreeImage(Int.List[I]);
  375. SetLength(Int.List, 0);
  376. Dispose(Int);
  377. ImageList := nil;
  378. end;
  379. Result := True;
  380. except
  381. Result := False;
  382. end;
  383. end;
  384. function ImLoadImageFromFile(FileName: PChar; var Image: TImageData): Boolean;
  385. begin
  386. try
  387. Result := Imaging.LoadImageFromFile(FileName, Image);
  388. except
  389. Result := False;
  390. end;
  391. end;
  392. function ImLoadImageFromMemory(Data: Pointer; Size: LongInt; var Image: TImageData): Boolean;
  393. begin
  394. try
  395. Result := Imaging.LoadImageFromMemory(Data, Size, Image);
  396. except
  397. Result := False;
  398. end;
  399. end;
  400. function ImLoadMultiImageFromFile(FileName: PChar; var ImageList: TImageDataList):
  401. Boolean;
  402. begin
  403. try
  404. ImInitImageList(0, ImageList);
  405. Result := Imaging.LoadMultiImageFromFile(FileName,
  406. PInternalList(ImageList).List);
  407. except
  408. Result := False;
  409. end;
  410. end;
  411. function ImLoadMultiImageFromMemory(Data: Pointer; Size: LongInt;
  412. var ImageList: TImageDataList): Boolean;
  413. begin
  414. try
  415. ImInitImageList(0, ImageList);
  416. Result := Imaging.LoadMultiImageFromMemory(Data, Size, PInternalList(ImageList).List);
  417. except
  418. Result := False;
  419. end;
  420. end;
  421. function ImSaveImageToFile(FileName: PChar; const Image: TImageData): Boolean;
  422. begin
  423. try
  424. Result := Imaging.SaveImageToFile(FileName, Image);
  425. except
  426. Result := False;
  427. end;
  428. end;
  429. function ImSaveImageToMemory(Ext: PChar; Data: Pointer; var Size: LongInt;
  430. const Image: TImageData): Boolean;
  431. begin
  432. try
  433. Result := Imaging.SaveImageToMemory(Ext, Data, Size, Image);
  434. except
  435. Result := False;
  436. end;
  437. end;
  438. function ImSaveMultiImageToFile(FileName: PChar;
  439. ImageList: TImageDataList): Boolean;
  440. begin
  441. try
  442. Result := Imaging.SaveMultiImageToFile(FileName,
  443. PInternalList(ImageList).List);
  444. except
  445. Result := False;
  446. end;
  447. end;
  448. function ImSaveMultiImageToMemory(Ext: PChar; Data: Pointer; Size: PLongInt;
  449. ImageList: TImageDataList): Boolean;
  450. begin
  451. try
  452. Result := Imaging.SaveMultiImageToMemory(Ext, Data, Size^,
  453. PInternalList(ImageList).List);
  454. except
  455. Result := False;
  456. end;
  457. end;
  458. function ImCloneImage(const Image: TImageData; var Clone: TImageData): Boolean;
  459. begin
  460. try
  461. Result := Imaging.CloneImage(Image, Clone);
  462. except
  463. Result := False;
  464. end;
  465. end;
  466. function ImConvertImage(var Image: TImageData; DestFormat: TImageFormat): Boolean;
  467. begin
  468. try
  469. Result := Imaging.ConvertImage(Image, DestFormat);
  470. except
  471. Result := False;
  472. end;
  473. end;
  474. function ImFlipImage(var Image: TImageData): Boolean;
  475. begin
  476. try
  477. Result := Imaging.FlipImage(Image);
  478. except
  479. Result := False;
  480. end;
  481. end;
  482. function ImMirrorImage(var Image: TImageData): Boolean;
  483. begin
  484. try
  485. Result := Imaging.MirrorImage(Image);
  486. except
  487. Result := False;
  488. end;
  489. end;
  490. function ImResizeImage(var Image: TImageData; NewWidth, NewHeight: LongInt;
  491. Filter: TResizeFilter): Boolean;
  492. begin
  493. try
  494. Result := Imaging.ResizeImage(Image, NewWidth, NewHeight, Filter);
  495. except
  496. Result := False;
  497. end;
  498. end;
  499. function ImSwapChannels(var Image: TImageData; SrcChannel, DstChannel: LongInt):
  500. Boolean;
  501. begin
  502. try
  503. Result := Imaging.SwapChannels(Image, SrcChannel, DstChannel);
  504. except
  505. Result := False;
  506. end;
  507. end;
  508. function ImReduceColors(var Image: TImageData; MaxColors: LongInt): Boolean;
  509. begin
  510. try
  511. Result := Imaging.ReduceColors(Image, MaxColors);
  512. except
  513. Result := False;
  514. end;
  515. end;
  516. function ImGenerateMipMaps(const Image: TImageData; Levels: LongInt;
  517. var MipMaps: TImageDataList): Boolean;
  518. begin
  519. try
  520. ImInitImageList(0, MipMaps);
  521. Result := Imaging.GenerateMipMaps(Image, Levels,
  522. PInternalList(MipMaps).List);
  523. except
  524. Result := False;
  525. end;
  526. end;
  527. function ImMapImageToPalette(var Image: TImageData; Pal: PPalette32;
  528. Entries: LongInt): Boolean;
  529. begin
  530. try
  531. Result := Imaging.MapImageToPalette(Image, Pal, Entries);
  532. except
  533. Result := False;
  534. end;
  535. end;
  536. function ImSplitImage(var Image: TImageData; var Chunks: TImageDataList;
  537. ChunkWidth, ChunkHeight: LongInt; var XChunks, YChunks: LongInt;
  538. PreserveSize: Boolean; Fill: Pointer): Boolean;
  539. begin
  540. try
  541. ImInitImageList(0, Chunks);
  542. Result := Imaging.SplitImage(Image, PInternalList(Chunks).List,
  543. ChunkWidth, ChunkHeight, XChunks, YChunks, PreserveSize, Fill);
  544. except
  545. Result := False;
  546. end;
  547. end;
  548. function ImMakePaletteForImages(Images: TImageDataList; Pal: PPalette32;
  549. MaxColors: LongInt; ConvertImages: Boolean): Boolean;
  550. begin
  551. try
  552. Result := Imaging.MakePaletteForImages(PInternalList(Images).List,
  553. Pal, MaxColors, ConvertImages);
  554. except
  555. Result := False;
  556. end;
  557. end;
  558. function ImRotateImage(var Image: TImageData; Angle: LongInt): Boolean;
  559. begin
  560. try
  561. Result := Imaging.RotateImage(Image, Angle);
  562. except
  563. Result := False;
  564. end;
  565. end;
  566. function ImCopyRect(const SrcImage: TImageData; SrcX, SrcY, Width, Height: LongInt;
  567. var DstImage: TImageData; DstX, DstY: LongInt): Boolean; cdecl;
  568. begin
  569. try
  570. Result := Imaging.CopyRect(SrcImage, SrcX, SrcY, Width, Height,
  571. DstImage, DstX, DstY);
  572. except
  573. Result := False;
  574. end;
  575. end;
  576. function ImFillRect(var Image: TImageData; X, Y, Width, Height: LongInt;
  577. Fill: Pointer): Boolean;
  578. begin
  579. try
  580. Result := Imaging.FillRect(Image, X, Y, Width, Height, Fill);
  581. except
  582. Result := False;
  583. end;
  584. end;
  585. function ImReplaceColor(var Image: TImageData; X, Y, Width, Height: LongInt;
  586. OldPixel, NewPixel: Pointer): Boolean;
  587. begin
  588. try
  589. Result := Imaging.ReplaceColor(Image, X, Y, Width, Height, OldPixel, NewPixel);
  590. except
  591. Result := False;
  592. end;
  593. end;
  594. function ImStretchRect(const SrcImage: TImageData; SrcX, SrcY, SrcWidth,
  595. SrcHeight: LongInt; var DstImage: TImageData; DstX, DstY, DstWidth,
  596. DstHeight: LongInt; Filter: TResizeFilter): Boolean; cdecl;
  597. begin
  598. try
  599. Result := Imaging.StretchRect(SrcImage, SrcX, SrcY, SrcWidth, SrcHeight,
  600. DstImage, DstX, DstY, DstWidth, DstHeight, Filter);
  601. except
  602. Result := False;
  603. end;
  604. end;
  605. procedure ImGetPixelDirect(const Image: TImageData; X, Y: LongInt; Pixel: Pointer);
  606. begin
  607. try
  608. Imaging.GetPixelDirect(Image, X, Y, Pixel);
  609. except
  610. end;
  611. end;
  612. procedure ImSetPixelDirect(const Image: TImageData; X, Y: LongInt; Pixel: Pointer);
  613. begin
  614. try
  615. Imaging.SetPixelDirect(Image, X, Y, Pixel);
  616. except
  617. end;
  618. end;
  619. function ImGetPixel32(const Image: TImageData; X, Y: LongInt): TColor32Rec; cdecl;
  620. begin
  621. try
  622. Result := Imaging.GetPixel32(Image, X, Y);
  623. except
  624. Result.Color := 0;
  625. end;
  626. end;
  627. procedure ImSetPixel32(const Image: TImageData; X, Y: LongInt; const Color: TColor32Rec);
  628. begin
  629. try
  630. Imaging.SetPixel32(Image, X, Y, Color);
  631. except
  632. end;
  633. end;
  634. function ImGetPixelFP(const Image: TImageData; X, Y: LongInt): TColorFPRec; cdecl;
  635. begin
  636. try
  637. Result := Imaging.GetPixelFP(Image, X, Y);
  638. except
  639. FillChar(Result, SizeOf(Result), 0);
  640. end;
  641. end;
  642. procedure ImSetPixelFP(const Image: TImageData; X, Y: LongInt; const Color: TColorFPRec);
  643. begin
  644. try
  645. Imaging.SetPixelFP(Image, X, Y, Color);
  646. except
  647. end;
  648. end;
  649. function ImNewPalette(Entries: LongInt; var Pal: PPalette32): Boolean;
  650. begin
  651. try
  652. Result := Imaging.NewPalette(Entries, Pal);
  653. except
  654. Result := False;
  655. end;
  656. end;
  657. function ImFreePalette(var Pal: PPalette32): Boolean;
  658. begin
  659. try
  660. Result := Imaging.FreePalette(Pal);
  661. except
  662. Result := False;
  663. end;
  664. end;
  665. function ImCopyPalette(SrcPal, DstPal: PPalette32; SrcIdx, DstIdx, Count: LongInt): Boolean;
  666. begin
  667. try
  668. Result := Imaging.CopyPalette(SrcPal, DstPal, SrcIdx, DstIdx, Count);
  669. except
  670. Result := False;
  671. end;
  672. end;
  673. function ImFindColor(Pal: PPalette32; Entries: LongInt; Color: TColor32): LongInt;
  674. begin
  675. try
  676. Result := Imaging.FindColor(Pal, Entries, Color);
  677. except
  678. Result := 0;
  679. end;
  680. end;
  681. function ImFillGrayscalePalette(Pal: PPalette32; Entries: LongInt): Boolean;
  682. begin
  683. try
  684. Result := Imaging.FillGrayscalePalette(Pal, Entries);
  685. except
  686. Result := False;
  687. end;
  688. end;
  689. function ImFillCustomPalette(Pal: PPalette32; Entries: LongInt; RBits, GBits,
  690. BBits: Byte; Alpha: Byte): Boolean;
  691. begin
  692. try
  693. Result := Imaging.FillCustomPalette(Pal, Entries, RBits, GBits, BBits,
  694. Alpha);
  695. except
  696. Result := False;
  697. end;
  698. end;
  699. function ImSwapChannelsOfPalette(Pal: PPalette32; Entries, SrcChannel,
  700. DstChannel: LongInt): Boolean;
  701. begin
  702. try
  703. Result := Imaging.SwapChannelsOfPalette(Pal, Entries, SrcChannel, DstChannel);
  704. except
  705. Result := False;
  706. end;
  707. end;
  708. function ImSetOption(OptionId, Value: LongInt): Boolean;
  709. begin
  710. try
  711. Result := Imaging.SetOption(OptionId, Value);
  712. except
  713. Result := False;
  714. end;
  715. end;
  716. function ImGetOption(OptionId: LongInt): LongInt;
  717. begin
  718. try
  719. Result := GetOption(OptionId);
  720. except
  721. Result := InvalidOption;
  722. end;
  723. end;
  724. function ImPushOptions: Boolean;
  725. begin
  726. try
  727. Result := Imaging.PushOptions;
  728. except
  729. Result := False;
  730. end;
  731. end;
  732. function ImPopOptions: Boolean;
  733. begin
  734. try
  735. Result := Imaging.PopOptions;
  736. except
  737. Result := False;
  738. end;
  739. end;
  740. function ImGetImageFormatInfo(Format: TImageFormat; var Info: TImageFormatInfo): Boolean;
  741. begin
  742. try
  743. Result := Imaging.GetImageFormatInfo(Format, Info);
  744. except
  745. Result := False;
  746. end;
  747. end;
  748. function ImGetPixelsSize(Format: TImageFormat; Width, Height: LongInt): LongInt;
  749. begin
  750. try
  751. Result := Imaging.GetPixelsSize(Format, Width, Height);
  752. except
  753. Result := 0;
  754. end;
  755. end;
  756. procedure ImSetUserFileIO(OpenReadProc: TOpenReadProc; OpenWriteProc:
  757. TOpenWriteProc; CloseProc: TCloseProc; EofProc: TEofProc; SeekProc: TSeekProc;
  758. TellProc: TTellProc; ReadProc: TReadProc; WriteProc: TWriteProc);
  759. begin
  760. try
  761. Imaging.SetUserFileIO(OpenReadProc, OpenWriteProc, CloseProc, EofProc,
  762. SeekProc, TellProc, ReadProc, WriteProc);
  763. except
  764. end;
  765. end;
  766. procedure ImResetFileIO;
  767. begin
  768. try
  769. Imaging.ResetFileIO;
  770. except
  771. end;
  772. end;
  773. {
  774. Changes/Bug Fixes:
  775. -- TODOS ----------------------------------------------------
  776. - nothing now
  777. -- 0.19 -----------------------------------------------------
  778. - updated to reflect changes in low level interface (added pixel set/get, ...)
  779. - changed ImInitImage to procedure to reflect change in Imaging.pas
  780. - added ImIsFileFormatSupported
  781. -- 0.15 -----------------------------------------------------
  782. - behaviour of ImGetImageListElement and ImSetImageListElement
  783. has changed - list items are now cloned rather than referenced,
  784. because of this ImFreeImageListKeepImages was no longer needed
  785. and was removed
  786. - many function headers were changed - mainly pointers were
  787. replaced with var and const parameters
  788. -- 0.13 -----------------------------------------------------
  789. - added TestImagesInList function and new 0.13 functions
  790. - images were not freed when image list was resized in ImSetImageListSize
  791. - ImSaveMultiImageTo* recreated the input image list with size = 0
  792. }
  793. end.