utility.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. {Procedure Hermes_Calculate_Generic_Info(s_r, s_g, s_b, s_a,
  18. d_r, d_g, d_b, d_a : int32;
  19. info : PHermesGenericInfo);
  20. Function Hermes_Topbit(mask : int32) : Integer;}
  21. Procedure Hermes_Calculate_Generic_Info(s_r, s_g, s_b, s_a,
  22. d_r, d_g, d_b, d_a : Integer;
  23. info : PHermesGenericInfo);
  24. Var
  25. r_right, g_right, b_right, a_right : Integer;
  26. Begin
  27. {Calculate right shift amount for red. If it's <0, then set it to 0
  28. and calculate left shift amount}
  29. r_right := s_r - d_r;
  30. If r_right < 0 Then
  31. Begin
  32. info^.r_left := -r_right;
  33. info^.r_right := 0;
  34. End
  35. Else
  36. Begin
  37. info^.r_left := 0;
  38. info^.r_right := r_right;
  39. End;
  40. {Same for green}
  41. g_right := s_g - d_g;
  42. If g_right < 0 Then
  43. Begin
  44. info^.g_left := -g_right;
  45. info^.g_right := 0;
  46. End
  47. Else
  48. Begin
  49. info^.g_left := 0;
  50. info^.g_right := g_right;
  51. End;
  52. {Same for blue}
  53. b_right := s_b - d_b;
  54. If b_right < 0 Then
  55. Begin
  56. info^.b_left := -b_right;
  57. info^.b_right := 0;
  58. End
  59. Else
  60. Begin
  61. info^.b_left := 0;
  62. info^.b_right := b_right;
  63. End;
  64. {Alpha}
  65. a_right := s_a - d_a;
  66. If a_right < 0 Then
  67. Begin
  68. info^.a_left := -a_right;
  69. info^.a_right := 0;
  70. End
  71. Else
  72. Begin
  73. info^.a_left := 0;
  74. info^.a_right := a_right;
  75. End;
  76. End;
  77. Function Hermes_Topbit(mask : int32) : Integer;
  78. Var
  79. i : Integer;
  80. Begin
  81. If mask = 0 Then
  82. Begin
  83. Hermes_Topbit := 0;
  84. Exit;
  85. End;
  86. i := 0;
  87. While (mask And 1) = 0 Do
  88. Begin
  89. mask := mask Shr 1;
  90. Inc(i);
  91. End;
  92. While (mask And 1) = 1 Do
  93. Begin
  94. mask := mask Shr 1;
  95. Inc(i);
  96. End;
  97. Hermes_Topbit := i;
  98. End;