format.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. {Function Hermes_FormatNewEmpty : PHermesFormat;
  18. Function Hermes_FormatNew(bits : Integer; r, g, b, a : int32;
  19. indexed : Boolean) : PHermesFormat;
  20. Procedure Hermes_FormatFree(fmt : PHermesFormat);
  21. Function Hermes_FormatNewEx(bits : Integer; r, g, b, a : int32;
  22. indexed, has_colorkey : Boolean;
  23. colorkey : int32) : PHermesFormat;
  24. Function Hermes_FormatEquals(op1, op2 : PHermesFormat) : Boolean;
  25. Procedure Hermes_FormatCopy(source, dest : PHermesFormat);}
  26. Function Hermes_FormatNewEmpty : PHermesFormat;
  27. Var
  28. tmp : PHermesFormat;
  29. Begin
  30. tmp := malloc(SizeOf(THermesFormat));
  31. If tmp = Nil Then
  32. Begin
  33. Hermes_FormatNewEmpty := Nil;
  34. Exit;
  35. End;
  36. tmp^.bits := 0;
  37. tmp^.indexed := False;
  38. tmp^.r := 0;
  39. tmp^.g := 0;
  40. tmp^.b := 0;
  41. tmp^.a := 0;
  42. tmp^.has_colorkey := False;
  43. tmp^.colorkey := 0;
  44. Hermes_FormatNewEmpty := tmp;
  45. End;
  46. Function Hermes_FormatNew(bits : Integer; r, g, b, a : int32;
  47. indexed : Boolean) : PHermesFormat;
  48. Var
  49. tmp : PHermesFormat;
  50. Begin
  51. If indexed And (bits <> 8) Then
  52. Begin
  53. Hermes_FormatNew := Nil;
  54. Exit;
  55. End;
  56. tmp := malloc(SizeOf(THermesFormat));
  57. If tmp = Nil Then
  58. Begin
  59. Hermes_FormatNew := Nil;
  60. Exit;
  61. End;
  62. tmp^.bits := bits;
  63. tmp^.r := r;
  64. tmp^.g := g;
  65. tmp^.b := b;
  66. tmp^.a := a;
  67. tmp^.indexed := indexed;
  68. tmp^.has_colorkey := False;
  69. tmp^.colorkey := 0;
  70. Hermes_FormatNew := tmp;
  71. End;
  72. Procedure Hermes_FormatFree(fmt : PHermesFormat);
  73. Begin
  74. If fmt <> Nil Then
  75. free(fmt);
  76. End;
  77. Function Hermes_FormatNewEx(bits : Integer; r, g, b, a : int32;
  78. indexed, has_colorkey : Boolean;
  79. colorkey : int32) : PHermesFormat;
  80. Var
  81. tmp : PHermesFormat;
  82. Begin
  83. If indexed And (bits <> 8) Then
  84. Begin
  85. Hermes_FormatNewEx := Nil;
  86. Exit;
  87. End;
  88. tmp := malloc(SizeOf(THermesFormat));
  89. If tmp = Nil Then
  90. Begin
  91. Hermes_FormatNewEx := Nil;
  92. Exit;
  93. End;
  94. tmp^.bits := bits;
  95. tmp^.r := r;
  96. tmp^.g := g;
  97. tmp^.b := b;
  98. tmp^.a := a;
  99. tmp^.indexed := indexed;
  100. tmp^.has_colorkey := has_colorkey;
  101. tmp^.colorkey := colorkey;
  102. Hermes_FormatNewEx := tmp;
  103. End;
  104. Function Hermes_FormatEquals(op1, op2 : PHermesFormat) : Boolean;
  105. Begin
  106. Hermes_FormatEquals := ((op1^.indexed = op2^.indexed) And
  107. (op1^.bits = op2^.bits) And
  108. (op1^.r = op2^.r) And
  109. (op1^.g = op2^.g) And
  110. (op1^.b = op2^.b) And
  111. (op1^.a = op2^.a) And
  112. (op1^.has_colorkey = op2^.has_colorkey) And
  113. ((op1^.has_colorkey = False) Or
  114. (op1^.colorkey = op2^.colorkey)));
  115. End;
  116. Procedure Hermes_FormatCopy(source, dest : PHermesFormat);
  117. Begin
  118. Move(source^, dest^, SizeOf(THermesFormat));
  119. End;