p_clr.inc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. }
  28. {
  29. C surface clearing 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 ClearP_32(iface: PHermesClearInterface); cdecl;
  36. var
  37. count: DWord;
  38. value: Uint32;
  39. dest: PUint8;
  40. begin
  41. value := iface^.value;
  42. dest := iface^.dest;
  43. repeat
  44. count := iface^.width;
  45. repeat
  46. PUint32(dest)^ := value;
  47. Inc(dest, 4);
  48. Dec(count);
  49. until count = 0;
  50. Inc(dest, iface^.add);
  51. Dec(iface^.height);
  52. until iface^.height = 0;
  53. end;
  54. procedure ClearP_24(iface: PHermesClearInterface); cdecl;
  55. var
  56. p_value: PUint8;
  57. count: DWord;
  58. dest: PUint8;
  59. begin
  60. p_value := PUint8(@iface^.value) + (R_32 - R_24);
  61. dest := iface^.dest;
  62. repeat
  63. count := iface^.width;
  64. repeat
  65. (dest + 0)^ := (p_value + 0)^;
  66. (dest + 1)^ := (p_value + 1)^;
  67. (dest + 2)^ := (p_value + 2)^;
  68. Inc(dest, 3);
  69. Dec(count);
  70. until count = 0;
  71. Inc(dest, iface^.add);
  72. Dec(iface^.height);
  73. until iface^.height = 0;
  74. end;
  75. procedure ClearP_16(iface: PHermesClearInterface); cdecl;
  76. var
  77. value32: DWord;
  78. countshifted, count: DWord;
  79. dest: PUint8;
  80. begin
  81. value32 := (iface^.value shl 16) or (iface^.value and $ffff);
  82. dest := iface^.dest;
  83. repeat
  84. count := iface^.width;
  85. { Align destination }
  86. if (PtrUInt(dest) and $3) <> 0 then
  87. begin
  88. PUint16(dest)^ := iface^.value;
  89. Inc(dest, 2);
  90. Dec(count);
  91. end;
  92. countshifted := count shr 1;
  93. while countshifted <> 0 do
  94. begin
  95. Dec(countshifted);
  96. PUint32(dest)^ := value32;
  97. Inc(dest, 4);
  98. end;
  99. if (count and 1) <> 0 then
  100. begin
  101. PUint16(dest)^ := iface^.value;
  102. Inc(dest, 2);
  103. end;
  104. Inc(dest, iface^.add);
  105. Dec(iface^.height);
  106. until iface^.height = 0;
  107. end;
  108. {$GOTO ON}
  109. procedure ClearP_8(iface: PHermesClearInterface); cdecl;
  110. label
  111. yloop;
  112. var
  113. count, shiftcount: DWord;
  114. value32: Uint32;
  115. value: Uint8;
  116. dest: PUint8;
  117. begin
  118. dest := iface^.dest;
  119. value := iface^.value and $ff;
  120. value32 := (value shl 24) or (value shl 16) or (value shl 8) or value;
  121. repeat
  122. count := iface^.width;
  123. while (PtrUInt(dest) and $3) <> 0 do { Align to dword boundary }
  124. begin
  125. dest^ := value;
  126. Inc(dest);
  127. Dec(count);
  128. if count = 0 then
  129. goto yloop; { GOTO's are nice ;) }
  130. end;
  131. shiftcount := count shr 2;
  132. while shiftcount <> 0 do
  133. begin
  134. Dec(shiftcount);
  135. PUint32(dest)^ := value32;
  136. Inc(dest, 4);
  137. end;
  138. count := count and $3;
  139. while count <> 0 do
  140. begin
  141. Dec(count);
  142. dest^ := value;
  143. Inc(dest);
  144. end;
  145. yloop:
  146. Inc(dest, iface^.add);
  147. Dec(iface^.height);
  148. until iface^.height = 0;
  149. end;