p_i8.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. }
  17. {
  18. Generic C converter (from 8 bit indexed) for the HERMES library
  19. Copyright (c) 1998 Christian Nentwich ([email protected])
  20. This source code is licensed under the GNU LGPL
  21. Please refer to the file COPYING.LIB contained in the distribution for
  22. licensing conditions
  23. }
  24. { -------------------------------------------------------------------------
  25. NORMAL CONVERTERS
  26. ------------------------------------------------------------------------- }
  27. Procedure ConvertP_index8_32(iface : PHermesConverterInterface); CDecl;
  28. Var
  29. i : Integer;
  30. s_pixel : char8;
  31. d_pixel : int32;
  32. source, dest : Pchar8;
  33. Begin
  34. source := iface^.s_pixels;
  35. dest := iface^.d_pixels;
  36. Repeat
  37. For i := 0 To iface^.s_width - 1 Do
  38. Begin
  39. s_pixel := source^;
  40. d_pixel := iface^.lookup[s_pixel];
  41. Pint32(dest)^ := d_pixel;
  42. Inc(source);
  43. Inc(dest, 4);
  44. End;
  45. Inc(source, iface^.s_add);
  46. Inc(dest, iface^.d_add);
  47. Dec(iface^.s_height);
  48. Until iface^.s_height = 0;
  49. End;
  50. Procedure ConvertP_index8_24(iface : PHermesConverterInterface); CDecl;
  51. Var
  52. count : Integer;
  53. s_pixel, s_pixel2, d_pixel : int32;
  54. d_ptr, source, dest : Pchar8;
  55. Begin
  56. d_ptr := @d_pixel;
  57. source := iface^.s_pixels;
  58. dest := iface^.d_pixels;
  59. Repeat
  60. count := iface^.d_width Shr 2;
  61. While count <> 0 Do
  62. Begin
  63. Dec(count);
  64. s_pixel := iface^.lookup[source^]; Inc(source);
  65. s_pixel2 := iface^.lookup[source^]; Inc(source);
  66. s_pixel := (s_pixel And $ffffff) Or (s_pixel2 Shl 24);
  67. Pint32(dest)^ := s_pixel;
  68. s_pixel := iface^.lookup[source^]; Inc(source);
  69. s_pixel2 := ((s_pixel2 Shr 8) And $ffff) Or (s_pixel Shl 16);
  70. Pint32(dest + 4)^ := s_pixel2;
  71. s_pixel2 := iface^.lookup[source^]; Inc(source);
  72. s_pixel := ((s_pixel Shr 16) And $ff) Or (s_pixel2 Shl 8);
  73. Pint32(dest + 8)^ := s_pixel;
  74. Inc(dest, 12);
  75. End;
  76. count := iface^.d_width And $3;
  77. While count <> 0 Do
  78. Begin
  79. Dec(count);
  80. d_pixel := iface^.lookup[source^]; Inc(source);
  81. (dest + R_24)^ := (d_ptr + R_32)^;
  82. (dest + G_24)^ := (d_ptr + G_32)^;
  83. (dest + B_24)^ := (d_ptr + B_32)^;
  84. Inc(dest, 3);
  85. End;
  86. Inc(source, iface^.s_add);
  87. Inc(dest, iface^.d_add);
  88. Dec(iface^.d_height);
  89. Until iface^.d_height = 0;
  90. End;
  91. Procedure ConvertP_index8_16(iface : PHermesConverterInterface); CDecl;
  92. Var
  93. source, dest : Pchar8;
  94. count, c : DWord;
  95. Begin
  96. source := iface^.s_pixels;
  97. dest := iface^.d_pixels;
  98. Repeat
  99. count := iface^.s_width;
  100. If (PtrUInt(dest) And $3) <> 0 Then
  101. Begin
  102. Pshort16(dest)^ := iface^.lookup[source^]; Inc(source);
  103. Inc(dest, 2);
  104. Dec(count);
  105. End;
  106. c := count Shr 1;
  107. If c <> 0 Then
  108. Repeat
  109. Pint32(dest)^ := iface^.lookup[source^] Or
  110. (iface^.lookup[(source + 1)^] Shl 16);
  111. Inc(dest, 4);
  112. Inc(source, 2);
  113. Dec(c);
  114. Until c = 0;
  115. If (count And 1) <> 0 Then
  116. Begin
  117. Pshort16(dest)^ := iface^.lookup[source^];
  118. Inc(source);
  119. Inc(dest, 2);
  120. End;
  121. Inc(source, iface^.s_add);
  122. Inc(dest, iface^.d_add);
  123. Dec(iface^.s_height);
  124. Until iface^.s_height = 0;
  125. End;
  126. Procedure ConvertP_index8_8(iface : PHermesConverterInterface); CDecl;
  127. Var
  128. source, dest : Pchar8;
  129. count, c : DWord;
  130. Begin
  131. source := iface^.s_pixels;
  132. dest := iface^.d_pixels;
  133. Repeat
  134. count := iface^.s_width;
  135. If (PtrUInt(dest) And $3) <> 0 Then
  136. Begin
  137. dest^ := iface^.lookup[source^]; Inc(source);
  138. Inc(dest);
  139. Dec(count);
  140. End;
  141. c := count Shr 2;
  142. If c <> 0 Then
  143. Repeat
  144. Pint32(dest)^ := iface^.lookup[source^] Or
  145. (iface^.lookup[(source + 1)^] Shl 8) Or
  146. (iface^.lookup[(source + 2)^] Shl 16) Or
  147. (iface^.lookup[(source + 3)^] Shl 24);
  148. Inc(dest, 4);
  149. Inc(source, 4);
  150. Dec(c);
  151. Until c = 0;
  152. count := count And $03;
  153. While count > 0 Do
  154. Begin
  155. dest^ := iface^.lookup[source^]; Inc(source);
  156. Inc(dest);
  157. Dec(count);
  158. End;
  159. Inc(source, iface^.s_add);
  160. Inc(dest, iface^.d_add);
  161. Dec(iface^.s_height);
  162. Until iface^.s_height = 0;
  163. End;
  164. { -------------------------------------------------------------------------
  165. STRETCH CONVERTERS
  166. ------------------------------------------------------------------------- }
  167. Procedure ConvertP_index8_32_S(iface : PHermesConverterInterface); CDecl;
  168. Var
  169. x, y, count : DWord;
  170. dx, dy : DWord;
  171. source : Pchar8;
  172. Begin
  173. y := 0;
  174. dy := (iface^.s_height Shl 16) Div iface^.d_height;
  175. dx := (iface^.s_width Shl 16) Div iface^.d_width;
  176. source := iface^.s_pixels;
  177. Repeat
  178. count := iface^.d_width;
  179. x := 0;
  180. Repeat
  181. Pint32(iface^.d_pixels)^ := iface^.lookup[(source + (x Shr 16))^];
  182. Inc(x, dx);
  183. Inc(iface^.d_pixels, 4);
  184. Dec(count);
  185. Until count = 0;
  186. { Go to next destination row }
  187. Inc(iface^.d_pixels, iface^.d_add);
  188. { Calculate amount of rows to move in source surface }
  189. Inc(y, dy);
  190. Inc(source, (y Shr 16) * DWord(iface^.s_pitch));
  191. y := y And $ffff;
  192. Dec(iface^.d_height);
  193. Until iface^.d_height = 0;
  194. End;
  195. {by me!}
  196. Procedure ConvertP_index8_24_S(iface : PHermesConverterInterface); CDecl;
  197. Var
  198. x, y, count : DWord;
  199. dx, dy : DWord;
  200. source, dest : Pchar8;
  201. s_pixel, s_pixel2, d_pixel : int32;
  202. Begin
  203. y := 0;
  204. dy := (iface^.s_height Shl 16) Div iface^.d_height;
  205. dx := (iface^.s_width Shl 16) Div iface^.d_width;
  206. source := iface^.s_pixels;
  207. dest := iface^.d_pixels;
  208. Repeat
  209. x := 0;
  210. count := iface^.d_width Shr 2;
  211. While count <> 0 Do
  212. Begin
  213. Dec(count);
  214. s_pixel := iface^.lookup[(source + (x Shr 16))^]; Inc(x, dx);
  215. s_pixel2 := iface^.lookup[(source + (x Shr 16))^]; Inc(x, dx);
  216. s_pixel := (s_pixel And $ffffff) Or (s_pixel2 Shl 24);
  217. Pint32(dest)^ := s_pixel;
  218. s_pixel := iface^.lookup[(source + (x Shr 16))^]; Inc(x, dx);
  219. s_pixel2 := ((s_pixel2 Shr 8) And $ffff) Or (s_pixel Shl 16);
  220. Pint32(dest + 4)^ := s_pixel2;
  221. s_pixel2 := iface^.lookup[(source + (x Shr 16))^]; Inc(x, dx);
  222. s_pixel := ((s_pixel Shr 16) And $ff) Or (s_pixel2 Shl 8);
  223. Pint32(dest + 8)^ := s_pixel;
  224. Inc(dest, 12);
  225. End;
  226. count := iface^.d_width And $3;
  227. While count <> 0 Do
  228. Begin
  229. Dec(count);
  230. d_pixel := iface^.lookup[(source + (x Shr 16))^]; Inc(x, dx);
  231. Pshort16(dest)^ := d_pixel;
  232. Pchar8(dest + 2)^ := d_pixel Shr 16;
  233. Inc(dest, 3);
  234. End;
  235. { Go to next destination row }
  236. { Inc(iface^.d_pixels, iface^.d_add);}
  237. Inc(dest, iface^.d_add);
  238. { Calculate amount of rows to move in source surface }
  239. Inc(y, dy);
  240. Inc(source, (y Shr 16) * DWord(iface^.s_pitch));
  241. y := y And $ffff;
  242. Dec(iface^.d_height);
  243. Until iface^.d_height = 0;
  244. End;
  245. { Quick hack of a index 8 to 16 stretch converter }
  246. Procedure ConvertP_index8_16_S(iface : PHermesConverterInterface); CDecl;
  247. Var
  248. x, y, count : DWord;
  249. dx, dy : DWord;
  250. source, dest : Pchar8;
  251. Begin
  252. y := 0;
  253. dy := (iface^.s_height Shl 16) Div iface^.d_height;
  254. dx := (iface^.s_width Shl 16) Div iface^.d_width;
  255. source := iface^.s_pixels;
  256. dest := iface^.d_pixels;
  257. Repeat
  258. { Do a two pixel at a time loop }
  259. count := iface^.d_width Shr 1;
  260. x := 0;
  261. While count <> 0 Do
  262. Begin
  263. Dec(count);
  264. Pint32(dest)^ := iface^.lookup[(source + (x Shr 16))^] Or
  265. (iface^.lookup[(source + ((x + dx) Shr 16))^] Shl 16);
  266. Inc(x, dx); Inc(x, dx);
  267. Inc(dest, 4);
  268. End;
  269. { Clean up remaining pixel if odd width }
  270. If (iface^.d_width And 1) <> 0 Then
  271. Begin
  272. Pshort16(dest)^ := iface^.lookup[(source + (x Shr 16))^];
  273. Inc(dest, 2);
  274. End;
  275. { Go to next destination row }
  276. Inc(dest, iface^.d_add);
  277. { Calculate amount of rows to move in source surface }
  278. Inc(y, dy);
  279. Inc(source, (y Shr 16) * DWord(iface^.s_pitch));
  280. y := y And $ffff;
  281. Dec(iface^.d_height);
  282. Until iface^.d_height = 0;
  283. End;
  284. Procedure ConvertP_index8_8_S(iface : PHermesConverterInterface); CDecl;
  285. Var
  286. x, y, count, c : DWord;
  287. dx, dy : DWord;
  288. source, dest : Pchar8;
  289. Begin
  290. y := 0;
  291. dy := (iface^.s_height Shl 16) Div iface^.d_height;
  292. dx := (iface^.s_width Shl 16) Div iface^.d_width;
  293. source := iface^.s_pixels;
  294. dest := iface^.d_pixels;
  295. Repeat
  296. { Do a four pixel at a time loop }
  297. count := iface^.d_width;
  298. x := 0;
  299. While ((PtrUInt(dest) And 3) <> 0) And (count > 0) Do
  300. Begin
  301. Dec(count);
  302. dest^ := iface^.lookup[(source + (x Shr 16))^];
  303. Inc(x, dx);
  304. Inc(dest);
  305. End;
  306. c := count Shr 2;
  307. count := count And 3;
  308. While c <> 0 Do
  309. Begin
  310. Dec(c);
  311. Pint32(dest)^ := iface^.lookup[(source + (x Shr 16))^] Or
  312. (iface^.lookup[(source + ((x + dx) Shr 16))^] Shl 8) Or
  313. (iface^.lookup[(source + ((x + (dx Shl 1)) Shr 16))^] Shl 16) Or
  314. (iface^.lookup[(source + ((x + dx + (dx Shl 1)) Shr 16))^] Shl 24);
  315. Inc(x, dx Shl 2);
  316. Inc(dest, 4);
  317. End;
  318. While count > 0 Do
  319. Begin
  320. Dec(count);
  321. dest^ := iface^.lookup[(source + (x Shr 16))^];
  322. Inc(dest);
  323. End;
  324. { Go to next destination row }
  325. Inc(dest, iface^.d_add);
  326. { Calculate amount of rows to move in source surface }
  327. Inc(y, dy);
  328. Inc(source, (y Shr 16) * DWord(iface^.s_pitch));
  329. y := y And $ffff;
  330. Dec(iface^.d_height);
  331. Until iface^.d_height = 0;
  332. End;