p_muhmu.inc 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  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. muhmuh converters 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. { TO 32 RGB }
  36. procedure ConvertP_muhmu32_32rgb888(source, dest: PUint8; count, inc_source: DWord); cdecl;
  37. var
  38. s_pixel: Uint32;
  39. begin
  40. repeat
  41. s_pixel := PUint32(source)^;
  42. PUint32(dest)^ := (s_pixel and $ff) or
  43. ((s_pixel and ($ff shl 10)) shr 2) or
  44. ((s_pixel and ($ff shl 20)) shr 4);
  45. Inc(dest, 4);
  46. Inc(source, 4);
  47. Dec(count);
  48. until count = 0;
  49. end;
  50. { TO 32 BGR }
  51. procedure ConvertP_muhmu32_32bgr888(source, dest: PUint8; count, inc_source: DWord); cdecl;
  52. var
  53. s_pixel: Uint32;
  54. begin
  55. repeat
  56. s_pixel := PUint32(source)^;
  57. PUint32(dest)^ := ((s_pixel and $ff) shl 16) or
  58. ((s_pixel and ($ff shl 10)) shr 2) or
  59. ((s_pixel shr 20) and $FF);
  60. Inc(dest, 4);
  61. Inc(source, 4);
  62. Dec(count);
  63. until count = 0;
  64. end;
  65. { TO 32 RGBA }
  66. procedure ConvertP_muhmu32_32rgba888(source, dest: PUint8; count, inc_source: DWord); cdecl;
  67. var
  68. s_pixel: Uint32;
  69. begin
  70. repeat
  71. s_pixel := PUint32(source)^;
  72. PUint32(dest)^ := (((s_pixel and $ff) or
  73. ((s_pixel and ($ff shl 10)) shr 2) or
  74. ((s_pixel and ($ff shl 20)) shr 4)) shl 8) or $FF;
  75. Inc(dest, 4);
  76. Inc(source, 4);
  77. Dec(count);
  78. until count = 0;
  79. end;
  80. { TO 32 BGRA }
  81. procedure ConvertP_muhmu32_32bgra888(source, dest: PUint8; count, inc_source: DWord); cdecl;
  82. var
  83. s_pixel: Uint32;
  84. begin
  85. repeat
  86. s_pixel := PUint32(source)^;
  87. PUint32(dest)^ := (((s_pixel and $ff) shl 24) or
  88. ((s_pixel and ($ff shl 10)) shl 6) or
  89. ((s_pixel shr 12) and $FF00)) or $FF;
  90. Inc(dest, 4);
  91. Inc(source, 4);
  92. Dec(count);
  93. until count = 0;
  94. end;
  95. { TO 24 RGB }
  96. procedure ConvertP_muhmu32_24rgb888(source, dest: PUint8; count, inc_source: DWord); cdecl;
  97. var
  98. s_pixel: Uint32;
  99. s_point: PUint8;
  100. begin
  101. s_point := PUint8(@s_pixel) + (R_32 - R_24);
  102. repeat
  103. s_pixel := PUint32(source)^;
  104. s_pixel := (s_pixel and $ff) or
  105. ((s_pixel and ($ff shl 10)) shr 2) or
  106. ((s_pixel and ($ff shl 20)) shr 4);
  107. (dest+0)^ := (s_point+0)^;
  108. (dest+1)^ := (s_point+1)^;
  109. (dest+2)^ := (s_point+2)^;
  110. Inc(source, 4);
  111. Inc(dest, 3);
  112. Dec(count);
  113. until count = 0;
  114. end;
  115. { TO 24 BGR }
  116. procedure ConvertP_muhmu32_24bgr888(source, dest: PUint8; count, inc_source: DWord); cdecl;
  117. var
  118. s_pixel: Uint32;
  119. s_point: PUint8;
  120. begin
  121. s_point := PUint8(@s_pixel) + (R_32 - R_24);
  122. repeat
  123. s_pixel := PUint32(source)^;
  124. s_pixel := (s_pixel and $ff) or
  125. ((s_pixel and ($ff shl 10)) shr 2) or
  126. ((s_pixel and ($ff shl 20)) shr 4);
  127. { Note that R and B are swapped }
  128. (dest+0)^ := (s_point+2)^;
  129. (dest+1)^ := (s_point+1)^;
  130. (dest+2)^ := (s_point+0)^;
  131. Inc(source, 4);
  132. Inc(dest, 3);
  133. Dec(count);
  134. until count = 0;
  135. end;
  136. { TO 16 RGB 565 }
  137. procedure ConvertP_muhmu32_16rgb565(source, dest: PUint8; count, inc_source: DWord); cdecl;
  138. var
  139. i: DWord;
  140. r, g, b: Uint32;
  141. s_pixel, d_pixelblock: Uint32;
  142. d_pixel: Uint16;
  143. begin
  144. { if the current pixel isn't dword aligned, try write one pixel first }
  145. if (PtrUInt(dest) and $3) <> 0 then
  146. begin
  147. s_pixel := PUint32(source)^;
  148. r := (s_pixel shr 12) and $f800;
  149. g := (s_pixel shr 7) and $7e0;
  150. b := (s_pixel shr 3) and $1f;
  151. d_pixel := r or g or b;
  152. PUint16(dest)^ := d_pixel;
  153. Inc(source, 4);
  154. Inc(dest, 2);
  155. Dec(count);
  156. end;
  157. { Write blocks of two pixels }
  158. for i := 1 to count shr 1 do
  159. begin
  160. s_pixel := PUint32(source)^;
  161. d_pixelblock := (((s_pixel shr 12) and $f800) or
  162. ((s_pixel shr 7) and $7e0) or
  163. ((s_pixel shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
  164. s_pixel := (PUint32(source) + 1)^;
  165. d_pixelblock := d_pixelblock or
  166. ((((s_pixel shr 12) and $f800) or
  167. ((s_pixel shr 7) and $7e0) or
  168. ((s_pixel shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
  169. PUint32(dest)^ := d_pixelblock;
  170. Inc(source, 8); Inc(dest, 4);
  171. end;
  172. { Eventually, write a single odd pixel that might be left }
  173. if (count and 1) <> 0 then
  174. begin
  175. s_pixel := PUint32(source)^;
  176. r := (s_pixel shr 12) and $f800;
  177. g := (s_pixel shr 7) and $7e0;
  178. b := (s_pixel shr 3) and $1f;
  179. d_pixel := r or g or b;
  180. PUint16(dest)^ := d_pixel;
  181. end;
  182. end;
  183. { TO 16 BGR 565 }
  184. procedure ConvertP_muhmu32_16bgr565(source, dest: PUint8; count, inc_source: DWord); cdecl;
  185. var
  186. i: DWord;
  187. r, g, b: Uint32;
  188. s_pixel, d_pixelblock: Uint32;
  189. d_pixel: Uint16;
  190. begin
  191. { if the current pixel isn't dword aligned, try write one pixel first }
  192. if (PtrUInt(dest) and $3) <> 0 then
  193. begin
  194. s_pixel := PUint32(source)^;
  195. r := (s_pixel shr 23) and $1f;
  196. g := (s_pixel shr 7) and $7e0;
  197. b := (s_pixel shl 8) and $f800;
  198. d_pixel := r or g or b;
  199. PUint16(dest)^ := d_pixel;
  200. Inc(source, 4);
  201. Inc(dest, 2);
  202. Dec(count);
  203. end;
  204. { Write blocks of two pixels }
  205. for i := 1 to count shr 1 do
  206. begin
  207. s_pixel := PUint32(source)^;
  208. d_pixelblock := (((s_pixel shr 23) and $1f) or
  209. ((s_pixel shr 7) and $7e0) or
  210. ((s_pixel shl 8) and $f800)) shl DWORD_SMALLINT0_SHL;
  211. s_pixel := (PUint32(source) + 1)^;
  212. d_pixelblock := d_pixelblock or
  213. ((((s_pixel shr 23) and $1f) or
  214. ((s_pixel shr 7) and $7e0) or
  215. ((s_pixel shl 8) and $f800)) shl DWORD_SMALLINT1_SHL);
  216. PUint32(dest)^ := d_pixelblock;
  217. Inc(source, 8); Inc(dest, 4);
  218. end;
  219. { Eventually, write a single odd pixel that might be left }
  220. if (count and 1) <> 0 then
  221. begin
  222. s_pixel := PUint32(source)^;
  223. r := (s_pixel shr 23) and $1f;
  224. g := (s_pixel shr 7) and $7e0;
  225. b := (s_pixel shl 8) and $f800;
  226. d_pixel := r or g or b;
  227. PUint16(dest)^ := d_pixel;
  228. end;
  229. end;
  230. { TO 16 RGB 555 }
  231. procedure ConvertP_muhmu32_16rgb555(source, dest: PUint8; count, inc_source: DWord); cdecl;
  232. var
  233. i: DWord;
  234. r, g, b: Uint32;
  235. s_pixel, d_pixelblock: Uint32;
  236. d_pixel: Uint16;
  237. begin
  238. if (PtrUInt(dest) and $3) <> 0 then
  239. begin
  240. s_pixel := PUint32(source)^;
  241. r := (s_pixel shr 13) and $7c00;
  242. g := (s_pixel shr 8) and $3e0;
  243. b := (s_pixel shr 3) and $1f;
  244. d_pixel := r or g or b;
  245. PUint16(dest)^ := d_pixel;
  246. Inc(source, 4);
  247. Inc(dest, 2);
  248. Dec(count);
  249. end;
  250. for i := 1 to count shr 1 do
  251. begin
  252. s_pixel := PUint32(source)^;
  253. d_pixelblock := (((s_pixel shr 13) and $7c00) or
  254. ((s_pixel shr 8) and $3e0) or
  255. ((s_pixel shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
  256. s_pixel := (PUint32(source) + 1)^;
  257. d_pixelblock := d_pixelblock or
  258. ((((s_pixel shr 13) and $7c00) or
  259. ((s_pixel shr 8) and $3e0) or
  260. ((s_pixel shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
  261. PUint32(dest)^ := d_pixelblock;
  262. Inc(source, 8); Inc(dest, 4);
  263. end;
  264. if (count and 1) <> 0 then
  265. begin
  266. s_pixel := PUint32(source)^;
  267. r := (s_pixel shr 13) and $7c00;
  268. g := (s_pixel shr 8) and $3e0;
  269. b := (s_pixel shr 3) and $1f;
  270. d_pixel := r or g or b;
  271. PUint16(dest)^ := d_pixel;
  272. end;
  273. end;
  274. { TO 16 BGR 555 }
  275. procedure ConvertP_muhmu32_16bgr555(source, dest: PUint8; count, inc_source: DWord); cdecl;
  276. var
  277. i: DWord;
  278. r, g, b: Uint32;
  279. s_pixel, d_pixelblock: Uint32;
  280. d_pixel: Uint16;
  281. begin
  282. if (PtrUInt(dest) and $3) <> 0 then
  283. begin
  284. s_pixel := PUint32(source)^;
  285. r := (s_pixel shr 23) and $1f;
  286. g := (s_pixel shr 8) and $3e0;
  287. b := (s_pixel shl 7) and $7c00;
  288. d_pixel := r or g or b;
  289. PUint16(dest)^ := d_pixel;
  290. Inc(source, 4);
  291. Inc(dest, 2);
  292. Dec(count);
  293. end;
  294. for i := 1 to count shr 1 do
  295. begin
  296. s_pixel := PUint32(source)^;
  297. d_pixelblock := (((s_pixel shr 23) and $1f) or
  298. ((s_pixel shr 8) and $3e0) or
  299. ((s_pixel shl 7) and $7c00)) shl DWORD_SMALLINT0_SHL;
  300. s_pixel := (PUint32(source) + 1)^;
  301. d_pixelblock := d_pixelblock or
  302. ((((s_pixel shr 23) and $1f) or
  303. ((s_pixel shr 8) and $3e0) or
  304. ((s_pixel shl 7) and $7c00)) shl DWORD_SMALLINT1_SHL);
  305. PUint32(dest)^ := d_pixelblock;
  306. Inc(source, 8); Inc(dest, 4);
  307. end;
  308. if (count and 1) <> 0 then
  309. begin
  310. s_pixel := PUint32(source)^;
  311. r := (s_pixel shr 23) and $1f;
  312. g := (s_pixel shr 8) and $3e0;
  313. b := (s_pixel shl 7) and $7c00;
  314. d_pixel := r or g or b;
  315. PUint16(dest)^ := d_pixel;
  316. end;
  317. end;
  318. { TO 8 RGB 332 }
  319. procedure ConvertP_muhmu32_8rgb332(source, dest: PUint8; count, inc_source: DWord); cdecl;
  320. var
  321. i: DWord;
  322. s_pixel, d_block: Uint32;
  323. d_pixel: Uint8;
  324. begin
  325. { Process single pixels until we are dword aligned }
  326. while (PtrUInt(dest) and $3) <> 0 do
  327. begin
  328. s_pixel := PUint32(source)^;
  329. d_pixel := ((s_pixel shr 20) and $e0) or
  330. ((s_pixel shr 13) and $1c) or
  331. ((s_pixel shr 6) and $3);
  332. dest^ := d_pixel;
  333. Dec(count);
  334. if count = 0 then
  335. exit;
  336. Inc(dest);
  337. Inc(source, 4);
  338. end;
  339. { Now process blocks of four pixels }
  340. for i := 1 to count shr 2 do
  341. begin
  342. s_pixel := PUint32(source)^;
  343. d_block := (((s_pixel shr 20) and $e0) or
  344. ((s_pixel shr 13) and $1c) or
  345. ((s_pixel shr 6) and $3)) shl DWORD_BYTE0_SHL;
  346. s_pixel := (PUint32(source) + 1)^;
  347. d_block := d_block or
  348. ((((s_pixel shr 20) and $e0) or
  349. ((s_pixel shr 13) and $1c) or
  350. ((s_pixel shr 6) and $3)) shl DWORD_BYTE1_SHL);
  351. s_pixel := (PUint32(source) + 2)^;
  352. d_block := d_block or
  353. ((((s_pixel shr 20) and $e0) or
  354. ((s_pixel shr 13) and $1c) or
  355. ((s_pixel shr 6) and $3)) shl DWORD_BYTE2_SHL);
  356. s_pixel := (PUint32(source) + 3)^;
  357. d_block := d_block or
  358. ((((s_pixel shr 20) and $e0) or
  359. ((s_pixel shr 13) and $1c) or
  360. ((s_pixel shr 6) and $3)) shl DWORD_BYTE3_SHL);
  361. PUint32(dest)^ := d_block;
  362. Inc(source, 16);
  363. Inc(dest, 4);
  364. end;
  365. { Write all possibly remaining pixel }
  366. count := count and 3;
  367. while count <> 0 do
  368. begin
  369. Dec(count);
  370. dest^ := ((s_pixel shr 20) and $e0) or
  371. ((s_pixel shr 13) and $1c) or
  372. ((s_pixel shr 6) and $3);
  373. Inc(dest);
  374. Inc(source, 4);
  375. end;
  376. end;
  377. { -------------------------------------------------------------------------
  378. STRETCH CONVERTERS
  379. ------------------------------------------------------------------------- }
  380. procedure ConvertP_muhmu32_32rgb888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
  381. var
  382. x: DWord;
  383. s_pixel: DWord;
  384. begin
  385. x := 0;
  386. while count > 0 do
  387. begin
  388. s_pixel := PUint32(source)^;
  389. PUint32(dest)^ := (s_pixel and $ff) or
  390. ((s_pixel and ($ff shl 10)) shr 2) or
  391. ((s_pixel and ($ff shl 20)) shr 4);
  392. Inc(x, inc_source);
  393. Inc(source, (x shr 16)*4);
  394. x := x and $FFFF;
  395. Inc(dest, 4);
  396. Dec(count);
  397. end;
  398. end;
  399. procedure ConvertP_muhmu32_32bgr888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
  400. var
  401. x: DWord;
  402. s_pixel: DWord;
  403. begin
  404. x := 0;
  405. while count > 0 do
  406. begin
  407. s_pixel := PUint32(source)^;
  408. PUint32(dest)^ := ((s_pixel and $ff) shl 16) or
  409. ((s_pixel and ($ff shl 10)) shr 2) or
  410. ((s_pixel shr 20) and $FF);
  411. Inc(x, inc_source);
  412. Inc(source, (x shr 16)*4);
  413. x := x and $FFFF;
  414. Inc(dest, 4);
  415. Dec(count);
  416. end;
  417. end;
  418. procedure ConvertP_muhmu32_32rgba888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
  419. var
  420. x: DWord;
  421. s_pixel: DWord;
  422. begin
  423. x := 0;
  424. while count > 0 do
  425. begin
  426. s_pixel := PUint32(source)^;
  427. PUint32(dest)^ := (((s_pixel and $ff) or
  428. ((s_pixel and ($ff shl 10)) shr 2) or
  429. ((s_pixel and ($ff shl 20)) shr 4)) shl 8) or $FF;
  430. Inc(x, inc_source);
  431. Inc(source, (x shr 16)*4);
  432. x := x and $FFFF;
  433. Inc(dest, 4);
  434. Dec(count);
  435. end;
  436. end;
  437. procedure ConvertP_muhmu32_32bgra888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
  438. var
  439. x: DWord;
  440. s_pixel: DWord;
  441. begin
  442. x := 0;
  443. while count > 0 do
  444. begin
  445. s_pixel := PUint32(source)^;
  446. PUint32(dest)^ := (((s_pixel and $ff) shl 24) or
  447. ((s_pixel and ($ff shl 10)) shl 6) or
  448. ((s_pixel shr 12) and $FF00)) or $FF;
  449. Inc(x, inc_source);
  450. Inc(source, (x shr 16)*4);
  451. x := x and $FFFF;
  452. Inc(dest, 4);
  453. Dec(count);
  454. end;
  455. end;
  456. procedure ConvertP_muhmu32_24rgb888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
  457. var
  458. x: DWord;
  459. p1, p2, p3, p4: DWord;
  460. c: DWord;
  461. begin
  462. x := 0;
  463. while (PtrUInt(dest) and 3) <> 0 do
  464. begin
  465. p1 := (PUint32(source) + (x shr 16))^;
  466. p1 := (p1 and $ff) or
  467. ((p1 and ($ff shl 10)) shr 2) or
  468. ((p1 and ($ff shl 20)) shr 4);
  469. PUint8(dest + B_24)^ := p1 and $FF;
  470. PUint8(dest + G_24)^ := (p1 shr 8) and $FF;
  471. PUint8(dest + R_24)^ := p1 shr 16;
  472. Inc(x, inc_source);
  473. Inc(dest, 3);
  474. Dec(count);
  475. if count = 0 then
  476. exit;
  477. end;
  478. c := count shr 2;
  479. while c > 0 do
  480. begin
  481. p1 := (PUint32(source) + (x shr 16))^;
  482. p2 := (PUint32(source) + ((x + inc_source) shr 16))^;
  483. p3 := (PUint32(source) + ((x + 2*inc_source) shr 16))^;
  484. p4 := (PUint32(source) + ((x + 3*inc_source) shr 16))^;
  485. {$IFDEF FPC_LITTLE_ENDIAN}
  486. PUint32(dest + 0)^ := ((p2 and $FF) shl 24) or ((p1 and $FF00000) shr 4) or ((p1 and $3FC00) shr 2) or (p1 and $FF);
  487. PUint32(dest + 4)^ := ((p3 and $3FC00) shl 14) or ((p3 and $FF) shl 16) or ((p2 and $FF00000) shr 12) or ((p2 and $3FC00) shr 10);
  488. PUint32(dest + 8)^ := ((p4 and $FF00000) shl 4) or ((p4 and $3FC00) shl 6) or ((p4 and $FF) shl 8) or ((p3 and $FF00000) shr 20);
  489. {$ELSE FPC_LITTLE_ENDIAN}
  490. PUint32(dest + 0)^ := ((p1 and $FF00000) shl 4) or ((p1 and $3FC00) shl 6) or ((p1 and $FF) shl 8) or ((p2 and $FF00000) shr 20);
  491. PUint32(dest + 4)^ := ((p2 and $3FC00) shl 14) or ((p2 and $FF) shl 16) or ((p3 and $FF00000) shr 12) or ((p3 and $3FC00) shr 10);
  492. PUint32(dest + 8)^ := ((p3 and $FF) shl 24) or ((p4 and $FF00000) shr 4) or ((p4 and $3FC00) shr 2) or (p4 and $FF);
  493. {$ENDIF FPC_LITTLE_ENDIAN}
  494. Dec(c);
  495. Inc(x, inc_source*4);
  496. Inc(dest, 12);
  497. end;
  498. count := count and 3;
  499. while count > 0 do
  500. begin
  501. p1 := (PUint32(source) + (x shr 16))^;
  502. p1 := (p1 and $ff) or
  503. ((p1 and ($ff shl 10)) shr 2) or
  504. ((p1 and ($ff shl 20)) shr 4);
  505. PUint8(dest + B_24)^ := p1 and $FF;
  506. PUint8(dest + G_24)^ := (p1 shr 8) and $FF;
  507. PUint8(dest + R_24)^ := p1 shr 16;
  508. Inc(x, inc_source);
  509. Inc(dest, 3);
  510. Dec(count);
  511. end;
  512. end;
  513. procedure ConvertP_muhmu32_24bgr888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
  514. var
  515. x: DWord;
  516. p1, p2, p3, p4: DWord;
  517. c: DWord;
  518. begin
  519. x := 0;
  520. while (PtrUInt(dest) and 3) <> 0 do
  521. begin
  522. p1 := (PUint32(source) + (x shr 16))^;
  523. p1 := ((p1 and $ff) shl 16) or
  524. ((p1 and ($ff shl 10)) shr 2) or
  525. ((p1 and ($ff shl 20)) shr 20);
  526. PUint8(dest + B_24)^ := p1 and $FF;
  527. PUint8(dest + G_24)^ := (p1 shr 8) and $FF;
  528. PUint8(dest + R_24)^ := p1 shr 16;
  529. Inc(x, inc_source);
  530. Inc(dest, 3);
  531. Dec(count);
  532. if count = 0 then
  533. exit;
  534. end;
  535. c := count shr 2;
  536. while c > 0 do
  537. begin
  538. p1 := (PUint32(source) + (x shr 16))^;
  539. p2 := (PUint32(source) + ((x + inc_source) shr 16))^;
  540. p3 := (PUint32(source) + ((x + 2*inc_source) shr 16))^;
  541. p4 := (PUint32(source) + ((x + 3*inc_source) shr 16))^;
  542. {$IFDEF FPC_LITTLE_ENDIAN}
  543. PUint32(dest + 0)^ := ((p2 and $FF00000) shl 4) or ((p1 and $FF) shl 16) or ((p1 and $3FC00) shr 2) or ((p1 and $FF00000) shr 20);
  544. PUint32(dest + 4)^ := ((p3 and $3FC00) shl 14) or ((p3 and $FF00000) shr 4) or ((p2 and $FF) shl 8) or ((p2 and $3FC00) shr 10);
  545. PUint32(dest + 8)^ := ((p4 and $FF) shl 24) or ((p4 and $3FC00) shl 6) or ((p4 and $FF00000) shr 12) or (p3 and $FF);
  546. {$ELSE FPC_LITTLE_ENDIAN}
  547. PUint32(dest + 0)^ := ((p1 and $FF) shl 24) or ((p1 and $3FC00) shl 6) or ((p1 and $FF00000) shr 12) or (p2 and $FF);
  548. PUint32(dest + 4)^ := ((p2 and $3FC00) shl 14) or ((p2 and $FF00000) shr 4) or ((p3 and $FF) shl 8) or ((p3 and $3FC00) shr 10);
  549. PUint32(dest + 8)^ := ((p3 and $FF00000) shl 4) or ((p4 and $FF) shl 16) or ((p4 and $3FC00) shr 2) or ((p4 and $FF00000) shr 20);
  550. {$ENDIF FPC_LITTLE_ENDIAN}
  551. Dec(c);
  552. Inc(x, inc_source*4);
  553. Inc(dest, 12);
  554. end;
  555. count := count and 3;
  556. while count > 0 do
  557. begin
  558. p1 := (PUint32(source) + (x shr 16))^;
  559. p1 := ((p1 and $ff) shl 16) or
  560. ((p1 and ($ff shl 10)) shr 2) or
  561. ((p1 and ($ff shl 20)) shr 20);
  562. PUint8(dest + B_24)^ := p1 and $FF;
  563. PUint8(dest + G_24)^ := (p1 shr 8) and $FF;
  564. PUint8(dest + R_24)^ := p1 shr 16;
  565. Inc(x, inc_source);
  566. Inc(dest, 3);
  567. Dec(count);
  568. end;
  569. end;
  570. procedure ConvertP_muhmu32_16rgb565_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
  571. var
  572. x, c: DWord;
  573. p: Uint32;
  574. begin
  575. x := 0;
  576. { Try to write 2 pixel blocks }
  577. c := count shr 1;
  578. while c <> 0 do
  579. begin
  580. Dec(c);
  581. p := ((((PUint32(source) + (x shr 16))^ shr 12) and $f800) or
  582. (((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
  583. (((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
  584. Inc(x, inc_source);
  585. p := p or
  586. (((((PUint32(source) + (x shr 16))^ shr 12) and $f800) or
  587. (((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
  588. (((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
  589. Inc(x, inc_source);
  590. PUint32(dest)^ := p;
  591. Inc(dest, 4);
  592. end;
  593. { Write trailing pixel }
  594. if (count and 1) <> 0 then
  595. PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 12) and $f800) or
  596. (((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
  597. (((PUint32(source) + (x shr 16))^ shr 3) and $1f);
  598. end;
  599. procedure ConvertP_muhmu32_16bgr565_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
  600. var
  601. x, c: DWord;
  602. p: Uint32;
  603. begin
  604. x := 0;
  605. { Try to write 2 pixel blocks }
  606. c := count shr 1;
  607. while c <> 0 do
  608. begin
  609. Dec(c);
  610. p := ((((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
  611. (((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
  612. (((PUint32(source) + (x shr 16))^ shl 8) and $f800)) shl DWORD_SMALLINT0_SHL;
  613. Inc(x, inc_source);
  614. p := p or
  615. (((((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
  616. (((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
  617. (((PUint32(source) + (x shr 16))^ shl 8) and $f800)) shl DWORD_SMALLINT1_SHL);
  618. Inc(x, inc_source);
  619. PUint32(dest)^ := p;
  620. Inc(dest, 4);
  621. end;
  622. { Write trailing pixel }
  623. if (count and 1) <> 0 then
  624. PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
  625. (((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
  626. (((PUint32(source) + (x shr 16))^ shl 8) and $f800);
  627. end;
  628. procedure ConvertP_muhmu32_16rgb555_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
  629. var
  630. x, c: DWord;
  631. p: Uint32;
  632. begin
  633. x := 0;
  634. { Try to write 2 pixel blocks }
  635. c := count shr 1;
  636. while c <> 0 do
  637. begin
  638. Dec(c);
  639. p := ((((PUint32(source) + (x shr 16))^ shr 13) and $7c00) or
  640. (((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
  641. (((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
  642. Inc(x, inc_source);
  643. p := p or
  644. (((((PUint32(source) + (x shr 16))^ shr 13) and $7c00) or
  645. (((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
  646. (((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
  647. Inc(x, inc_source);
  648. PUint32(dest)^ := p;
  649. Inc(dest, 4);
  650. end;
  651. { Write trailing pixel }
  652. if (count and 1) <> 0 then
  653. PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 13) and $7c00) or
  654. (((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
  655. (((PUint32(source) + (x shr 16))^ shr 3) and $1f);
  656. end;
  657. procedure ConvertP_muhmu32_16bgr555_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
  658. var
  659. x, c: DWord;
  660. p: Uint32;
  661. begin
  662. x := 0;
  663. { Try to write 2 pixel blocks }
  664. c := count shr 1;
  665. while c <> 0 do
  666. begin
  667. Dec(c);
  668. p := ((((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
  669. (((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
  670. (((PUint32(source) + (x shr 16))^ shl 7) and $7c00)) shl DWORD_SMALLINT0_SHL;
  671. Inc(x, inc_source);
  672. p := p or
  673. (((((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
  674. (((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
  675. (((PUint32(source) + (x shr 16))^ shl 7) and $7c00)) shl DWORD_SMALLINT1_SHL);
  676. Inc(x, inc_source);
  677. PUint32(dest)^ := p;
  678. Inc(dest, 4);
  679. end;
  680. { Write trailing pixel }
  681. if (count and 1) <> 0 then
  682. PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
  683. (((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
  684. (((PUint32(source) + (x shr 16))^ shl 7) and $7c00);
  685. end;
  686. procedure ConvertP_muhmu32_8rgb332_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
  687. var
  688. x, c: DWord;
  689. p: Uint32;
  690. begin
  691. x := 0;
  692. { Write single pixels until the destination address is aligned mod 4 }
  693. while (PtrUInt(dest) and $3) <> 0 do
  694. begin
  695. dest^ := (((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
  696. (((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
  697. (((PUint32(source) + (x shr 16))^ shr 6) and $3);
  698. Inc(x, inc_source);
  699. Inc(dest);
  700. Dec(count);
  701. if count = 0 then
  702. exit;
  703. end;
  704. { Write blocks of four pixels now }
  705. c := count shr 2;
  706. while c <> 0 do
  707. begin
  708. Dec(c);
  709. p := ((((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
  710. (((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
  711. (((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE0_SHL;
  712. Inc(x, inc_source);
  713. p := p or
  714. (((((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
  715. (((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
  716. (((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE1_SHL);
  717. Inc(x, inc_source);
  718. p := p or
  719. (((((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
  720. (((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
  721. (((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE2_SHL);
  722. Inc(x, inc_source);
  723. p := p or
  724. (((((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
  725. (((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
  726. (((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE3_SHL);
  727. Inc(x, inc_source);
  728. PUint32(dest)^ := p;
  729. Inc(dest, 4);
  730. end;
  731. { Write up to three trailing pixels }
  732. c := count and $3;
  733. while c <> 0 do
  734. begin
  735. Dec(c);
  736. dest^ := (((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
  737. (((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
  738. (((PUint32(source) + (x shr 16))^ shr 6) and $3);
  739. Inc(x, inc_source);
  740. Inc(dest);
  741. end;
  742. end;