sdlfilter.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. unit sdlfilter;
  2. {******************************************************************************}
  3. {
  4. $Id: sdlfilter.pas,v 1.2 2004/03/31 09:04:30 savage Exp $
  5. }
  6. { }
  7. { Borland Delphi SDL_Image - An image processing and effects library for }
  8. { use with SDL Surfaces }
  9. { }
  10. { }
  11. { }
  12. { The initial developer of this Pascal code was : }
  13. { Jason Farmer <[email protected]> }
  14. { }
  15. { Contributor(s) }
  16. { -------------- }
  17. { Dominique Louis <[email protected]> }
  18. { }
  19. { Obtained through: }
  20. { Joint Endeavour of Delphi Innovators ( Project JEDI ) }
  21. { }
  22. { You may retrieve the latest version of this file at the Project }
  23. { JEDI home page, located at http://delphi-jedi.org }
  24. { }
  25. { The contents of this file are used with permission, subject to }
  26. { the Mozilla Public License Version 1.1 (the "License"); you may }
  27. { not use this file except in compliance with the License. You may }
  28. { obtain a copy of the License at }
  29. { http://www.mozilla.org/MPL/MPL-1.1.html }
  30. { }
  31. { Software distributed under the License is distributed on an }
  32. { "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or }
  33. { implied. See the License for the specific language governing }
  34. { rights and limitations under the License. }
  35. { }
  36. { Description }
  37. { ----------- }
  38. { A simple library to manipulate SDL surfaces. }
  39. { Applies Image Kernel Filters and procedural effects to images }
  40. { }
  41. { Requires }
  42. { -------- }
  43. { SDL.pas in your search path. }
  44. { SDL_Image in your search path }
  45. { SDL_Utils in your search path }
  46. { }
  47. { Programming Notes }
  48. { ----------------- }
  49. { The Kernels must be built prior to application. Use the BuildXxX Kernel }
  50. { functions provided to use predefined effects or supply your own. }
  51. { }
  52. { Effect Functions always output to another surface. Do not use the source }
  53. { Surface for the results, strange things will happen if you do. }
  54. { }
  55. { Revision History }
  56. { ---------------- }
  57. { Sept 30 2001 - JF : First Written }
  58. { Oct 01 2001 - DL : Made Kylix Friendly }
  59. { Oct 03 2001 - RK : Fixed a bug in OutLine effect + minor speed up }
  60. {
  61. $Log: sdlfilter.pas,v $
  62. Revision 1.2 2004/03/31 09:04:30 savage
  63. Added jedi-sdl.inc files for better FreePascal/multi compiler support.
  64. Revision 1.1 2004/03/28 13:52:14 savage
  65. Filtering unit and demo
  66. }
  67. {******************************************************************************}
  68. {$I jedi-sdl.inc}
  69. interface
  70. uses
  71. SysUtils,
  72. sdl,
  73. sdlutils;
  74. Type
  75. TKernelTypes = ( HighPassVeryWeak,
  76. HighPassVeryStrong,
  77. HighPassStrong,
  78. HighPassWeak,
  79. LowPassUniform,
  80. LowPassPeaked,
  81. LowPassStronglyPeaked,
  82. PrewittEdge_NW_SE,
  83. PrewittEdge_N_S,
  84. PrewittEdge_NE_SW,
  85. PrewittEdge_E_W,
  86. PrewittEdge_SE_NW,
  87. PrewittEdge_S_N,
  88. PrewittEdge_SW_NE,
  89. PrewittEdge_W_E,
  90. LapiacianEdgeWeak,
  91. LapiacianEdgeStrong,
  92. LapiacianEdgeVeryStrong);
  93. T3x3Kernel = array[1..3,1..3] of double; // Just work with 3x3 Kernels
  94. //T5x5Kernel = array[1..5,1..5] of double; // Not implemented yet
  95. //T7x7Kernel = array[1..7,1..7] of double;
  96. P3x3Kernel = ^T3x3Kernel;
  97. procedure ApplyFilter( SourceSurface : PSDL_Surface; SourceRect : PSDL_Rect; DestinationSurface : PSDL_Surface; DestinationRect : PSDL_Rect; KernelToApply: P3x3Kernel);Overload;
  98. //procedure ApplyFilter( SourceSurface : PSDL_Surface; SourceRect : PSDL_Rect; DestinationSurface : PSDL_Surface; DestinationRect : PSDL_Rect; KernelToApply: T5x5Kernel);overload;
  99. //procedure ApplyFilter( SourceSurface : PSDL_Surface; SourceRect : PSDL_Rect; DestinationSurface : PSDL_Surface; DestinationRect : PSDL_Rect; KernelToApply: T7x7Kernel);overload;
  100. // 3X3 kernel construction functions
  101. procedure Build3x3Kernel( KernelType : TKernelTypes; FilterKernel: P3x3Kernel); Overload;
  102. procedure ApplyImageOutline( SourceSurface : PSDL_Surface; SourceRect : PSDL_Rect; DestinationSurface : PSDL_Surface; DestinationRect : PSDL_Rect; OutlineColour : Cardinal);Overload;
  103. function PixelMatch( TestSurface : PSDL_Surface;X : Integer;Y:Integer;TransparentColour:cardinal) : Boolean;
  104. implementation
  105. procedure ApplyImageOutline( SourceSurface : PSDL_Surface; SourceRect : PSDL_Rect; DestinationSurface : PSDL_Surface; DestinationRect : PSDL_Rect; OutlineColour : Cardinal);Overload;
  106. // This procedure traces the outline of a sprite based on its transparent value.
  107. // It draws the outline in the supplied colour.
  108. var
  109. Red,Green,Blue : UInt8;
  110. TempRed,TempGreen,TempBlue : integer;
  111. X,Y,MaxX,MaxY,SOX,SOY,DOX,DOY,KX,KY,LeftX,RightX,TopY,BottomY:Integer;
  112. Srect,DRect : SDL_Rect;
  113. SourcePixel, DestinationPixel: cardinal;
  114. WorkRed,WorkGreen,WorkBlue : double;
  115. SourceTransparentPixel,DestinationTransparentPixel : cardinal;
  116. FoundAPixel : Boolean;
  117. begin
  118. // Make sure we have rects and make sure they are within the bounds of the surface
  119. if SourceRect = nil then
  120. begin
  121. Srect.x := 0;
  122. Srect.y := 0;
  123. Srect.w := Sourcesurface.w ;
  124. Srect.h := sourcesurface.h ;
  125. end
  126. else
  127. begin
  128. Srect.x := SourceRect.x;
  129. Srect.y := SourceRect.y;
  130. if (SourceRect.x + sourcerect.w)> SourceSurface.w then
  131. begin
  132. Srect.w := SourceSurface.w - SourceRect.x;
  133. end
  134. else
  135. begin
  136. Srect.w := SourceRect.w;
  137. end;
  138. if (SourceRect.y + sourcerect.h)> SourceSurface.h then
  139. begin
  140. Srect.h := SourceSurface.h - SourceRect.y;
  141. end
  142. else
  143. begin
  144. Srect.h := SourceRect.h;
  145. end;
  146. end;
  147. if DestinationRect = nil then
  148. begin
  149. DRect.x := 0;
  150. DRect.y := 0;
  151. DRect.w := DestinationSurface.w;
  152. DRect.h := DestinationSurface.h;
  153. end
  154. else
  155. begin
  156. DRect.x :=DestinationRect.x;
  157. DRect.y :=DestinationRect.y;
  158. if (DestinationRect.x + DestinationRect.w)> SourceSurface.w then
  159. begin
  160. DRect.w := DestinationSurface.w - DestinationRect.x;
  161. end
  162. else
  163. begin
  164. DRect.w := DestinationRect.w;
  165. end;
  166. if (DestinationRect.y + DestinationRect.h)> DestinationSurface.h then
  167. begin
  168. DRect.h := DestinationSurface.h - DestinationRect.y;
  169. end
  170. else
  171. begin
  172. DRect.h := DestinationRect.h;
  173. end;
  174. end;
  175. // Now we're happy that the rects are within valid areas,
  176. // We need to find the lowest extents for the rects
  177. // Get pixel RGB
  178. if srect.w>DRect.w then
  179. begin
  180. MaxX := DRect.w - 1;
  181. end
  182. else
  183. begin
  184. MaxX := SRect.w - 1;
  185. end;
  186. if srect.h>DRect.h then
  187. begin
  188. MaxY := DRect.h - 1;
  189. end
  190. else
  191. begin
  192. MaxY := SRect.h - 1;
  193. end;
  194. // Now we know the lowest width and height, we can get on with the work
  195. // Set the Source Offsets and Dest Offsets
  196. SOX := SRect.x;
  197. SOY := Srect.y;
  198. DOX := DRect.X;
  199. DOY := DRect.y;
  200. // Do the test
  201. // Lock both surfaces
  202. SourceTransparentPixel := sourcesurface.format.colorkey;
  203. DestinationTransparentPixel := DestinationSurface.format.colorkey;
  204. SDL_FillRect(DestinationSurface, @DRect, DestinationTransparentPixel);
  205. SDL_LockSurface(SourceSurface);
  206. SDL_LockSurface(DestinationSurface);
  207. for Y := 0 to maxy do
  208. begin
  209. for X := 0 to maxx do
  210. begin
  211. sourcepixel := SDL_GetPixel(SourceSurface, X, Y);
  212. if sourcepixel = SourceTransparentPixel then
  213. begin
  214. KX := x + sox;
  215. KY := y + soy;
  216. LeftX := kx - 1;
  217. if LeftX < sox then LeftX := sox;
  218. RightX := kx + 1;
  219. if RightX > maxx + sox then RightX := Maxx+sox;
  220. TopY := ky - 1;
  221. if TopY < soy then TopY := soy;
  222. BottomY := ky + 1;
  223. if BottomY > maxy + soy then BottomY := Maxy + soy;
  224. // sourcepixel := SDL_GetPixel(SourceSurface, KX, KY);
  225. // Check pixels around current pixel for non transparent values
  226. FoundAPixel := not PixelMatch(SourceSurface,LeftX,TopY,SourceTransparentPixel);
  227. if (FoundAPixel=False) then FoundAPixel := not PixelMatch(SourceSurface, LeftX, KY, SourceTransparentPixel);
  228. if (FoundAPixel=False) then FoundAPixel := not PixelMatch(SourceSurface, LeftX, BottomY, SourceTransparentPixel);
  229. if (FoundAPixel=False) then FoundAPixel := not PixelMatch(SourceSurface, KX, TopY, SourceTransparentPixel);
  230. if (FoundAPixel=False) then FoundAPixel := not PixelMatch(SourceSurface, KX, BottomY, SourceTransparentPixel);
  231. if (FoundAPixel=False) then FoundAPixel := not PixelMatch(SourceSurface, RightX, TopY, SourceTransparentPixel);
  232. if (FoundAPixel=False) then FoundAPixel := not PixelMatch(SourceSurface, RightX, KY, SourceTransparentPixel);
  233. if (FoundAPixel=False) then FoundAPixel := not PixelMatch(SourceSurface, RightX, BottomY, SourceTransparentPixel);;
  234. if FoundAPixel = true then
  235. begin
  236. // A non transparent pixel is next to our transpa
  237. SDL_PutPixel(DestinationSurface,dox+x,doy+y,OutlineColour);
  238. end;
  239. end;
  240. end;
  241. end;
  242. SDL_UnlockSurface(SourceSurface);
  243. SDL_UnlockSurface(DestinationSurface);
  244. end;
  245. function PixelMatch( TestSurface : PSDL_Surface;X : Integer;Y:Integer;TransparentColour:cardinal) : Boolean;
  246. begin
  247. result := (SDL_GetPixel(TestSurface,x,y)=TransparentColour);
  248. end;
  249. procedure ApplyFilter( SourceSurface : PSDL_Surface; SourceRect : PSDL_Rect; DestinationSurface : PSDL_Surface; DestinationRect : PSDL_Rect; KernelToApply: P3x3Kernel);Overload;
  250. var
  251. Red,Green,Blue : UInt8;
  252. TempRed,TempGreen,TempBlue : integer;
  253. X,Y,MaxX,MaxY,SOX,SOY,DOX,DOY,KX,KY:Integer;
  254. Srect,DRect : SDL_Rect;
  255. SourcePixel, DestinationPixel: cardinal;
  256. WorkRed,WorkGreen,WorkBlue : double;
  257. begin
  258. // Make sure we have rects and make sure they are within the bounds of the surface
  259. if SourceRect = nil then
  260. begin
  261. Srect.x := 0;
  262. Srect.y := 0;
  263. Srect.w := Sourcesurface.w ;
  264. Srect.h := sourcesurface.h ;
  265. end
  266. else
  267. begin
  268. Srect.x := SourceRect.x;
  269. Srect.y := SourceRect.y;
  270. if (SourceRect.x + sourcerect.w)> SourceSurface.w then
  271. begin
  272. Srect.w := SourceSurface.w - SourceRect.x;
  273. end
  274. else
  275. begin
  276. Srect.w := SourceRect.w;
  277. end;
  278. if (SourceRect.y + sourcerect.h)> SourceSurface.h then
  279. begin
  280. Srect.h := SourceSurface.h - SourceRect.y;
  281. end
  282. else
  283. begin
  284. Srect.h := SourceRect.h;
  285. end;
  286. end;
  287. if DestinationRect = nil then
  288. begin
  289. DRect.x := 0;
  290. DRect.y := 0;
  291. DRect.w := DestinationSurface.w;
  292. DRect.h := DestinationSurface.h;
  293. end
  294. else
  295. begin
  296. DRect.x :=DestinationRect.x;
  297. DRect.y :=DestinationRect.y;
  298. if (DestinationRect.x + DestinationRect.w)> SourceSurface.w then
  299. begin
  300. DRect.w := DestinationSurface.w - DestinationRect.x;
  301. end
  302. else
  303. begin
  304. DRect.w := DestinationRect.w;
  305. end;
  306. if (DestinationRect.y + DestinationRect.h)> DestinationSurface.h then
  307. begin
  308. DRect.h := DestinationSurface.h - DestinationRect.y;
  309. end
  310. else
  311. begin
  312. DRect.h := DestinationRect.h;
  313. end;
  314. end;
  315. // Now we're happy that the rects are within valid areas,
  316. // We need to find the lowest extents for the rects
  317. // Get pixel RGB
  318. if srect.w>DRect.w then
  319. begin
  320. MaxX := DRect.w;
  321. end
  322. else
  323. begin
  324. MaxX := SRect.w;
  325. end;
  326. if srect.h>DRect.h then
  327. begin
  328. MaxY := DRect.h;
  329. end
  330. else
  331. begin
  332. MaxY := SRect.h;
  333. end;
  334. // Now we know the lowest width and height, we can get on with the work
  335. // Set the Source Offsets and Dest Offsets
  336. SOX := SRect.x;
  337. SOY := Srect.y;
  338. DOX := DRect.X;
  339. DOY := DRect.y;
  340. // Alter the values to allow for a 1 pixel border
  341. if SOX = 0 then SOX := 1;
  342. if SOY = 0 then SOY := 1;
  343. if DOX = 0 then DOX := 1;
  344. if DOY = 0 then DOY := 1;
  345. If Maxx+Sox >= SourceSurface.w then
  346. begin
  347. dec(maxx);
  348. end;
  349. If Maxy+Soy >= SourceSurface.h then
  350. begin
  351. dec(maxy);
  352. end;
  353. If Maxx+dox >= DestinationSurface.w then
  354. begin
  355. dec(maxx);
  356. end;
  357. If Maxy+doy >= DestinationSurface.h then
  358. begin
  359. dec(maxy);
  360. end;
  361. // Do the filter
  362. // Lock both surfaces
  363. SDL_LockSurface(SourceSurface);
  364. SDL_LockSurface(DestinationSurface);
  365. for Y:=0 to maxy-1 do
  366. begin
  367. for X := 0 to maxx-1 do
  368. begin
  369. TempRed := 0;
  370. TempGreen := 0;
  371. TempBlue := 0;
  372. for KX := 1 to 3 do
  373. begin
  374. for KY := 1 to 3 do
  375. begin
  376. sourcepixel := SDL_GetPixel(SourceSurface,x+sox+(KY-2),y+soy+(KX-2));
  377. SDL_GetRGB(sourcepixel,SourceSurface.format,@Red,@Green,@Blue);
  378. workred := red;
  379. workgreen := green;
  380. workblue := blue;
  381. TempRed := round( TempRed + workred * KernelToApply[KY, KX]);
  382. TempGreen := round(TempGreen +workgreen * KernelToApply[KY, KX]);
  383. TempBlue := round( TempBlue + workblue * KernelToApply[KY, KX]);
  384. end;
  385. end;
  386. // Make sure we can put the values back into bytes
  387. If TempRed < 0 Then TempRed := 0;
  388. If TempRed > 255 Then TempRed := 255 ;
  389. If TempGreen < 0 Then TempGreen := 0;
  390. If TempGreen > 255 Then TempGreen := 255;
  391. If TempBlue < 0 Then TempBlue := 0;
  392. If TempBlue > 255 Then TempBlue := 255;
  393. // Put the pixel back into the destination
  394. DestinationPixel := SDL_MapRGB(destinationsurface.format,byte(tempred),byte(tempgreen),byte(tempblue));
  395. try
  396. SDL_PutPixel(DestinationSurface,dox+x,doy+y,destinationpixel);
  397. except
  398. on E: Exception do e.CreateFmt('Error occurred X=%d,Y=%d,dox=%d,doy=%d',[x,y,dox,doy]);
  399. end;
  400. end;
  401. end;
  402. SDL_UnlockSurface(SourceSurface);
  403. SDL_UnlockSurface(DestinationSurface);
  404. end;
  405. procedure Build3x3Kernel( KernelType : TKernelTypes; FilterKernel: P3x3Kernel); Overload;
  406. var
  407. X,Y : integer;
  408. begin
  409. // Depending on the type of known kernel that we want to build,
  410. // Populate the kernel array
  411. case KernelType of
  412. HighPassVeryWeak :
  413. begin
  414. FilterKernel[1,1] := -1 / 12; FilterKernel[1,2] := -1 / 12; FilterKernel[1,3] := -1 / 12;
  415. FilterKernel[2,1] := -1 / 12; FilterKernel[2,2] := 20 / 12; FilterKernel[2,3] := -1 / 12;
  416. FilterKernel[3,1] := -1 / 12; FilterKernel[3,2] := -1 / 12; FilterKernel[3,3] := -1 / 12;
  417. end;
  418. HighPassVeryStrong :
  419. begin
  420. FilterKernel[1,1] := -1 ; FilterKernel[1,2] := -1 ; FilterKernel[1,3] := -1 ;
  421. FilterKernel[2,1] := -1 ; FilterKernel[2,2] := 9; FilterKernel[2,3] := -1 ;
  422. FilterKernel[3,1] := -1 ; FilterKernel[3,2] := -1 ; FilterKernel[3,3] := -1 ;
  423. end;
  424. HighPassStrong :
  425. begin
  426. FilterKernel[1,1] := 0; FilterKernel[1,2] := -1; FilterKernel[1,3] := 0;
  427. FilterKernel[2,1] := -1; FilterKernel[2,2] := 5; FilterKernel[2,3] := -1;
  428. FilterKernel[3,1] := 0; FilterKernel[3,2] := -1; FilterKernel[3,3] := 0;
  429. end;
  430. HighPassWeak :
  431. begin
  432. FilterKernel[1,1] := -1 / 4; FilterKernel[1,2] := -1 / 4; FilterKernel[1,3] := -1 / 4;
  433. FilterKernel[2,1] := -1 / 4; FilterKernel[2,2] := 12 / 4; FilterKernel[2,3] := -1 / 4;
  434. FilterKernel[3,1] := -1 / 4; FilterKernel[3,2] := -1 / 4; FilterKernel[3,3] := -1 / 4;
  435. end;
  436. LowPassUniform :
  437. begin
  438. For X := 1 To 3 do
  439. begin
  440. For Y := 1 To 3 do
  441. begin
  442. FilterKernel[X, Y] := 0.1 ;
  443. end;
  444. end;
  445. end;
  446. LowPassPeaked :
  447. begin
  448. FilterKernel[1,1] := 0.0666; FilterKernel[1,2] := 0.1333; FilterKernel[1,3] := 0.0666;
  449. FilterKernel[2,1] := 0.1333; FilterKernel[2,2] := 0.2; FilterKernel[2,3] := 0.1333;
  450. FilterKernel[3,1] := 0.0666; FilterKernel[3,2] := 0.1333; FilterKernel[3,3] := 0.0666;
  451. end;
  452. LowPassStronglyPeaked :
  453. begin
  454. FilterKernel[1,1] := 0.05; FilterKernel[1,2] := 0.05; FilterKernel[1,3] := 0.05;
  455. FilterKernel[2,1] := 0.05; FilterKernel[2,2] := 0.6; FilterKernel[2,3] := 0.05;
  456. FilterKernel[3,1] := 0.05; FilterKernel[3,2] := 0.05; FilterKernel[3,3] := 0.05;
  457. end;
  458. PrewittEdge_NW_SE :
  459. begin
  460. FilterKernel[1,1] := 1; FilterKernel[1,2] := 1; FilterKernel[1,3] := 1;
  461. FilterKernel[2,1] := 1; FilterKernel[2,2] := -2; FilterKernel[2,3] := -1;
  462. FilterKernel[3,1] := 1; FilterKernel[3,2] := -1; FilterKernel[3,3] := -1;
  463. end;
  464. PrewittEdge_N_S :
  465. begin
  466. FilterKernel[1,1] := 1; FilterKernel[1,2] := 1; FilterKernel[1,3] := 1;
  467. FilterKernel[2,1] := 1; FilterKernel[2,2] := -2; FilterKernel[2,3] := 1;
  468. FilterKernel[3,1] :=-1; FilterKernel[3,2] := -1; FilterKernel[3,3] := -1;
  469. end;
  470. PrewittEdge_NE_SW :
  471. begin
  472. FilterKernel[1,1] := 1; FilterKernel[1,2] := 1; FilterKernel[1,3] := 1;
  473. FilterKernel[2,1] :=-1; FilterKernel[2,2] := -2; FilterKernel[2,3] := 1;
  474. FilterKernel[3,1] :=-1; FilterKernel[3,2] := -1; FilterKernel[3,3] := 1;
  475. end;
  476. PrewittEdge_E_W :
  477. begin
  478. FilterKernel[1,1] :=-1; FilterKernel[1,2] := 1; FilterKernel[1,3] := 1;
  479. FilterKernel[2,1] :=-1; FilterKernel[2,2] := -2; FilterKernel[2,3] := 1;
  480. FilterKernel[3,1] :=-1; FilterKernel[3,2] := 1; FilterKernel[3,3] := 1;
  481. end;
  482. PrewittEdge_SE_NW :
  483. begin
  484. FilterKernel[1,1] :=-1; FilterKernel[1,2] := -1; FilterKernel[1,3] := 1;
  485. FilterKernel[2,1] :=-1; FilterKernel[2,2] := -2; FilterKernel[2,3] := 1;
  486. FilterKernel[3,1] := 1; FilterKernel[3,2] := 1; FilterKernel[3,3] := 1;
  487. end;
  488. PrewittEdge_S_N :
  489. begin
  490. FilterKernel[1,1] :=-1; FilterKernel[1,2] := -1; FilterKernel[1,3] := -1;
  491. FilterKernel[2,1] := 1; FilterKernel[2,2] := -2; FilterKernel[2,3] := 1;
  492. FilterKernel[3,1] := 1; FilterKernel[3,2] := 1; FilterKernel[3,3] := 1;
  493. end;
  494. PrewittEdge_SW_NE :
  495. begin
  496. FilterKernel[1,1] := 1; FilterKernel[1,2] := -1; FilterKernel[1,3] := -1;
  497. FilterKernel[2,1] := 1; FilterKernel[2,2] := -2; FilterKernel[2,3] := -1;
  498. FilterKernel[3,1] := 1; FilterKernel[3,2] := 1; FilterKernel[3,3] := 1;
  499. end;
  500. PrewittEdge_W_E :
  501. begin
  502. FilterKernel[1,1] := 1; FilterKernel[1,2] := 1; FilterKernel[1,3] := -1;
  503. FilterKernel[2,1] := 1; FilterKernel[2,2] := -2; FilterKernel[2,3] := -1;
  504. FilterKernel[3,1] := 1; FilterKernel[3,2] := 1; FilterKernel[3,3] := -1;
  505. end;
  506. LapiacianEdgeWeak :
  507. begin
  508. FilterKernel[1,1] := 0; FilterKernel[1,2] := -1; FilterKernel[1,3] := 0;
  509. FilterKernel[2,1] :=-1; FilterKernel[2,2] := 4; FilterKernel[2,3] := -1;
  510. FilterKernel[3,1] := 0; FilterKernel[3,2] := -1; FilterKernel[3,3] := 0;
  511. end;
  512. LapiacianEdgeStrong :
  513. begin
  514. FilterKernel[1,1] :=-1; FilterKernel[1,2] := -1; FilterKernel[1,3] := -1;
  515. FilterKernel[2,1] :=-1; FilterKernel[2,2] := 8; FilterKernel[2,3] := -1;
  516. FilterKernel[3,1] :=-1; FilterKernel[3,2] := -1; FilterKernel[3,3] := -1;
  517. end;
  518. LapiacianEdgeVeryStrong :
  519. begin
  520. FilterKernel[1,1] :=-1; FilterKernel[1,2] := -2; FilterKernel[1,3] := -1;
  521. FilterKernel[2,1] :=-2; FilterKernel[2,2] := 12; FilterKernel[2,3] := -2;
  522. FilterKernel[3,1] :=-1; FilterKernel[3,2] := -2; FilterKernel[3,3] := -1;
  523. end;
  524. end;
  525. end;
  526. end.