ImagingExport.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  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. Imaging.FreeImage(Image);
  231. Result := True;
  232. except
  233. Result := False;
  234. end;
  235. end;
  236. function ImDetermineFileFormat(FileName, Ext: PChar): Boolean;
  237. var
  238. S: string;
  239. begin
  240. try
  241. S := Imaging.DetermineFileFormat(FileName);
  242. Result := S <> '';
  243. StrCopy(Ext, PChar(S));
  244. except
  245. Result := False;
  246. end;
  247. end;
  248. function ImDetermineMemoryFormat(Data: Pointer; Size: LongInt; Ext: PChar): Boolean;
  249. var
  250. S: string;
  251. begin
  252. try
  253. S := Imaging.DetermineMemoryFormat(Data, Size);
  254. Result := S <> '';
  255. StrCopy(Ext, PChar(S));
  256. except
  257. Result := False;
  258. end;
  259. end;
  260. function ImIsFileFormatSupported(FileName: PChar): Boolean;
  261. begin
  262. try
  263. Result := Imaging.IsFileFormatSupported(FileName);
  264. except
  265. Result := False;
  266. end;
  267. end;
  268. function ImEnumFileFormats(var Index: LongInt; Name, DefaultExt, Masks: PChar;
  269. var CanSave, IsMultiImageFormat: Boolean): Boolean;
  270. var
  271. StrName, StrDefaultExt, StrMasks: string;
  272. begin
  273. try
  274. Result := Imaging.EnumFileFormats(Index, StrName, StrDefaultExt, StrMasks, CanSave,
  275. IsMultiImageFormat);
  276. StrCopy(Name, PChar(StrName));
  277. StrCopy(DefaultExt, PChar(StrDefaultExt));
  278. StrCopy(Masks, PChar(StrMasks));
  279. except
  280. Result := False;
  281. end;
  282. end;
  283. function ImInitImageList(Size: LongInt; var ImageList: TImageDataList): Boolean;
  284. var
  285. Int: PInternalList;
  286. begin
  287. try
  288. try
  289. ImFreeImageList(ImageList);
  290. except
  291. end;
  292. New(Int);
  293. SetLength(Int.List, Size);
  294. ImageList := TImageDataList(Int);
  295. Result := True;
  296. except
  297. Result := False;
  298. ImageList := nil;
  299. end;
  300. end;
  301. function ImGetImageListSize(ImageList: TImageDataList): LongInt;
  302. begin
  303. try
  304. Result := Length(PInternalList(ImageList).List);
  305. except
  306. Result := -1;
  307. end;
  308. end;
  309. function ImGetImageListElement(ImageList: TImageDataList; Index: LongInt;
  310. var OutImage: TImageData): Boolean;
  311. begin
  312. try
  313. Index := ClampInt(Index, 0, Length(PInternalList(ImageList).List) - 1);
  314. ImCloneImage(PInternalList(ImageList).List[Index], OutImage);
  315. Result := True;
  316. except
  317. Result := False;
  318. end;
  319. end;
  320. function ImSetImageListSize(ImageList: TImageDataList; NewSize: LongInt):
  321. Boolean;
  322. var
  323. I, OldSize: LongInt;
  324. begin
  325. try
  326. OldSize := Length(PInternalList(ImageList).List);
  327. if NewSize < OldSize then
  328. for I := NewSize to OldSize - 1 do
  329. Imaging.FreeImage(PInternalList(ImageList).List[I]);
  330. SetLength(PInternalList(ImageList).List, NewSize);
  331. Result := True;
  332. except
  333. Result := False;
  334. end;
  335. end;
  336. function ImSetImageListElement(ImageList: TImageDataList; Index: LongInt;
  337. const InImage: TImageData): Boolean;
  338. begin
  339. try
  340. Index := ClampInt(Index, 0, Length(PInternalList(ImageList).List) - 1);
  341. ImCloneImage(InImage, PInternalList(ImageList).List[Index]);
  342. Result := True;
  343. except
  344. Result := False;
  345. end;
  346. end;
  347. function ImTestImagesInList(ImageList: TImageDataList): Boolean;
  348. var
  349. I: LongInt;
  350. Arr: TDynImageDataArray;
  351. begin
  352. Arr := nil;
  353. try
  354. Arr := PInternalList(ImageList).List;
  355. Result := True;
  356. for I := 0 to Length(Arr) - 1 do
  357. begin
  358. Result := Result and Imaging.TestImage(Arr[I]);
  359. if not Result then Break;
  360. end;
  361. except
  362. Result := False;
  363. end;
  364. end;
  365. function ImFreeImageList(var ImageList: TImageDataList): Boolean;
  366. var
  367. Int: PInternalList;
  368. begin
  369. try
  370. if ImageList <> nil then
  371. begin
  372. Int := PInternalList(ImageList);
  373. FreeImagesInArray(Int.List);
  374. Dispose(Int);
  375. ImageList := nil;
  376. end;
  377. Result := True;
  378. except
  379. Result := False;
  380. end;
  381. end;
  382. function ImLoadImageFromFile(FileName: PChar; var Image: TImageData): Boolean;
  383. begin
  384. try
  385. Result := Imaging.LoadImageFromFile(FileName, Image);
  386. except
  387. Result := False;
  388. end;
  389. end;
  390. function ImLoadImageFromMemory(Data: Pointer; Size: LongInt; var Image: TImageData): Boolean;
  391. begin
  392. try
  393. Result := Imaging.LoadImageFromMemory(Data, Size, Image);
  394. except
  395. Result := False;
  396. end;
  397. end;
  398. function ImLoadMultiImageFromFile(FileName: PChar; var ImageList: TImageDataList):
  399. Boolean;
  400. begin
  401. try
  402. ImInitImageList(0, ImageList);
  403. Result := Imaging.LoadMultiImageFromFile(FileName,
  404. PInternalList(ImageList).List);
  405. except
  406. Result := False;
  407. end;
  408. end;
  409. function ImLoadMultiImageFromMemory(Data: Pointer; Size: LongInt;
  410. var ImageList: TImageDataList): Boolean;
  411. begin
  412. try
  413. ImInitImageList(0, ImageList);
  414. Result := Imaging.LoadMultiImageFromMemory(Data, Size, PInternalList(ImageList).List);
  415. except
  416. Result := False;
  417. end;
  418. end;
  419. function ImSaveImageToFile(FileName: PChar; const Image: TImageData): Boolean;
  420. begin
  421. try
  422. Result := Imaging.SaveImageToFile(FileName, Image);
  423. except
  424. Result := False;
  425. end;
  426. end;
  427. function ImSaveImageToMemory(Ext: PChar; Data: Pointer; var Size: LongInt;
  428. const Image: TImageData): Boolean;
  429. begin
  430. try
  431. Result := Imaging.SaveImageToMemory(Ext, Data, Size, Image);
  432. except
  433. Result := False;
  434. end;
  435. end;
  436. function ImSaveMultiImageToFile(FileName: PChar;
  437. ImageList: TImageDataList): Boolean;
  438. begin
  439. try
  440. Result := Imaging.SaveMultiImageToFile(FileName,
  441. PInternalList(ImageList).List);
  442. except
  443. Result := False;
  444. end;
  445. end;
  446. function ImSaveMultiImageToMemory(Ext: PChar; Data: Pointer; Size: PLongInt;
  447. ImageList: TImageDataList): Boolean;
  448. begin
  449. try
  450. Result := Imaging.SaveMultiImageToMemory(Ext, Data, Size^,
  451. PInternalList(ImageList).List);
  452. except
  453. Result := False;
  454. end;
  455. end;
  456. function ImCloneImage(const Image: TImageData; var Clone: TImageData): Boolean;
  457. begin
  458. try
  459. Result := Imaging.CloneImage(Image, Clone);
  460. except
  461. Result := False;
  462. end;
  463. end;
  464. function ImConvertImage(var Image: TImageData; DestFormat: TImageFormat): Boolean;
  465. begin
  466. try
  467. Result := Imaging.ConvertImage(Image, DestFormat);
  468. except
  469. Result := False;
  470. end;
  471. end;
  472. function ImFlipImage(var Image: TImageData): Boolean;
  473. begin
  474. try
  475. Result := Imaging.FlipImage(Image);
  476. except
  477. Result := False;
  478. end;
  479. end;
  480. function ImMirrorImage(var Image: TImageData): Boolean;
  481. begin
  482. try
  483. Result := Imaging.MirrorImage(Image);
  484. except
  485. Result := False;
  486. end;
  487. end;
  488. function ImResizeImage(var Image: TImageData; NewWidth, NewHeight: LongInt;
  489. Filter: TResizeFilter): Boolean;
  490. begin
  491. try
  492. Result := Imaging.ResizeImage(Image, NewWidth, NewHeight, Filter);
  493. except
  494. Result := False;
  495. end;
  496. end;
  497. function ImSwapChannels(var Image: TImageData; SrcChannel, DstChannel: LongInt):
  498. Boolean;
  499. begin
  500. try
  501. Result := Imaging.SwapChannels(Image, SrcChannel, DstChannel);
  502. except
  503. Result := False;
  504. end;
  505. end;
  506. function ImReduceColors(var Image: TImageData; MaxColors: LongInt): Boolean;
  507. begin
  508. try
  509. Result := Imaging.ReduceColors(Image, MaxColors);
  510. except
  511. Result := False;
  512. end;
  513. end;
  514. function ImGenerateMipMaps(const Image: TImageData; Levels: LongInt;
  515. var MipMaps: TImageDataList): Boolean;
  516. begin
  517. try
  518. ImInitImageList(0, MipMaps);
  519. Result := Imaging.GenerateMipMaps(Image, Levels,
  520. PInternalList(MipMaps).List);
  521. except
  522. Result := False;
  523. end;
  524. end;
  525. function ImMapImageToPalette(var Image: TImageData; Pal: PPalette32;
  526. Entries: LongInt): Boolean;
  527. begin
  528. try
  529. Result := Imaging.MapImageToPalette(Image, Pal, Entries);
  530. except
  531. Result := False;
  532. end;
  533. end;
  534. function ImSplitImage(var Image: TImageData; var Chunks: TImageDataList;
  535. ChunkWidth, ChunkHeight: LongInt; var XChunks, YChunks: LongInt;
  536. PreserveSize: Boolean; Fill: Pointer): Boolean;
  537. begin
  538. try
  539. ImInitImageList(0, Chunks);
  540. Result := Imaging.SplitImage(Image, PInternalList(Chunks).List,
  541. ChunkWidth, ChunkHeight, XChunks, YChunks, PreserveSize, Fill);
  542. except
  543. Result := False;
  544. end;
  545. end;
  546. function ImMakePaletteForImages(Images: TImageDataList; Pal: PPalette32;
  547. MaxColors: LongInt; ConvertImages: Boolean): Boolean;
  548. begin
  549. try
  550. Result := Imaging.MakePaletteForImages(PInternalList(Images).List,
  551. Pal, MaxColors, ConvertImages);
  552. except
  553. Result := False;
  554. end;
  555. end;
  556. function ImRotateImage(var Image: TImageData; Angle: LongInt): Boolean;
  557. begin
  558. try
  559. Result := Imaging.RotateImage(Image, Angle);
  560. except
  561. Result := False;
  562. end;
  563. end;
  564. function ImCopyRect(const SrcImage: TImageData; SrcX, SrcY, Width, Height: LongInt;
  565. var DstImage: TImageData; DstX, DstY: LongInt): Boolean; cdecl;
  566. begin
  567. try
  568. Result := Imaging.CopyRect(SrcImage, SrcX, SrcY, Width, Height,
  569. DstImage, DstX, DstY);
  570. except
  571. Result := False;
  572. end;
  573. end;
  574. function ImFillRect(var Image: TImageData; X, Y, Width, Height: LongInt;
  575. Fill: Pointer): Boolean;
  576. begin
  577. try
  578. Result := Imaging.FillRect(Image, X, Y, Width, Height, Fill);
  579. except
  580. Result := False;
  581. end;
  582. end;
  583. function ImReplaceColor(var Image: TImageData; X, Y, Width, Height: LongInt;
  584. OldPixel, NewPixel: Pointer): Boolean;
  585. begin
  586. try
  587. Result := Imaging.ReplaceColor(Image, X, Y, Width, Height, OldPixel, NewPixel);
  588. except
  589. Result := False;
  590. end;
  591. end;
  592. function ImStretchRect(const SrcImage: TImageData; SrcX, SrcY, SrcWidth,
  593. SrcHeight: LongInt; var DstImage: TImageData; DstX, DstY, DstWidth,
  594. DstHeight: LongInt; Filter: TResizeFilter): Boolean; cdecl;
  595. begin
  596. try
  597. Result := Imaging.StretchRect(SrcImage, SrcX, SrcY, SrcWidth, SrcHeight,
  598. DstImage, DstX, DstY, DstWidth, DstHeight, Filter);
  599. except
  600. Result := False;
  601. end;
  602. end;
  603. procedure ImGetPixelDirect(const Image: TImageData; X, Y: LongInt; Pixel: Pointer);
  604. begin
  605. try
  606. Imaging.GetPixelDirect(Image, X, Y, Pixel);
  607. except
  608. end;
  609. end;
  610. procedure ImSetPixelDirect(const Image: TImageData; X, Y: LongInt; Pixel: Pointer);
  611. begin
  612. try
  613. Imaging.SetPixelDirect(Image, X, Y, Pixel);
  614. except
  615. end;
  616. end;
  617. function ImGetPixel32(const Image: TImageData; X, Y: LongInt): TColor32Rec; cdecl;
  618. begin
  619. try
  620. Result := Imaging.GetPixel32(Image, X, Y);
  621. except
  622. Result.Color := 0;
  623. end;
  624. end;
  625. procedure ImSetPixel32(const Image: TImageData; X, Y: LongInt; const Color: TColor32Rec);
  626. begin
  627. try
  628. Imaging.SetPixel32(Image, X, Y, Color);
  629. except
  630. end;
  631. end;
  632. function ImGetPixelFP(const Image: TImageData; X, Y: LongInt): TColorFPRec; cdecl;
  633. begin
  634. try
  635. Result := Imaging.GetPixelFP(Image, X, Y);
  636. except
  637. FillChar(Result, SizeOf(Result), 0);
  638. end;
  639. end;
  640. procedure ImSetPixelFP(const Image: TImageData; X, Y: LongInt; const Color: TColorFPRec);
  641. begin
  642. try
  643. Imaging.SetPixelFP(Image, X, Y, Color);
  644. except
  645. end;
  646. end;
  647. function ImNewPalette(Entries: LongInt; var Pal: PPalette32): Boolean;
  648. begin
  649. try
  650. Imaging.NewPalette(Entries, Pal);
  651. Result := True;
  652. except
  653. Result := False;
  654. end;
  655. end;
  656. function ImFreePalette(var Pal: PPalette32): Boolean;
  657. begin
  658. try
  659. Imaging.FreePalette(Pal);
  660. Result := True;
  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. Imaging.CopyPalette(SrcPal, DstPal, SrcIdx, DstIdx, Count);
  669. Result := True;
  670. except
  671. Result := False;
  672. end;
  673. end;
  674. function ImFindColor(Pal: PPalette32; Entries: LongInt; Color: TColor32): LongInt;
  675. begin
  676. try
  677. Result := Imaging.FindColor(Pal, Entries, Color);
  678. except
  679. Result := 0;
  680. end;
  681. end;
  682. function ImFillGrayscalePalette(Pal: PPalette32; Entries: LongInt): Boolean;
  683. begin
  684. try
  685. Imaging.FillGrayscalePalette(Pal, Entries);
  686. Result := True;
  687. except
  688. Result := False;
  689. end;
  690. end;
  691. function ImFillCustomPalette(Pal: PPalette32; Entries: LongInt; RBits, GBits,
  692. BBits: Byte; Alpha: Byte): Boolean;
  693. begin
  694. try
  695. Imaging.FillCustomPalette(Pal, Entries, RBits, GBits, BBits, Alpha);
  696. Result := True;
  697. except
  698. Result := False;
  699. end;
  700. end;
  701. function ImSwapChannelsOfPalette(Pal: PPalette32; Entries, SrcChannel,
  702. DstChannel: LongInt): Boolean;
  703. begin
  704. try
  705. Imaging.SwapChannelsOfPalette(Pal, Entries, SrcChannel, DstChannel);
  706. Result := True;
  707. except
  708. Result := False;
  709. end;
  710. end;
  711. function ImSetOption(OptionId, Value: LongInt): Boolean;
  712. begin
  713. try
  714. Result := Imaging.SetOption(OptionId, Value);
  715. except
  716. Result := False;
  717. end;
  718. end;
  719. function ImGetOption(OptionId: LongInt): LongInt;
  720. begin
  721. try
  722. Result := GetOption(OptionId);
  723. except
  724. Result := InvalidOption;
  725. end;
  726. end;
  727. function ImPushOptions: Boolean;
  728. begin
  729. try
  730. Result := Imaging.PushOptions;
  731. except
  732. Result := False;
  733. end;
  734. end;
  735. function ImPopOptions: Boolean;
  736. begin
  737. try
  738. Result := Imaging.PopOptions;
  739. except
  740. Result := False;
  741. end;
  742. end;
  743. function ImGetImageFormatInfo(Format: TImageFormat; var Info: TImageFormatInfo): Boolean;
  744. begin
  745. try
  746. Result := Imaging.GetImageFormatInfo(Format, Info);
  747. except
  748. Result := False;
  749. end;
  750. end;
  751. function ImGetPixelsSize(Format: TImageFormat; Width, Height: LongInt): LongInt;
  752. begin
  753. try
  754. Result := Imaging.GetPixelsSize(Format, Width, Height);
  755. except
  756. Result := 0;
  757. end;
  758. end;
  759. procedure ImSetUserFileIO(OpenReadProc: TOpenReadProc; OpenWriteProc:
  760. TOpenWriteProc; CloseProc: TCloseProc; EofProc: TEofProc; SeekProc: TSeekProc;
  761. TellProc: TTellProc; ReadProc: TReadProc; WriteProc: TWriteProc);
  762. begin
  763. try
  764. Imaging.SetUserFileIO(OpenReadProc, OpenWriteProc, CloseProc, EofProc,
  765. SeekProc, TellProc, ReadProc, WriteProc);
  766. except
  767. end;
  768. end;
  769. procedure ImResetFileIO;
  770. begin
  771. try
  772. Imaging.ResetFileIO;
  773. except
  774. end;
  775. end;
  776. {
  777. Changes/Bug Fixes:
  778. -- TODOS ----------------------------------------------------
  779. - nothing now
  780. -- 0.19 -----------------------------------------------------
  781. - updated to reflect changes in low level interface (added pixel set/get, ...)
  782. - changed ImInitImage to procedure to reflect change in Imaging.pas
  783. - added ImIsFileFormatSupported
  784. -- 0.15 -----------------------------------------------------
  785. - behaviour of ImGetImageListElement and ImSetImageListElement
  786. has changed - list items are now cloned rather than referenced,
  787. because of this ImFreeImageListKeepImages was no longer needed
  788. and was removed
  789. - many function headers were changed - mainly pointers were
  790. replaced with var and const parameters
  791. -- 0.13 -----------------------------------------------------
  792. - added TestImagesInList function and new 0.13 functions
  793. - images were not freed when image list was resized in ImSetImageListSize
  794. - ImSaveMultiImageTo* recreated the input image list with size = 0
  795. }
  796. end.