dither.inc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. { Everything in here (C)1998 The Rasterman }
  18. { Rasterman's dither matrix }
  19. Const
  20. DitherMatrix_44 : Array[0..3, 0..3] Of char8 = (
  21. (0, 4, 1, 5),
  22. (6, 2, 7, 3),
  23. (1, 5, 0, 4),
  24. (7, 3, 6, 2));
  25. Var
  26. DitherTab_r565_44 : Array[0..3, 0..3, 0..255] Of short16;
  27. DitherTab_g565_44 : Array[0..3, 0..3, 0..255] Of short16;
  28. DitherTab_b565_44 : Array[0..3, 0..3, 0..255] Of short16;
  29. DitherTab_r332_44 : Array[0..3, 0..3, 0..255] Of char8;
  30. DitherTab_g332_44 : Array[0..3, 0..3, 0..255] Of char8;
  31. DitherTab_b332_44 : Array[0..3, 0..3, 0..255] Of char8;
  32. Procedure Dither_SetupMatrices;
  33. Var
  34. i, x, y : LongInt;
  35. Begin
  36. For y := 0 To 3 Do
  37. For x := 0 To 3 Do
  38. For i := 0 To 255 Do
  39. Begin
  40. If (DitherMatrix_44[x, y] < (i And $7)) And (i < (256 - 8)) Then
  41. Begin
  42. DitherTab_r565_44[x, y, i] := ((i + 8) And $f8) Shl 8;
  43. DitherTab_r332_44[x, y, i] := ((i + 8) And $e0);
  44. End
  45. Else
  46. Begin
  47. DitherTab_r565_44[x, y, i] := (i And $f8) Shl 8;
  48. DitherTab_r332_44[x, y, i] := i And $e0;
  49. End;
  50. If (DitherMatrix_44[x, y] < ((i And $3) Shl 1)) And (i < (256 - 4)) Then
  51. Begin
  52. DitherTab_g565_44[x, y, i] := (((i + 4) And $fc) Shl 8) Shr 5;
  53. DitherTab_g332_44[x, y, i] := ((i + 4) And $e0) Shr 3;
  54. End
  55. Else
  56. Begin
  57. DitherTab_g565_44[x, y, i] := ((i And $fc) Shl 8) Shr 5;
  58. DitherTab_g332_44[x, y, i] := (i And $e0) Shr 3;
  59. End;
  60. If (DitherMatrix_44[x, y] < (i And $7)) And (i < (256 - 8)) Then
  61. Begin
  62. DitherTab_b565_44[x, y, i] := (((i + 8) And $f8) Shl 16) Shr 19;
  63. DitherTab_b332_44[x, y, i] := ((i + 8) Shr 6) And $3;
  64. End
  65. Else
  66. Begin
  67. DitherTab_b565_44[x, y, i] := ((i And $f8) Shl 16) Shr 19;
  68. DitherTab_b332_44[x, y, i] := (i Shr 6) And $3;
  69. End;
  70. End;
  71. End;