cleari.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. {
  2. Free Pascal port of the OpenPTC C++ library.
  3. Copyright (C) 2001-2003 Nikolay Nikolov ([email protected])
  4. Original C++ version by Glenn Fiedler ([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. Constructor TPTCClear.Create;
  18. Begin
  19. FFormat := Nil;
  20. { initialize hermes }
  21. If Not Hermes_Init Then
  22. Raise TPTCError.Create('could not initialize hermes');
  23. { default current format }
  24. FFormat := TPTCFormat.Create;
  25. { create hermes clearer instance }
  26. FHandle := Hermes_ClearerInstance;
  27. { check hermes clearer instance }
  28. If FHandle = 0 Then
  29. Raise TPTCError.Create('could not create hermes clearer instance');
  30. End;
  31. Destructor TPTCClear.Destroy;
  32. Begin
  33. { return the clearer instance }
  34. Hermes_ClearerReturn(FHandle);
  35. FFormat.Free;
  36. { free hermes }
  37. Hermes_Done;
  38. Inherited Destroy;
  39. End;
  40. Procedure TPTCClear.Request(Const AFormat : TPTCFormat);
  41. Var
  42. hermes_format : PHermesFormat;
  43. Begin
  44. hermes_format := @AFormat.FFormat;
  45. { request surface clear for this format }
  46. If Not Hermes_ClearerRequest(FHandle, hermes_format) Then
  47. Raise TPTCError.Create('unsupported clear format');
  48. { update current format }
  49. FFormat.Assign(AFormat);
  50. End;
  51. Procedure TPTCClear.Clear(APixels : Pointer; AX, AY, AWidth, AHeight, APitch : Integer; Const AColor : TPTCColor);
  52. Var
  53. r, g, b, a : LongInt;
  54. index : LongInt;
  55. Begin
  56. If APixels = Nil Then
  57. Raise TPTCError.Create('nil pixels pointer in clear');
  58. { check format type }
  59. If FFormat.direct Then
  60. Begin
  61. { check color type }
  62. If Not AColor.direct Then
  63. Raise TPTCError.Create('direct pixel formats can only be cleared with direct color');
  64. { setup clear color }
  65. r := Trunc(AColor.R * 255);
  66. g := Trunc(AColor.G * 255);
  67. b := Trunc(AColor.B * 255);
  68. a := Trunc(AColor.A * 255);
  69. { clamp red }
  70. If r > 255 Then
  71. r := 255
  72. Else
  73. If r < 0 Then
  74. r := 0;
  75. { clamp green }
  76. If g > 255 Then
  77. g := 255
  78. Else
  79. If g < 0 Then
  80. g := 0;
  81. { clamp blue }
  82. If b > 255 Then
  83. b := 255
  84. Else
  85. If b < 0 Then
  86. b := 0;
  87. { clamp alpha }
  88. If a > 255 Then
  89. a := 255
  90. Else
  91. If a < 0 Then
  92. a := 0;
  93. { perform the clearing }
  94. Hermes_ClearerClear(FHandle, APixels, AX, AY, AWidth, AHeight, APitch,
  95. r, g, b, a);
  96. End
  97. Else
  98. Begin
  99. { check color type }
  100. If Not AColor.indexed Then
  101. Raise TPTCError.Create('indexed pixel formats can only be cleared with indexed color');
  102. { setup clear index }
  103. index := AColor.index;
  104. { clamp color index }
  105. If index > 255 Then
  106. index := 255
  107. Else
  108. If index < 0 Then
  109. index := 0;
  110. { perform the clearing }
  111. Hermes_ClearerClear(FHandle, APixels, AX, AY, AWidth, AHeight, APitch,
  112. 0, 0, 0, index);
  113. End;
  114. End;