formati.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. {
  2. Free Pascal port of the OpenPTC C++ library.
  3. Copyright (C) 2001-2006 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 TPTCFormat.Create;
  18. Begin
  19. { defaults }
  20. FFormat.r := 0;
  21. FFormat.g := 0;
  22. FFormat.b := 0;
  23. FFormat.a := 0;
  24. FFormat.bits := 0;
  25. FFormat.indexed := False;
  26. { initialize hermes }
  27. If Not Hermes_Init Then
  28. Raise TPTCError.Create('could not initialize hermes');
  29. End;
  30. Constructor TPTCFormat.Create(ABits : Integer);
  31. Begin
  32. { check bits per pixel }
  33. If ABits <> 8 Then
  34. Raise TPTCError.Create('unsupported bits per pixel');
  35. { indexed color }
  36. FFormat.r := 0;
  37. FFormat.g := 0;
  38. FFormat.b := 0;
  39. FFormat.a := 0;
  40. FFormat.bits := ABits;
  41. FFormat.indexed := True;
  42. { initialize hermes }
  43. If Not Hermes_Init Then
  44. Raise TPTCError.Create('could not initialize hermes');
  45. End;
  46. Constructor TPTCFormat.Create(ABits : Integer;
  47. ARedMask, AGreenMask, ABlueMask : Uint32;
  48. AAlphaMask : Uint32 = 0);
  49. Begin
  50. { check bits per pixel }
  51. If ((ABits And 7) <> 0) Or (ABits <= 0) Or (ABits > 32) Then
  52. Raise TPTCError.Create('unsupported bits per pixel');
  53. { direct color }
  54. FFormat.r := ARedMask;
  55. FFormat.g := AGreenMask;
  56. FFormat.b := ABlueMask;
  57. FFormat.a := AAlphaMask;
  58. FFormat.bits := ABits;
  59. FFormat.indexed := False;
  60. { initialize hermes }
  61. If Not Hermes_Init Then
  62. Raise TPTCError.Create('could not initialize hermes');
  63. End;
  64. Constructor TPTCFormat.Create(Const format : TPTCFormat);
  65. Begin
  66. { initialize hermes }
  67. If Not Hermes_Init Then
  68. Raise TPTCError.Create('could not initialize hermes');
  69. Hermes_FormatCopy(@format.FFormat, @FFormat)
  70. End;
  71. {$INFO TODO: check what happens if Hermes_Init blows up in the constructor...}
  72. Destructor TPTCFormat.Destroy;
  73. Begin
  74. Hermes_Done;
  75. Inherited Destroy;
  76. End;
  77. Procedure TPTCFormat.Assign(Const format : TPTCFormat);
  78. Begin
  79. If Self = format Then
  80. Exit;
  81. Hermes_FormatCopy(@format.Fformat, @Fformat);
  82. End;
  83. Function TPTCFormat.Equals(Const format : TPTCFormat) : Boolean;
  84. Begin
  85. Result := Hermes_FormatEquals(@format.FFormat, @FFormat);
  86. End;
  87. Function TPTCFormat.GetDirect : Boolean;
  88. Begin
  89. Result := Not FFormat.indexed;
  90. End;
  91. Function TPTCFormat.GetBytes : Integer;
  92. Begin
  93. Result := FFormat.bits Shr 3;
  94. End;