You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

497 lines
21 KiB

  1. unit ultsImage;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,
  6. utsTextSuite,
  7. ultsTypes;
  8. type
  9. TltsImageLoadFunc = procedure(aHandle: TltsImageHandle; X, Y: Integer; var aPixel: TtsColor4f; aArgs: Pointer); stdcall;
  10. TltsImageBlendFunc = procedure(aHandle: TltsImageHandle; aSrc, aDst: TtsColor4f; out aResult: TtsColor4f; aArgs: Pointer); stdcall;
  11. function ltsImageCreate (aContext: TltsContextHandle): TltsImageHandle; stdcall;
  12. function ltsImageIsEmpty (aHandle: TltsImageHandle; out aValue: Boolean): TltsErrorCode; stdcall;
  13. function ltsImageGetWidth (aHandle: TltsImageHandle): Integer; stdcall;
  14. function ltsImageGetHeight (aHandle: TltsImageHandle): Integer; stdcall;
  15. function ltsImageGetLineSize (aHandle: TltsImageHandle): Integer; stdcall;
  16. function ltsImageGetDataSize (aHandle: TltsImageHandle): Integer; stdcall;
  17. function ltsImageGetFormat (aHandle: TltsImageHandle; out aValue: TtsFormat): TltsErrorCode; stdcall;
  18. function ltsImageGetData (aHandle: TltsImageHandle): Pointer; stdcall;
  19. function ltsImageGetScanline (aHandle: TltsImageHandle; aIndex: Integer): Pointer; stdcall;
  20. function ltsImageGetPixelAt (aHandle: TltsImageHandle; aX, aY: Integer; out aColor: TtsColor4f): TltsErrorCode; stdcall;
  21. function ltsImageAssign (aHandle, aSource: TltsImageHandle): TltsErrorCode; stdcall;
  22. function ltsImageCreateEmpty (aHandle: TltsImageHandle; aFormat: TtsFormat; aWidth, aHeight: Integer): TltsErrorCode; stdcall;
  23. function ltsImageLoadFromFunc (aHandle: TltsImageHandle; aCallback: TltsImageLoadFunc; aArgs: Pointer): TltsErrorCode; stdcall;
  24. function ltsImageResize (aHandle: TltsImageHandle; aWidth, aHeight, aX, aY: Integer): TltsErrorCode; stdcall;
  25. function ltsImageFillColor (aHandle: TltsImageHandle; aColor: TtsColor4f; aMask: TtsColorChannels; aModes: TtsImageModes): TltsErrorCode; stdcall;
  26. function ltsImageFillPattern (aHandle, aPattern: TltsImageHandle; aX, aY: Integer; aMask: TtsColorChannels; aModes: TtsImageModes): TltsErrorCode; stdcall;
  27. function ltsImageBlend (aHandle, aSource: TltsImageHandle; aX, aY: Integer; aBlendFunc: TltsImageBlendFunc; aArgs: Pointer): TltsErrorCode; stdcall;
  28. function ltsImageBlur (aHandle: TltsImageHandle; aHorzRad, aHorzStr, aVertRad, aVertStr: Single; aMask: TtsColorChannels): TltsErrorCode; stdcall;
  29. function ltsImageDestroy (aHandle: TltsImageHandle): TltsErrorCode; stdcall;
  30. implementation
  31. uses
  32. ultsUtils, utsUtils {$IFDEF DEBUG}, uutlLogger{$ENDIF};
  33. type
  34. PLoadArgs = ^TLoadArgs;
  35. TLoadArgs = packed record
  36. args: Pointer;
  37. handle: TltsImageHandle;
  38. callback: TltsImageLoadFunc
  39. end;
  40. PBlendArgs = ^TBlendArgs;
  41. TBlendArgs = packed record
  42. args: Pointer;
  43. handle: TltsImageHandle;
  44. callback: TltsImageBlendFunc;
  45. end;
  46. procedure ImageLoadCallback(const aImage: TtsImage; X, Y: Integer; var aPixel: TtsColor4f; aArgs: Pointer);
  47. var
  48. p: PLoadArgs;
  49. begin
  50. p := PLoadArgs(aArgs);
  51. p^.callback(p^.handle, X, Y, aPixel, p^.args);
  52. end;
  53. function ImageBlendCallback(const aSrc, aDst: TtsColor4f; aArgs: Pointer): TtsColor4f;
  54. var
  55. p: PBlendArgs;
  56. begin
  57. p := PBlendArgs(aArgs);
  58. p^.callback(p^.handle, aSrc, aDst, result, p^.args);
  59. end;
  60. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  61. //ltsImage//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  62. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  63. function ltsImageCreate(aContext: TltsContextHandle): TltsImageHandle; stdcall;
  64. var
  65. img: TtsImage;
  66. c: TtsContext;
  67. begin
  68. try
  69. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageCreate(Context=%p)', [Pointer(aContext)]);{$ENDIF}
  70. result := nil;
  71. if not CheckContextHandle(aContext, c) then
  72. exit;
  73. img := TtsImage.Create(c);
  74. AddReference(ltsObjTypeImage, img);
  75. result := img;
  76. except
  77. on ex: Exception do begin
  78. SetLastError(ex);
  79. result := nil;
  80. end;
  81. end;
  82. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageCreate=%p', [Pointer(result)]);{$ENDIF}
  83. end;
  84. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  85. function ltsImageIsEmpty(aHandle: TltsImageHandle; out aValue: Boolean): TltsErrorCode; stdcall;
  86. var
  87. img: TtsImage;
  88. begin
  89. try
  90. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageIsEmpty(Handle=%p; Value=%p)', [Pointer(aHandle), Pointer(@aValue)]);{$ENDIF}
  91. result := ltsErrNone;
  92. if CheckImageHandle(aHandle, img)
  93. then aValue := img.IsEmpty
  94. else result := LastErrorCode;
  95. except
  96. on ex: Exception do begin
  97. SetLastError(ex);
  98. result := LastErrorCode;
  99. end;
  100. end;
  101. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageIsEmpty=%d', [Integer(result)]);{$ENDIF}
  102. end;
  103. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  104. function ltsImageGetWidth(aHandle: TltsImageHandle): Integer; stdcall;
  105. var
  106. img: TtsImage;
  107. begin
  108. try
  109. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetWidth(Handle=%p)', [Pointer(aHandle)]);{$ENDIF}
  110. if CheckImageHandle(aHandle, img)
  111. then result := img.Width
  112. else result := -1;
  113. except
  114. on ex: Exception do begin
  115. SetLastError(ex);
  116. result := -1;
  117. end;
  118. end;
  119. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetWidth=%d', [Integer(result)]);{$ENDIF}
  120. end;
  121. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  122. function ltsImageGetHeight(aHandle: TltsImageHandle): Integer; stdcall;
  123. var
  124. img: TtsImage;
  125. begin
  126. try
  127. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetHeight(Handle=%p)', [Pointer(aHandle)]);{$ENDIF}
  128. if CheckImageHandle(aHandle, img)
  129. then result := img.Height
  130. else result := -1;
  131. except
  132. on ex: Exception do begin
  133. SetLastError(ex);
  134. result := -1;
  135. end;
  136. end;
  137. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetHeight=%d', [Integer(result)]);{$ENDIF}
  138. end;
  139. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  140. function ltsImageGetLineSize(aHandle: TltsImageHandle): Integer; stdcall;
  141. var
  142. img: TtsImage;
  143. begin
  144. try
  145. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetLineSize(Handle=%p)', [Pointer(aHandle)]);{$ENDIF}
  146. if CheckImageHandle(aHandle, img)
  147. then result := img.LineSize
  148. else result := -1;
  149. except
  150. on ex: Exception do begin
  151. SetLastError(ex);
  152. result := -1;
  153. end;
  154. end;
  155. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetLineSize=%d', [Integer(result)]);{$ENDIF}
  156. end;
  157. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  158. function ltsImageGetDataSize(aHandle: TltsImageHandle): Integer; stdcall;
  159. var
  160. img: TtsImage;
  161. begin
  162. try
  163. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetDataSize(Handle=%p)', [Pointer(aHandle)]);{$ENDIF}
  164. if CheckImageHandle(aHandle, img)
  165. then result := img.DataSize
  166. else result := -1;
  167. except
  168. on ex: Exception do begin
  169. SetLastError(ex);
  170. result := -1;
  171. end;
  172. end;
  173. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetDataSize=%d', [Integer(result)]);{$ENDIF}
  174. end;
  175. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  176. function ltsImageGetFormat(aHandle: TltsImageHandle; out aValue: TtsFormat): TltsErrorCode; stdcall;
  177. var
  178. img: TtsImage;
  179. begin
  180. try
  181. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetFormat(Handle=%p; Value=%p)', [Pointer(aHandle), Pointer(@aValue)]);{$ENDIF}
  182. result := ltsErrNone;
  183. if CheckImageHandle(aHandle, img)
  184. then aValue := img.Format
  185. else result := LastErrorCode;
  186. except
  187. on ex: Exception do begin
  188. SetLastError(ex);
  189. result := LastErrorCode;
  190. end;
  191. end;
  192. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetFormat=%d', [Integer(result)]);{$ENDIF}
  193. end;
  194. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  195. function ltsImageGetData(aHandle: TltsImageHandle): Pointer; stdcall;
  196. var
  197. img: TtsImage;
  198. begin
  199. try
  200. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetData(Handle=%p)', [Pointer(aHandle)]);{$ENDIF}
  201. if CheckImageHandle(aHandle, img)
  202. then result := img.Data
  203. else result := nil;
  204. except
  205. on ex: Exception do begin
  206. SetLastError(ex);
  207. result := nil;
  208. end;
  209. end;
  210. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetData=%p', [Pointer(result)]);{$ENDIF}
  211. end;
  212. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  213. function ltsImageGetScanline(aHandle: TltsImageHandle; aIndex: Integer): Pointer; stdcall;
  214. var
  215. img: TtsImage;
  216. begin
  217. try
  218. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetScanline(Handle=%p; Index=%d)', [Pointer(aHandle), aIndex]);{$ENDIF}
  219. if CheckImageHandle(aHandle, img) then begin
  220. result := img.Scanline[aIndex];
  221. if not Assigned(result) then
  222. SetLastError(ltsErrInvalidValue, Format('index (%d) is out of range', [aIndex]));
  223. end else
  224. result := nil;
  225. except
  226. on ex: Exception do begin
  227. SetLastError(ex);
  228. result := nil;
  229. end;
  230. end;
  231. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetScanline=%p', [Pointer(result)]);{$ENDIF}
  232. end;
  233. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  234. function ltsImageGetPixelAt(aHandle: TltsImageHandle; aX, aY: Integer; out aColor: TtsColor4f): TltsErrorCode; stdcall;
  235. var
  236. img: TtsImage;
  237. begin
  238. try
  239. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetPixelAt(Handle=%p; X=%d; Y=%d; Color=%p)', [Pointer(aHandle), aX, aY, Pointer(@aColor)]);{$ENDIF}
  240. result := ltsErrNone;
  241. if CheckImageHandle(aHandle, img) then begin
  242. if not img.GetPixelAt(aX, aY, aColor) then begin
  243. SetLastError(ltsErrInvalidValue, Format('x (%d) or y (%d) is out of range', [aX, aY]));
  244. result := LastErrorCode;
  245. end;
  246. end else
  247. result := LastErrorCode;
  248. except
  249. on ex: Exception do begin
  250. SetLastError(ex);
  251. result := LastErrorCode;
  252. end;
  253. end;
  254. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageGetPixelAt=%d', [Integer(result)]);{$ENDIF}
  255. end;
  256. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  257. function ltsImageAssign(aHandle, aSource: TltsImageHandle): TltsErrorCode; stdcall;
  258. var
  259. img, src: TtsImage;
  260. begin
  261. try
  262. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageAssign(Handle=%p; Source=%p)', [Pointer(aHandle), Pointer(aSource)]);{$ENDIF}
  263. result := ltsErrNone;
  264. if CheckImageHandle(aHandle, img) and CheckImageHandle(aSource, src)
  265. then img.Assign(src)
  266. else result := LastErrorCode;
  267. except
  268. on ex: Exception do begin
  269. SetLastError(ex);
  270. result := LastErrorCode;
  271. end;
  272. end;
  273. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageAssign=%d', [Integer(result)]);{$ENDIF}
  274. end;
  275. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  276. function ltsImageCreateEmpty(aHandle: TltsImageHandle; aFormat: TtsFormat; aWidth, aHeight: Integer): TltsErrorCode; stdcall;
  277. var
  278. img: TtsImage;
  279. begin
  280. try
  281. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageCreateEmpty(Handle=%p; Format=%d; Width=%d; Height=%d)', [Pointer(aHandle), Integer(aFormat), aWidth, aHeight]);{$ENDIF}
  282. result := ltsErrNone;
  283. if not ValidateFormat(aFormat) then begin
  284. result := LastErrorCode;
  285. end else if (aWidth < 0) then begin
  286. SetLastError(ltsErrInvalidValue, 'width must be a positive value');
  287. result := LastErrorCode;
  288. end else if (aHeight < 0) then begin
  289. SetLastError(ltsErrInvalidValue, 'height must be a positive value');
  290. result := LastErrorCode;
  291. end else if not CheckImageHandle(aHandle, img) then begin
  292. result := LastErrorCode;
  293. end else
  294. img.CreateEmpty(aFormat, aWidth, aHeight);
  295. except
  296. on ex: Exception do begin
  297. SetLastError(ex);
  298. result := LastErrorCode;
  299. end;
  300. end;
  301. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageCreateEmpty=%d', [Integer(result)]);{$ENDIF}
  302. end;
  303. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  304. function ltsImageLoadFromFunc(aHandle: TltsImageHandle; aCallback: TltsImageLoadFunc; aArgs: Pointer): TltsErrorCode; stdcall;
  305. var
  306. img: TtsImage;
  307. la: TLoadArgs;
  308. begin
  309. try
  310. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageLoadFromFunc(Handle=%p; Callback=%p; Args=%p)', [Pointer(aHandle), Pointer(aCallback), aArgs]);{$ENDIF}
  311. result := ltsErrNone;
  312. if CheckImageHandle(aHandle, img) then begin
  313. la.args := aArgs;
  314. la.callback := aCallback;
  315. la.handle := aHandle;
  316. img.LoadFromFunc(@ImageLoadCallback, @la);
  317. end else
  318. result := LastErrorCode;
  319. except
  320. on ex: Exception do begin
  321. SetLastError(ex);
  322. result := LastErrorCode;
  323. end;
  324. end;
  325. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageLoadFromFunc=%d', [Integer(result)]);{$ENDIF}
  326. end;
  327. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  328. function ltsImageResize(aHandle: TltsImageHandle; aWidth, aHeight, aX, aY: Integer): TltsErrorCode; stdcall;
  329. var
  330. img: TtsImage;
  331. begin
  332. try
  333. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageResize(Handle=%p; Width=%d; Height=%d; X=%d; Y=%d)', [Pointer(aHandle), aWidth, aHeight, aX, aY]);{$ENDIF}
  334. result := ltsErrNone;
  335. if (aWidth < 0) then begin
  336. SetLastError(ltsErrInvalidValue, 'width must be a positive value');
  337. result := LastErrorCode;
  338. end else if (aHeight < 0) then begin
  339. SetLastError(ltsErrInvalidValue, 'height must be a positive value');
  340. result := LastErrorCode;
  341. end else if not CheckImageHandle(aHandle, img) then begin
  342. result := LastErrorCode;
  343. end else
  344. img.Resize(aWidth, aHeight, aX, aY);
  345. except
  346. on ex: Exception do begin
  347. SetLastError(ex);
  348. result := LastErrorCode;
  349. end;
  350. end;
  351. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageResize=%d', [Integer(result)]);{$ENDIF}
  352. end;
  353. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  354. function ltsImageFillColor(aHandle: TltsImageHandle; aColor: TtsColor4f; aMask: TtsColorChannels; aModes: TtsImageModes): TltsErrorCode; stdcall;
  355. var
  356. img: TtsImage;
  357. begin
  358. try
  359. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageFillColor(Handle=%p; Color=(%f;%f;%f;%f); Mask=%d; Modes=(%d;%d;%d;%d))', [Pointer(aHandle), aColor.r, aColor.g, aColor.b, aColor.a, Integer(aMask), Integer(aModes[TtsColorChannel.tsChannelRed]), Integer(aModes[TtsColorChannel.tsChannelGreen]), Integer(aModes[TtsColorChannel.tsChannelBlue]), Integer(aModes[TtsColorChannel.tsChannelAlpha])]);{$ENDIF}
  360. result := ltsErrNone;
  361. if CheckImageHandle(aHandle, img)
  362. then img.FillColor(aColor, aMask, aModes)
  363. else result := LastErrorCode;
  364. except
  365. on ex: Exception do begin
  366. SetLastError(ex);
  367. result := LastErrorCode;
  368. end;
  369. end;
  370. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageFillColor=%d', [Integer(result)]);{$ENDIF}
  371. end;
  372. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  373. function ltsImageFillPattern(aHandle, aPattern: TltsImageHandle; aX, aY: Integer; aMask: TtsColorChannels; aModes: TtsImageModes): TltsErrorCode; stdcall;
  374. var
  375. img, pattern: TtsImage;
  376. begin
  377. try
  378. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageFillPattern(Handle=%p; Pattern=%p; X=%d; Y=%d; Mask=%d; Modes=(%d;%d;%d;%d))', [Pointer(aHandle), Pointer(aPattern), aX, aY, Integer(aMask), Integer(aModes[TtsColorChannel.tsChannelRed]), Integer(aModes[TtsColorChannel.tsChannelGreen]), Integer(aModes[TtsColorChannel.tsChannelBlue]), Integer(aModes[TtsColorChannel.tsChannelAlpha])]);{$ENDIF}
  379. result := ltsErrNone;
  380. if CheckImageHandle(aHandle, img) and CheckImageHandle(aPattern, pattern)
  381. then img.FillPattern(pattern, aX, aY, aMask, aModes)
  382. else result := LastErrorCode;
  383. except
  384. on ex: Exception do begin
  385. SetLastError(ex);
  386. result := LastErrorCode;
  387. end;
  388. end;
  389. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageFillPattern=%d', [Integer(result)]);{$ENDIF}
  390. end;
  391. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  392. function ltsImageBlend(aHandle, aSource: TltsImageHandle; aX, aY: Integer; aBlendFunc: TltsImageBlendFunc; aArgs: Pointer): TltsErrorCode; stdcall;
  393. var
  394. img, src: TtsImage;
  395. ba: TBlendArgs;
  396. begin
  397. try
  398. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageBlend(Handle=%p; Source=%p; X=%d; Y=%d; BlendFunc=%p; Args=%p)', [Pointer(aHandle), Pointer(aSource), aX, aY, Pointer(aBlendFunc), aArgs]);{$ENDIF}
  399. result := ltsErrNone;
  400. if CheckImageHandle(aHandle, img) and CheckImageHandle(aSource, src) then begin
  401. ba.args := aArgs;
  402. ba.handle := aHandle;
  403. ba.callback := aBlendFunc;
  404. img.Blend(src, aX, aY, @ImageBlendCallback, @ba);
  405. end else
  406. result := LastErrorCode;
  407. except
  408. on ex: Exception do begin
  409. SetLastError(ex);
  410. result := LastErrorCode;
  411. end;
  412. end;
  413. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageBlend=%d', [Integer(result)]);{$ENDIF}
  414. end;
  415. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  416. function ltsImageBlur(aHandle: TltsImageHandle; aHorzRad, aHorzStr, aVertRad, aVertStr: Single; aMask: TtsColorChannels): TltsErrorCode; stdcall;
  417. var
  418. img: TtsImage;
  419. horz, vert: TtsKernel1D;
  420. begin
  421. try
  422. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageBlur(Handle=%p; HorzRad=%f; HorzStr=%f; VertRad=%f; VertStr=%f; Mask=%d)', [Pointer(aHandle), aHorzRad, aHorzStr, aVertRad, aVertStr, Integer(aMask)]);{$ENDIF}
  423. result := ltsErrNone;
  424. if CheckImageHandle(aHandle, img) then begin
  425. horz := TtsKernel1D.Create(aHorzRad, aHorzStr);
  426. vert := TtsKernel1D.Create(aVertRad, aVertStr);
  427. try
  428. img.Blur(horz, vert, aMask);
  429. finally
  430. FreeAndNil(horz);
  431. FreeAndNil(vert);
  432. end;
  433. end else
  434. result := LastErrorCode;
  435. except
  436. on ex: Exception do begin
  437. SetLastError(ex);
  438. result := LastErrorCode;
  439. end;
  440. end;
  441. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageBlur=%d', [Integer(result)]);{$ENDIF}
  442. end;
  443. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  444. function ltsImageDestroy(aHandle: TltsImageHandle): TltsErrorCode; stdcall;
  445. var
  446. img: TtsImage;
  447. begin
  448. try
  449. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageDestroy(Handle=%p)', [Pointer(aHandle)]);{$ENDIF}
  450. result := ltsErrNone;
  451. if CheckImageHandle(aHandle, img) then begin
  452. DelReference(ltsObjTypeImage, img);
  453. FreeAndNil(img);
  454. end else
  455. result := LastErrorCode;
  456. except
  457. on ex: Exception do begin
  458. SetLastError(ex);
  459. result := LastErrorCode;
  460. end;
  461. end;
  462. {$IFDEF DEBUG}utlLogger.Log(nil, 'ltsImageDestroy=%d', [Integer(result)]);{$ENDIF}
  463. end;
  464. end.