p_cpy.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. C straight copy routines 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. Procedure CopyP_4byte(source, dest : Pchar8; count, inc_source : DWord); CDecl;
  25. Begin
  26. Move(source^, dest^, count Shl 2);
  27. End;
  28. Procedure CopyP_3byte(source, dest : Pchar8; count, inc_source : DWord); CDecl;
  29. Begin
  30. Move(source^, dest^, count * 3);
  31. End;
  32. Procedure CopyP_2byte(source, dest : Pchar8; count, inc_source : DWord); CDecl;
  33. Begin
  34. Move(source^, dest^, count Shl 1);
  35. End;
  36. Procedure CopyP_1byte(source, dest : Pchar8; count, inc_source : DWord); CDecl;
  37. Begin
  38. Move(source^, dest^, count);
  39. End;
  40. Procedure CopyP_4byte_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
  41. Var
  42. x : DWord;
  43. Begin
  44. x := 0;
  45. Repeat
  46. Pint32(dest)^ := (Pint32(source)+(x Shr 16))^;
  47. Inc(x, inc_source);
  48. Inc(dest, 4);
  49. Dec(count);
  50. Until count = 0;
  51. End;
  52. { TODO: Optimise }
  53. Procedure CopyP_3byte_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
  54. Var
  55. x : DWord;
  56. Begin
  57. x := 0;
  58. Repeat
  59. dest[R_24] := source[R_24];
  60. dest[G_24] := source[G_24];
  61. dest[B_24] := source[B_24];
  62. Inc(x, inc_source);
  63. Inc(source, 3*(x Shr 16));
  64. x := x And $FFFF;
  65. Inc(dest, 3);
  66. Dec(count);
  67. Until count = 0;
  68. End;
  69. Procedure CopyP_2byte_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
  70. Var
  71. x, c : DWord;
  72. p : int32;
  73. Begin
  74. x := 0;
  75. { Alignment mod 4 }
  76. If (PtrUInt(dest) And 3) <> 0 Then
  77. Begin
  78. Pshort16(dest)^ := (Pshort16(source) + (x Shr 16))^;
  79. Inc(x, inc_source);
  80. Inc(dest, 2);
  81. Dec(count);
  82. End;
  83. c := count Shr 1;
  84. While c <> 0 Do
  85. Begin
  86. Dec(c);
  87. { TODO: make fast :) }
  88. p := (Pshort16(source) + (x Shr 16))^; Inc(x, inc_source);
  89. p := p Or ((Pshort16(source) + (x Shr 16))^ Shl 16);
  90. Inc(x, inc_source);
  91. Pint32(dest)^ := p;
  92. Inc(dest, 4);
  93. End;
  94. If (count And 1) <> 0 Then
  95. Pshort16(dest)^ := (Pshort16(source) + (x Shr 16))^;
  96. End;
  97. Procedure CopyP_1byte_S(source, dest : Pchar8; count, inc_source : DWord); CDecl;
  98. Var
  99. x, c : DWord;
  100. p : int32;
  101. Begin
  102. x := 0;
  103. { Alignment mod 4 }
  104. While (PtrUInt(dest) And 3) <> 0 Do
  105. Begin
  106. dest^ := (source + (x Shr 16))^;
  107. Inc(x, inc_source);
  108. Inc(dest); Dec(count);
  109. If count = 0 Then
  110. Exit;
  111. End;
  112. { Write blocks of four pixels }
  113. c := count Shr 2;
  114. While c <> 0 Do
  115. Begin
  116. Dec(c);
  117. p := (source + (x Shr 16))^; Inc(x, inc_source);
  118. p := p Or ((source + (x Shr 16))^ Shl 8); Inc(x, inc_source);
  119. p := p Or ((source + (x Shr 16))^ Shl 16); Inc(x, inc_source);
  120. p := p Or ((source + (x Shr 16))^ Shl 24); Inc(x, inc_source);
  121. Pint32(dest)^ := p;
  122. Inc(dest, 4);
  123. End;
  124. { Write up to three trailing pixels }
  125. c := count And $3;
  126. While c <> 0 Do
  127. Begin
  128. Dec(c);
  129. dest^ := (source + (x Shr 16))^;
  130. Inc(x, inc_source);
  131. Inc(dest);
  132. End;
  133. End;