ImagingExport.pas 25 KB

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