ImagingExport.pas 26 KB

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