copyi.inc 4.4 KB

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