d_32.inc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. 32 bit to * dithered converters 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 ConvertP_32rgb888_16rgb565_dither(iface : PHermesConverterInterface); CDecl;
  25. Var
  26. source, dest : Pchar8;
  27. d_pixel : int32;
  28. y, count : LongInt;
  29. Begin
  30. y := 0;
  31. source := iface^.s_pixels;
  32. dest := iface^.d_pixels;
  33. While y < iface^.d_height Do
  34. Begin
  35. { Get counter for this scanline }
  36. count := iface^.d_width;
  37. { Check first pixel alignment, correct if necessary }
  38. If (PtrUInt(iface^.d_pixels) And 3) <> 0 Then
  39. Begin
  40. Pshort16(dest)^ :=
  41. DitherTab_r565_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
  42. DitherTab_g565_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
  43. DitherTab_b565_44[count And 3, y And 3, Pint32(source)^ And $ff];
  44. Inc(source, 4);
  45. Inc(dest, 2);
  46. Dec(count);
  47. End;
  48. { Two pixels at a time loop }
  49. While count > 1 Do
  50. Begin
  51. d_pixel :=
  52. DitherTab_r565_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
  53. DitherTab_g565_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
  54. DitherTab_b565_44[count And 3, y And 3, Pint32(source)^ And $ff];
  55. Inc(source, 4);
  56. Dec(count);
  57. d_pixel := d_pixel Or ((
  58. DitherTab_r565_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
  59. DitherTab_g565_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
  60. DitherTab_b565_44[count And 3, y And 3, Pint32(source)^ And $ff]) Shl 16);
  61. Dec(count);
  62. Inc(source, 4);
  63. Pint32(dest)^ := d_pixel;
  64. Inc(dest, 4);
  65. End;
  66. { Convert the odd trailing pixel }
  67. If (iface^.d_width And 1) <> 0 Then
  68. Begin
  69. Pshort16(dest)^ :=
  70. DitherTab_r565_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
  71. DitherTab_g565_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
  72. DitherTab_b565_44[count And 3, y And 3, Pint32(source)^ And $ff];
  73. Inc(source, 4);
  74. Inc(dest, 2);
  75. End;
  76. Inc(source, iface^.s_add);
  77. Inc(dest, iface^.d_add);
  78. Inc(y);
  79. End;
  80. End;
  81. Procedure ConvertP_32rgb888_8rgb332_dither(iface : PHermesConverterInterface); CDecl;
  82. Var
  83. source, dest : Pchar8;
  84. d_pixel : int32;
  85. y, count : LongInt;
  86. Begin
  87. y := 0;
  88. source := iface^.s_pixels;
  89. dest := iface^.d_pixels;
  90. While y < iface^.d_height Do
  91. Begin
  92. { Get counter for this scanline }
  93. count := iface^.d_width;
  94. { TODO: alignment loop }
  95. { Convert 4 pixels at a time }
  96. While count > 3 Do
  97. Begin
  98. d_pixel :=
  99. DitherTab_r332_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
  100. DitherTab_g332_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
  101. DitherTab_b332_44[count And 3, y And 3, Pint32(source)^ And $ff];
  102. Dec(count);
  103. Inc(source, 4);
  104. d_pixel := d_pixel Or ((
  105. DitherTab_r332_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
  106. DitherTab_g332_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
  107. DitherTab_b332_44[count And 3, y And 3, Pint32(source)^ And $ff]) Shl 8);
  108. Dec(count);
  109. Inc(source, 4);
  110. d_pixel := d_pixel Or ((
  111. DitherTab_r332_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
  112. DitherTab_g332_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
  113. DitherTab_b332_44[count And 3, y And 3, Pint32(source)^ And $ff]) Shl 16);
  114. Dec(count);
  115. Inc(source, 4);
  116. d_pixel := d_pixel Or ((
  117. DitherTab_r332_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
  118. DitherTab_g332_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
  119. DitherTab_b332_44[count And 3, y And 3, Pint32(source)^ And $ff]) Shl 24);
  120. Dec(count);
  121. Inc(source, 4);
  122. Pint32(dest)^ := d_pixel;
  123. Inc(dest, 4);
  124. End;
  125. { Write trailing pixels }
  126. While count <> 0 Do
  127. Begin
  128. Dec(count);
  129. dest^ :=
  130. DitherTab_r332_44[count And 3, y And 3, (Pint32(source)^ Shr 16) And $ff] Or
  131. DitherTab_g332_44[count And 3, y And 3, (Pint32(source)^ Shr 8) And $ff] Or
  132. DitherTab_b332_44[count And 3, y And 3, Pint32(source)^ And $ff];
  133. Inc(source, 4);
  134. Inc(dest);
  135. End;
  136. Inc(source, iface^.s_add);
  137. Inc(dest, iface^.d_add);
  138. Inc(y);
  139. End;
  140. End;