formati.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 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(_bits : Integer);
  31. Begin
  32. { check bits per pixel }
  33. If _bits <> 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 := _bits;
  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(_bits : Integer; _r, _g, _b, _a : int32);
  47. Begin
  48. { check bits per pixel }
  49. If ((_bits And 7) <> 0) Or (_bits <= 0) Or (_bits > 32) Then
  50. Raise TPTCError.Create('unsupported bits per pixel');
  51. { direct color }
  52. Fformat.r := _r;
  53. Fformat.g := _g;
  54. Fformat.b := _b;
  55. Fformat.a := _a;
  56. Fformat.bits := _bits;
  57. Fformat.indexed := False;
  58. { initialize hermes }
  59. If Not Hermes_Init Then
  60. Raise TPTCError.Create('could not initialize hermes');
  61. End;
  62. Constructor TPTCFormat.Create(_bits : Integer; _r, _g, _b : int32);
  63. Begin
  64. { check bits per pixel }
  65. If ((_bits And 7) <> 0) Or (_bits <= 0) Or (_bits > 32) Then
  66. Raise TPTCError.Create('unsupported bits per pixel');
  67. { direct color }
  68. Fformat.r := _r;
  69. Fformat.g := _g;
  70. Fformat.b := _b;
  71. Fformat.a := 0;
  72. Fformat.bits := _bits;
  73. Fformat.indexed := False;
  74. { initialize hermes }
  75. If Not Hermes_Init Then
  76. Raise TPTCError.Create('could not initialize hermes');
  77. End;
  78. Constructor TPTCFormat.Create(Const format : TPTCFormat);
  79. Begin
  80. { initialize hermes }
  81. If Not Hermes_Init Then
  82. Raise TPTCError.Create('could not initialize hermes');
  83. Hermes_FormatCopy(@format.Fformat, @Fformat)
  84. End;
  85. Destructor TPTCFormat.Destroy;
  86. Begin
  87. Hermes_Done;
  88. Inherited Destroy;
  89. End;
  90. Procedure TPTCFormat.Assign(Const format : TPTCFormat);
  91. Begin
  92. If Self = format Then
  93. Raise TPTCError.Create('self assignment is not allowed');
  94. Hermes_FormatCopy(@format.Fformat, @Fformat)
  95. End;
  96. Function TPTCFormat.Equals(Const format : TPTCFormat) : Boolean;
  97. Begin
  98. Equals := Hermes_FormatEquals(@format.Fformat, @Fformat);
  99. End;
  100. Function TPTCFormat.direct : Boolean;
  101. Begin
  102. direct := Not Fformat.indexed;
  103. End;
  104. Function TPTCFormat.bytes : Integer;
  105. Begin
  106. bytes := Fformat.bits Shr 3;
  107. End;