/packages/hermes/src/hermes_dither.inc

https://github.com/slibre/freepascal · Pascal · 92 lines · 53 code · 6 blank · 33 comment · 6 complexity · 7cd38b733cf76a7470f0384cc73e7ce0 MD5 · raw file

  1. {
  2. Free Pascal port of the Hermes C library.
  3. Copyright (C) 2001-2003 Nikolay Nikolov (nickysn@users.sourceforge.net)
  4. Original C version by Christian Nentwich (c.nentwich@cs.ucl.ac.uk)
  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. { Everything in here (C)1998 The Rasterman }
  29. { Rasterman's dither matrix }
  30. const
  31. DitherMatrix_44: array [0..3, 0..3] of Uint8 = (
  32. (0, 4, 1, 5),
  33. (6, 2, 7, 3),
  34. (1, 5, 0, 4),
  35. (7, 3, 6, 2));
  36. var
  37. DitherTab_r565_44: array [0..3, 0..3, 0..255] of Uint16;
  38. DitherTab_g565_44: array [0..3, 0..3, 0..255] of Uint16;
  39. DitherTab_b565_44: array [0..3, 0..3, 0..255] of Uint16;
  40. DitherTab_r332_44: array [0..3, 0..3, 0..255] of Uint8;
  41. DitherTab_g332_44: array [0..3, 0..3, 0..255] of Uint8;
  42. DitherTab_b332_44: array [0..3, 0..3, 0..255] of Uint8;
  43. procedure Dither_SetupMatrices;
  44. var
  45. i, x, y: LongInt;
  46. begin
  47. for y := 0 to 3 do
  48. for x := 0 to 3 do
  49. for i := 0 to 255 do
  50. begin
  51. if (DitherMatrix_44[x, y] < (i and $7)) and (i < (256 - 8)) then
  52. begin
  53. DitherTab_r565_44[x, y, i] := ((i + 8) and $f8) shl 8;
  54. DitherTab_r332_44[x, y, i] := ((i + 8) and $e0);
  55. end
  56. else
  57. begin
  58. DitherTab_r565_44[x, y, i] := (i and $f8) shl 8;
  59. DitherTab_r332_44[x, y, i] := i and $e0;
  60. end;
  61. if (DitherMatrix_44[x, y] < ((i and $3) shl 1)) and (i < (256 - 4)) then
  62. begin
  63. DitherTab_g565_44[x, y, i] := (((i + 4) and $fc) shl 8) shr 5;
  64. DitherTab_g332_44[x, y, i] := ((i + 4) and $e0) shr 3;
  65. end
  66. else
  67. begin
  68. DitherTab_g565_44[x, y, i] := ((i and $fc) shl 8) shr 5;
  69. DitherTab_g332_44[x, y, i] := (i and $e0) shr 3;
  70. end;
  71. if (DitherMatrix_44[x, y] < (i and $7)) and (i < (256 - 8)) then
  72. begin
  73. DitherTab_b565_44[x, y, i] := (((i + 8) and $f8) shl 16) shr 19;
  74. DitherTab_b332_44[x, y, i] := ((i + 8) shr 6) and $3;
  75. end
  76. else
  77. begin
  78. DitherTab_b565_44[x, y, i] := ((i and $f8) shl 16) shr 19;
  79. DitherTab_b332_44[x, y, i] := (i shr 6) and $3;
  80. end;
  81. end;
  82. end;