copyi.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 TPTCCopy.Create;
  18. Begin
  19. If Not Hermes_Init Then
  20. Raise TPTCError.Create('could not initialize hermes');
  21. m_flags := HERMES_CONVERT_NORMAL;
  22. m_handle := Hermes_ConverterInstance(m_flags);
  23. If m_handle = 0 Then
  24. Raise TPTCError.Create('could not create hermes converter instance');
  25. End;
  26. Destructor TPTCCopy.Destroy;
  27. Begin
  28. Hermes_ConverterReturn(m_handle);
  29. Hermes_Done;
  30. Inherited Destroy;
  31. End;
  32. Procedure TPTCCopy.request(Const source, destination : TPTCFormat);
  33. Var
  34. hermes_source_format, hermes_destination_format : PHermesFormat;
  35. Begin
  36. hermes_source_format := @source.Fformat;
  37. hermes_destination_format := @destination.Fformat;
  38. If Not Hermes_ConverterRequest(m_handle, hermes_source_format,
  39. hermes_destination_format) Then
  40. Raise TPTCError.Create('unsupported hermes pixel format conversion');
  41. End;
  42. Procedure TPTCCopy.palette(Const source, destination : TPTCPalette);
  43. Begin
  44. If Not Hermes_ConverterPalette(m_handle, source.m_handle,
  45. destination.m_handle) Then
  46. Raise TPTCError.Create('could not set hermes conversion palettes');
  47. End;
  48. Procedure TPTCCopy.copy(Const source_pixels : Pointer; source_x, source_y,
  49. source_width, source_height, source_pitch : Integer;
  50. destination_pixels : Pointer; destination_x, destination_y,
  51. destination_width, destination_height, destination_pitch : Integer);
  52. Var
  53. source : Pointer;
  54. Begin
  55. {$IFDEF DEBUG}
  56. {
  57. This checking is performed only when DEBUG is defined,
  58. and can be used to track down errors early caused by passing
  59. nil pointers to surface and console functions.
  60. Even though technicially it is the users responsibility
  61. to ensure that all pointers are non-nil, it is useful
  62. to provide a check here in debug build to prevent such
  63. bugs from ever occuring.
  64. The checking function also tests that the source and destination
  65. pointers are not the same, a bug that can be caused by copying
  66. a surface to itself. The nature of the copy routine is that
  67. this operation is undefined if the source and destination memory
  68. areas overlap.
  69. }
  70. If source_pixels = Nil Then
  71. Raise TPTCError.Create('nil source pointer in copy');
  72. If destination_pixels = Nil Then
  73. Raise TPTCError.Create('nil destination pointer in copy');
  74. If source_pixels = destination_pixels Then
  75. Raise TPTCError.Create('identical source and destination pointers in copy');
  76. {$ELSE DEBUG}
  77. { in release build no checking is performed for the sake of efficiency. }
  78. {$ENDIF DEBUG}
  79. source := source_pixels;
  80. If Not Hermes_ConverterCopy(m_handle, source, source_x, source_y,
  81. source_width, source_height, source_pitch, destination_pixels,
  82. destination_x, destination_y, destination_width, destination_height,
  83. destination_pitch) Then
  84. Raise TPTCError.Create('hermes conversion failure');
  85. End;
  86. Function TPTCCopy.option(Const _option : String) : Boolean;
  87. Begin
  88. If (_option = 'attempt dithering') And ((m_flags And HERMES_CONVERT_DITHER) = 0) Then
  89. Begin
  90. m_flags := m_flags Or HERMES_CONVERT_DITHER;
  91. update;
  92. option := True;
  93. Exit;
  94. End;
  95. If (_option = 'disable dithering') And ((m_flags And HERMES_CONVERT_DITHER) <> 0) Then
  96. Begin
  97. m_flags := m_flags And (Not HERMES_CONVERT_DITHER);
  98. update;
  99. option := True;
  100. Exit;
  101. End;
  102. option := False;
  103. End;
  104. Procedure TPTCCopy.update;
  105. Begin
  106. Hermes_ConverterReturn(m_handle);
  107. m_handle := Hermes_ConverterInstance(m_flags);
  108. If m_handle = 0 Then
  109. Raise TPTCError.Create('could not update hermes converter instance');
  110. End;