p_ga.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. {
  2. Free Pascal port of the Hermes C library.
  3. Copyright (C) 2001-2003 Nikolay Nikolov ([email protected])
  4. Original C version by Christian Nentwich ([email protected])
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version
  9. with the following modification:
  10. As a special exception, the copyright holders of this library give you
  11. permission to link this library with independent modules to produce an
  12. executable, regardless of the license terms of these independent modules,and
  13. to copy and distribute the resulting executable under terms of your choice,
  14. provided that you also meet, for each linked independent module, the terms
  15. and conditions of the license of that module. An independent module is a
  16. module which is not derived from or based on this library. If you modify
  17. this library, you may extend this exception to your version of the library,
  18. but you are not obligated to do so. If you do not wish to do so, delete this
  19. exception statement from your version.
  20. This library is distributed in the hope that it will be useful,
  21. but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  23. Lesser General Public License for more details.
  24. You should have received a copy of the GNU Lesser General Public
  25. License along with this library; if not, write to the Free Software
  26. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  27. }
  28. {
  29. Generic format conversion routines for the HERMES library
  30. Copyright (c) 1998 Christian Nentwich ([email protected])
  31. This source code is licensed under the GNU LGPL
  32. Please refer to the file COPYING.LIB contained in the distribution for
  33. licensing conditions
  34. }
  35. procedure ConvertP_Generic32_A_Generic32_A(iface: PHermesConverterInterface); cdecl;
  36. var
  37. s_pixel, r, g, b, a: Uint32;
  38. count: DWord;
  39. source, dest: PUint8;
  40. begin
  41. source := iface^.s_pixels; dest := iface^.d_pixels;
  42. repeat
  43. count := iface^.s_width;
  44. repeat
  45. s_pixel := PUint32(source)^;
  46. r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
  47. iface^.mask_r;
  48. g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
  49. iface^.mask_g;
  50. b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
  51. iface^.mask_b;
  52. a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
  53. iface^.mask_a;
  54. PUint32(dest)^ := r or g or b or a;
  55. Inc(source, 4);
  56. Inc(dest, 4);
  57. Dec(count);
  58. until count = 0;
  59. Inc(source, iface^.s_add);
  60. Inc(dest, iface^.d_add);
  61. Dec(iface^.s_height);
  62. until iface^.s_height = 0;
  63. end;
  64. procedure ConvertP_Generic32_A_Generic24_A(iface: PHermesConverterInterface); cdecl;
  65. var
  66. s_pixel, r, g, b, a: Uint32;
  67. d_ptr: PUint8;
  68. count: DWord;
  69. source, dest: PUint8;
  70. begin
  71. d_ptr := PUint8(@s_pixel) + (R_32 - R_24);
  72. source := iface^.s_pixels; dest := iface^.d_pixels;
  73. repeat
  74. count := iface^.s_width;
  75. repeat
  76. s_pixel := PUint32(source)^;
  77. r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
  78. iface^.mask_r;
  79. g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
  80. iface^.mask_g;
  81. b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
  82. iface^.mask_b;
  83. a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
  84. iface^.mask_a;
  85. s_pixel := r or g or b or a;
  86. (dest+0)^ := (d_ptr+0)^;
  87. (dest+1)^ := (d_ptr+1)^;
  88. (dest+2)^ := (d_ptr+2)^;
  89. Inc(source, 4);
  90. Inc(dest, 3);
  91. Dec(count);
  92. until count = 0;
  93. Inc(source, iface^.s_add);
  94. Inc(dest, iface^.d_add);
  95. Dec(iface^.s_height);
  96. until iface^.s_height = 0;
  97. end;
  98. procedure ConvertP_Generic32_A_Generic16_A(iface: PHermesConverterInterface); cdecl;
  99. var
  100. s_pixel, r, g, b, a: Uint32;
  101. count: DWord;
  102. source, dest: PUint8;
  103. begin
  104. source := iface^.s_pixels; dest := iface^.d_pixels;
  105. repeat
  106. count := iface^.s_width shr 1;
  107. if count <> 0 then
  108. repeat
  109. r := (((PUint32(source)^) shr iface^.info.r_right) shl iface^.info.r_left) and
  110. iface^.mask_r;
  111. g := (((PUint32(source)^) shr iface^.info.g_right) shl iface^.info.g_left) and
  112. iface^.mask_g;
  113. b := (((PUint32(source)^) shr iface^.info.b_right) shl iface^.info.b_left) and
  114. iface^.mask_b;
  115. a := (((PUint32(source)^) shr iface^.info.a_right) shl iface^.info.a_left) and
  116. iface^.mask_a;
  117. s_pixel := (r or g or b or a) shl DWORD_SMALLINT0_SHL;
  118. r := ((((PUint32(source)+1)^) shr iface^.info.r_right) shl iface^.info.r_left) and
  119. iface^.mask_r;
  120. g := ((((PUint32(source)+1)^) shr iface^.info.g_right) shl iface^.info.g_left) and
  121. iface^.mask_g;
  122. b := ((((PUint32(source)+1)^) shr iface^.info.b_right) shl iface^.info.b_left) and
  123. iface^.mask_b;
  124. a := ((((PUint32(source)+1)^) shr iface^.info.a_right) shl iface^.info.a_left) and
  125. iface^.mask_a;
  126. s_pixel := s_pixel or ((r or g or b or a) shl DWORD_SMALLINT1_SHL);
  127. PUint32(dest)^ := s_pixel;
  128. Inc(source, 8);
  129. Inc(dest, 4);
  130. Dec(count);
  131. until count = 0;
  132. { Trailing pixel }
  133. if (iface^.s_width and 1) <> 0 then
  134. begin
  135. r := (((PUint32(source)^) shr iface^.info.r_right) shl iface^.info.r_left) and
  136. iface^.mask_r;
  137. g := (((PUint32(source)^) shr iface^.info.g_right) shl iface^.info.g_left) and
  138. iface^.mask_g;
  139. b := (((PUint32(source)^) shr iface^.info.b_right) shl iface^.info.b_left) and
  140. iface^.mask_b;
  141. a := (((PUint32(source)^) shr iface^.info.a_right) shl iface^.info.a_left) and
  142. iface^.mask_a;
  143. PUint16(dest)^ := r or g or b or a;
  144. Inc(dest, 2);
  145. Inc(source, 4);
  146. end;
  147. Inc(source, iface^.s_add);
  148. Inc(dest, iface^.d_add);
  149. Dec(iface^.s_height);
  150. until iface^.s_height = 0;
  151. end;
  152. procedure ConvertP_Generic32_A_Generic8_A(iface: PHermesConverterInterface); cdecl;
  153. var
  154. s_pixel, r, g, b, a: Uint32;
  155. count: DWord;
  156. source, dest: PUint8;
  157. begin
  158. source := iface^.s_pixels; dest := iface^.d_pixels;
  159. repeat
  160. count := iface^.s_width;
  161. repeat
  162. s_pixel := PUint32(source)^;
  163. r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
  164. iface^.mask_r;
  165. g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
  166. iface^.mask_g;
  167. b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
  168. iface^.mask_b;
  169. a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
  170. iface^.mask_a;
  171. dest^ := r or g or b or a;
  172. Inc(source, 4);
  173. Inc(dest);
  174. Dec(count);
  175. until count = 0;
  176. Inc(source, iface^.s_add);
  177. Inc(dest, iface^.d_add);
  178. Dec(iface^.s_height);
  179. until iface^.s_height = 0;
  180. end;
  181. procedure ConvertP_Generic24_A_Generic32_A(iface: PHermesConverterInterface); cdecl;
  182. var
  183. s_pixel, r, g, b, a: Uint32;
  184. count: DWord;
  185. source, dest: PUint8;
  186. begin
  187. source := iface^.s_pixels; dest := iface^.d_pixels;
  188. repeat
  189. count := iface^.s_width;
  190. repeat
  191. s_pixel := ((PUint32(source+R_24)^) shl 16) or
  192. ((PUint32(source+G_24)^) shl 8) or
  193. (PUint32(source+B_24)^);
  194. r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
  195. iface^.mask_r;
  196. g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
  197. iface^.mask_g;
  198. b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
  199. iface^.mask_b;
  200. a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
  201. iface^.mask_a;
  202. PUint32(dest)^ := r or g or b or a;
  203. Inc(source, 3);
  204. Inc(dest, 4);
  205. Dec(count);
  206. until count = 0;
  207. Inc(source, iface^.s_add);
  208. Inc(dest, iface^.d_add);
  209. Dec(iface^.s_height);
  210. until iface^.s_height = 0;
  211. end;
  212. procedure ConvertP_Generic24_A_Generic24_A(iface: PHermesConverterInterface); cdecl;
  213. var
  214. s_pixel, r, g, b, a: Uint32;
  215. d_ptr: PUint8;
  216. count: DWord;
  217. source, dest: PUint8;
  218. begin
  219. d_ptr := PUint8(@s_pixel) + (R_32 - R_24);
  220. source := iface^.s_pixels; dest := iface^.d_pixels;
  221. repeat
  222. count := iface^.s_width;
  223. repeat
  224. s_pixel := ((PUint32(source+R_24)^) shl 16) or
  225. ((PUint32(source+G_24)^) shl 8) or
  226. (PUint32(source+B_24)^);
  227. r := ((s_pixel shl iface^.info.r_left) shr iface^.info.r_right) and
  228. iface^.mask_r;
  229. g := ((s_pixel shl iface^.info.g_left) shr iface^.info.g_right) and
  230. iface^.mask_g;
  231. b := ((s_pixel shl iface^.info.b_left) shr iface^.info.b_right) and
  232. iface^.mask_b;
  233. a := ((s_pixel shl iface^.info.a_left) shr iface^.info.a_right) and
  234. iface^.mask_a;
  235. s_pixel := r or g or b or a;
  236. (dest + 0)^ := (d_ptr + 0)^;
  237. (dest + 1)^ := (d_ptr + 1)^;
  238. (dest + 2)^ := (d_ptr + 2)^;
  239. Inc(source, 3);
  240. Inc(dest, 3);
  241. Dec(count);
  242. until count = 0;
  243. Inc(source, iface^.s_add);
  244. Inc(dest, iface^.d_add);
  245. Dec(iface^.s_height);
  246. until iface^.s_height = 0;
  247. end;
  248. procedure ConvertP_Generic24_A_Generic16_A(iface: PHermesConverterInterface); cdecl;
  249. var
  250. s_pixel, r, g, b, a: Uint32;
  251. count: DWord;
  252. source, dest: PUint8;
  253. begin
  254. source := iface^.s_pixels; dest := iface^.d_pixels;
  255. repeat
  256. count := iface^.s_width;
  257. repeat
  258. s_pixel := ((PUint32(source+R_24)^) shl 16) or
  259. ((PUint32(source+G_24)^) shl 8) or
  260. (PUint32(source+B_24)^);
  261. r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
  262. iface^.mask_r;
  263. g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
  264. iface^.mask_g;
  265. b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
  266. iface^.mask_b;
  267. a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
  268. iface^.mask_a;
  269. PUint16(dest)^ := r or g or b or a;
  270. Inc(source, 3);
  271. Inc(dest, 2);
  272. Dec(count);
  273. until count = 0;
  274. Inc(source, iface^.s_add);
  275. Inc(dest, iface^.d_add);
  276. Dec(iface^.s_height);
  277. until iface^.s_height = 0;
  278. end;
  279. procedure ConvertP_Generic24_A_Generic8_A(iface: PHermesConverterInterface); cdecl;
  280. var
  281. s_pixel, r, g, b, a: Uint32;
  282. count: DWord;
  283. source, dest: PUint8;
  284. begin
  285. source := iface^.s_pixels; dest := iface^.d_pixels;
  286. repeat
  287. count := iface^.s_width;
  288. repeat
  289. s_pixel := ((PUint32(source+R_24)^) shl 16) or
  290. ((PUint32(source+G_24)^) shl 8) or
  291. (PUint32(source+B_24)^);
  292. r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
  293. iface^.mask_r;
  294. g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
  295. iface^.mask_g;
  296. b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
  297. iface^.mask_b;
  298. a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
  299. iface^.mask_a;
  300. dest^ := r or g or b or a;
  301. Inc(source, 3);
  302. Inc(dest);
  303. Dec(count);
  304. until count = 0;
  305. Inc(source, iface^.s_add);
  306. Inc(dest, iface^.d_add);
  307. Dec(iface^.s_height);
  308. until iface^.s_height = 0;
  309. end;
  310. procedure ConvertP_Generic16_A_Generic32_A(iface: PHermesConverterInterface); cdecl;
  311. var
  312. s_pixel, r, g, b, a: Uint32;
  313. count: DWord;
  314. source, dest: PUint8;
  315. begin
  316. source := iface^.s_pixels; dest := iface^.d_pixels;
  317. repeat
  318. count := iface^.s_width;
  319. repeat
  320. s_pixel := PUint16(source)^;
  321. r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
  322. iface^.mask_r;
  323. g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
  324. iface^.mask_g;
  325. b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
  326. iface^.mask_b;
  327. a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
  328. iface^.mask_a;
  329. PUint32(dest)^ := r or g or b or a;
  330. Inc(source, 2);
  331. Inc(dest, 4);
  332. Dec(count);
  333. until count = 0;
  334. Inc(source, iface^.s_add);
  335. Inc(dest, iface^.d_add);
  336. Dec(iface^.s_height);
  337. until iface^.s_height = 0;
  338. end;
  339. procedure ConvertP_Generic16_A_Generic24_A(iface: PHermesConverterInterface); cdecl;
  340. var
  341. s_pixel, r, g, b, a: Uint32;
  342. d_ptr: PUint8;
  343. count: DWord;
  344. source, dest: PUint8;
  345. begin
  346. d_ptr := PUint8(@s_pixel) + (R_32 - R_24);
  347. source := iface^.s_pixels; dest := iface^.d_pixels;
  348. repeat
  349. count := iface^.s_width;
  350. repeat
  351. s_pixel := PUint16(source)^;
  352. r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
  353. iface^.mask_r;
  354. g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
  355. iface^.mask_g;
  356. b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
  357. iface^.mask_b;
  358. a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
  359. iface^.mask_a;
  360. s_pixel := r or g or b or a;
  361. (dest + 0)^ := (d_ptr + 0)^;
  362. (dest + 1)^ := (d_ptr + 1)^;
  363. (dest + 2)^ := (d_ptr + 2)^;
  364. Inc(source, 2);
  365. Inc(dest, 3);
  366. Dec(count);
  367. until count = 0;
  368. Inc(source, iface^.s_add);
  369. Inc(dest, iface^.d_add);
  370. Dec(iface^.s_height);
  371. until iface^.s_height = 0;
  372. end;
  373. procedure ConvertP_Generic16_A_Generic16_A(iface: PHermesConverterInterface); cdecl;
  374. var
  375. s_pixel, r, g, b, a: Uint32;
  376. count: DWord;
  377. source, dest: PUint8;
  378. begin
  379. source := iface^.s_pixels; dest := iface^.d_pixels;
  380. repeat
  381. count := iface^.s_width;
  382. repeat
  383. s_pixel := PUint16(source)^;
  384. r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
  385. iface^.mask_r;
  386. g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
  387. iface^.mask_g;
  388. b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
  389. iface^.mask_b;
  390. a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
  391. iface^.mask_a;
  392. PUint16(dest)^ := r or g or b or a;
  393. Inc(source, 2);
  394. Inc(dest, 2);
  395. Dec(count);
  396. until count = 0;
  397. Inc(source, iface^.s_add);
  398. Inc(dest, iface^.d_add);
  399. Dec(iface^.s_height);
  400. until iface^.s_height = 0;
  401. end;
  402. procedure ConvertP_Generic16_A_Generic8_A(iface: PHermesConverterInterface); cdecl;
  403. var
  404. s_pixel, r, g, b, a: Uint32;
  405. count: DWord;
  406. source, dest: PUint8;
  407. begin
  408. source := iface^.s_pixels; dest := iface^.d_pixels;
  409. repeat
  410. count := iface^.s_width;
  411. repeat
  412. s_pixel := PUint16(source)^;
  413. r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
  414. iface^.mask_r;
  415. g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
  416. iface^.mask_g;
  417. b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
  418. iface^.mask_b;
  419. a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
  420. iface^.mask_a;
  421. dest^ := r or g or b or a;
  422. Inc(source, 2);
  423. Inc(dest);
  424. Dec(count);
  425. until count = 0;
  426. Inc(source, iface^.s_add);
  427. Inc(dest, iface^.d_add);
  428. Dec(iface^.s_height);
  429. until iface^.s_height = 0;
  430. end;
  431. { -------------------------------------------------------------------------
  432. STRETCH CONVERTERS
  433. ------------------------------------------------------------------------- }
  434. procedure ConvertP_Generic32_A_Generic32_A_S(iface: PHermesConverterInterface); cdecl;
  435. var
  436. s_pixel, r, g, b, a: Uint32;
  437. count: DWord;
  438. source, dest: PUint8;
  439. dx, dy, x, y: DWord;
  440. begin
  441. source := iface^.s_pixels;
  442. dest := iface^.d_pixels;
  443. dy := (iface^.s_height shl 16) div iface^.d_height;
  444. dx := (iface^.s_width shl 16) div iface^.d_width;
  445. y := 0;
  446. repeat
  447. count := iface^.d_width;
  448. x := 0;
  449. repeat
  450. s_pixel := (PUint32(source)+(x shr 16))^;
  451. r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
  452. iface^.mask_r;
  453. g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
  454. iface^.mask_g;
  455. b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
  456. iface^.mask_b;
  457. a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
  458. iface^.mask_a;
  459. PUint32(dest)^ := r or g or b or a;
  460. Inc(x, dx);
  461. Inc(dest, 4);
  462. Dec(count);
  463. until count = 0;
  464. Inc(dest, iface^.d_add);
  465. Inc(y, dy);
  466. Inc(source, (y shr 16)*DWord(iface^.s_pitch));
  467. y := y and $ffff;
  468. Dec(iface^.d_height);
  469. until iface^.d_height = 0;
  470. end;
  471. procedure ConvertP_Generic32_A_Generic16_A_S(iface: PHermesConverterInterface); cdecl;
  472. var
  473. s_pixel, r, g, b, a: Uint32;
  474. count: DWord;
  475. source, dest: PUint8;
  476. dx, dy, x, y: DWord;
  477. begin
  478. source := iface^.s_pixels;
  479. dest := iface^.d_pixels;
  480. dy := (iface^.s_height shl 16) div iface^.d_height;
  481. dx := (iface^.s_width shl 16) div iface^.d_width;
  482. y := 0;
  483. repeat
  484. count := iface^.d_width;
  485. x := 0;
  486. repeat
  487. s_pixel := (PUint32(source)+(x shr 16))^;
  488. r := ((s_pixel shr iface^.info.r_right) shl iface^.info.r_left) and
  489. iface^.mask_r;
  490. g := ((s_pixel shr iface^.info.g_right) shl iface^.info.g_left) and
  491. iface^.mask_g;
  492. b := ((s_pixel shr iface^.info.b_right) shl iface^.info.b_left) and
  493. iface^.mask_b;
  494. a := ((s_pixel shr iface^.info.a_right) shl iface^.info.a_left) and
  495. iface^.mask_a;
  496. PUint16(dest)^ := r or g or b or a;
  497. Inc(x, dx);
  498. Inc(dest, 2);
  499. Dec(count);
  500. until count = 0;
  501. Inc(dest, iface^.d_add);
  502. Inc(y, dy);
  503. Inc(source, (y shr 16)*DWord(iface^.s_pitch));
  504. y := y and $ffff;
  505. Dec(iface^.d_height);
  506. until iface^.d_height = 0;
  507. end;