lz77mgr.pp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. {$MACRO ON}
  2. (******************************************************************************
  3. *
  4. * Copyright (c) 1994-2001 Palm, Inc. or its subsidiaries.
  5. * All rights reserved.
  6. *
  7. * File: Lz77Mgr.h
  8. *
  9. * Release: Palm OS SDK 4.0 (63220)
  10. *
  11. * History:
  12. * 11/01/99 Created by Michel Turcotte
  13. * Initial revision based on InetLib
  14. *
  15. *****************************************************************************)
  16. {$IFNDEF FPC_DOTTEDUNITS}
  17. unit lz77mgr;
  18. {$ENDIF FPC_DOTTEDUNITS}
  19. interface
  20. {$IFDEF FPC_DOTTEDUNITS}
  21. uses PalmApi.Palmos, PalmApi.Libtraps, PalmApi.Errorbase, PalmApi.Systemresources;
  22. {$ELSE FPC_DOTTEDUNITS}
  23. uses palmos, libtraps, errorbase, systemresources;
  24. {$ENDIF FPC_DOTTEDUNITS}
  25. //
  26. // Common PalmOS and Windows section
  27. //
  28. const
  29. Lz77VerID = 1;
  30. Lz77LastSupportedVerID = 1;
  31. lz77Compress = True;
  32. lz77Expand = False;
  33. type
  34. Lz77ErrorType = Err;
  35. (********************************************************************
  36. * Error codes
  37. ********************************************************************)
  38. const
  39. lz77Success = $00;
  40. // Non Fatal Errors
  41. lz77ErrNonFatalFirstErr = lz77ErrorClass or $00;
  42. lz77ErrNonFatalInputBufferIncomplete = lz77ErrorClass or $01;
  43. lz77ErrNonFatalOutputBufferFull = lz77ErrorClass or $02;
  44. lz77ErrNonFatalLastErr = lz77ErrorClass or $7F;
  45. // Fatal Errors
  46. lz77ErrFatalFirstErr = lz77ErrorClass or $80;
  47. lz77ErrFatalUnfinishedInputBuffer = lz77ErrorClass or $80;
  48. lz77ErrFatalInputBufferIncomplete = lz77ErrorClass or $81;
  49. lz77ErrFatalInputBufferInvalid = lz77ErrorClass or $82;
  50. lz77ErrFatalMemAllocation = lz77ErrorClass or $83;
  51. lz77ErrFatalHandleInvalid = lz77ErrorClass or $84;
  52. lz77ErrFatalCantChangeToCompress = lz77ErrorClass or $85;
  53. lz77ErrFatalUnknownVersion = lz77ErrorClass or $86;
  54. lz77ErrFatalOutputBufferTooSmall = lz77ErrorClass or $87;
  55. lz77ErrFatalInvalidArgument = lz77ErrorClass or $88;
  56. lz77ErrFatalLastErr = lz77ErrorClass or $FF;
  57. function lz77ErrIsFatal(err: Lz77ErrorType): Boolean;
  58. //
  59. // Specific PalmOS section
  60. //
  61. // Creator. Used for both the database that contains the LZ77 Library and
  62. // it's features for the feature manager.
  63. const
  64. lz77Creator = sysFileCLz77Lib; // Lz77 Library creator
  65. lz77LibName = 'Lz77.lib'; // pass in to SysLibFind()
  66. (********************************************************************
  67. * LZ77 Library functions.
  68. ********************************************************************)
  69. const
  70. lz77LibTrapChunk = sysLibTrapCustom;
  71. lz77LibTrapMaxBufferSize = sysLibTrapCustom + 1;
  72. lz77LibTrapBufferGetInfo = sysLibTrapCustom + 2;
  73. lz77LibTrapBufferSetInfo = sysLibTrapCustom + 3;
  74. //--------------------------------------------------
  75. // Library initialization, shutdown, sleep and wake
  76. //--------------------------------------------------
  77. function Lz77LibOpen(
  78. libRefnum: UInt16; // Palm OS reference calling number
  79. var lz77HandleP: MemHandle; // <- Pointer to returning LZ77 handle (NULL for error)
  80. compressFlag: Boolean; // -> TRUE = Compress; FALSE = Expand
  81. sourceSize: UInt32; // -> Source size in bytes
  82. var destHP: MemHandle; // <-> If (*destHP != NULL) => use pre allocated memory
  83. // (*destHP and *destSizeP)
  84. // If (*destHP == NULL) => allocate memory in *destHP
  85. var destSizeP: UInt32; // <-> If (*destSizeP ==0) THEN *destP must be NULL
  86. // => Lz77Open will calculate maximum buffer size
  87. // based on compressFlag and sourceSize
  88. // If (*destSizeP !=0) THEN it indicate
  89. // the size in bytes of the destination buffer
  90. useVerNum: UInt16; // -> if (useVerNum !=0) THEN Use Version numbering
  91. // (Compress will write the value useVerNum in the
  92. // output buffer Expand will verify if the Version
  93. // in the source buffer is compatible)
  94. var primerP: UInt8; // -> if (compressFlag ==lz77Compress)
  95. // UncompressPrimer buffer pointer
  96. // else CompressPrimer buffer pointer
  97. // Must be valid compressed lz77 data
  98. // compressed without a primer.
  99. // NULL means no primer
  100. primerL: UInt32; // -> Byte length of primer
  101. processedPrimerL: UInt32 // -> Byte length of processed primer
  102. ): Err; syscall sysLibTrapOpen;
  103. // Note: The output buffer must be large enough to include the emtire processed primer.
  104. // When Expanding, the compressed primer is passed to the Open routine and
  105. // the output buffer must be large enough to contain the expanded primer.
  106. function Lz77LibClose(
  107. libRefnum: UInt16; // Palm OS reference calling number
  108. lz77Handle: MemHandle; // -> Lz77 Handle
  109. var ResultingSizeP: UInt32 // <- Size in bytes of output generated buffer
  110. // Output buffer will be resized to the resulting size
  111. // if Lz77Open have allocated the output buffer.
  112. // Output buffer must be free by the calling application
  113. ): Err; syscall sysLibTrapClose;
  114. function Lz77LibSleep(libRefnum: UInt16): Err; syscall sysLibTrapSleep;
  115. function Lz77LibWake(libRefnum: UInt16): Err; syscall sysLibTrapWake;
  116. function Lz77LibChunk(
  117. libRefnum: UInt16; // Palm OS reference calling number
  118. lz77Handle: MemHandle; // -> Lz77 Handle
  119. var sourceP: Int8; // -> Source buffer pointer
  120. sourceSize: UInt32; // -> Source buffer Size (bytes)
  121. var sourceBitReadOffset: UInt32 // <-> Next bit to read from source
  122. ): Err; syscall lz77LibTrapChunk;
  123. function Lz77LibMaxBufferSize(
  124. libRefnum: UInt16; // Palm OS reference calling number
  125. compressFlag: Boolean; // -> TRUE = Compress; FALSE = Expand
  126. sourceSize: UInt32; // -> Size of Source buffer
  127. var maxBufferSizeP: UInt32 // <- result size pointer
  128. ): Err; syscall lz77LibTrapMaxBufferSize;
  129. function Lz77LibBufferGetInfo(
  130. libRefnum: UInt16; // Palm OS reference calling number
  131. lz77Handle: MemHandle; // -> Lz77 Handle
  132. var compressFlagP: Boolean; // <- Get compressFlag (true = compress mode; false = expand mode)
  133. var bufferHP: MemHandle; // <- Get the Pointer to the accumulated destination buffer
  134. var bufferByteSizeP: UInt32; // <- Get destination buffer size in bytes
  135. var destBitOffsetP: UInt32 // <- Get destination bit offset
  136. ): Err; syscall lz77LibTrapBufferGetInfo;
  137. function Lz77LibBufferSetInfo(
  138. libRefnum: UInt16; // Palm OS reference calling number
  139. lz77Handle: MemHandle; // -> Lz77 Handle
  140. compressFlag: Boolean; // -> Set compressFlag (true = compress mode; false = expand mode)
  141. destH: MemHandle; // -> Set a Pointer to the accumulated destination buffer
  142. destByteSize: UInt32; // -> Set destination buffer size in bytes
  143. destBitOffset: UInt32 // -> Set destination bit offset
  144. ): Err; syscall lz77LibTrapBufferSetInfo;
  145. implementation
  146. function lz77ErrIsFatal(err: Lz77ErrorType): Boolean;
  147. begin
  148. lz77ErrIsFatal := (err <> lz77Success) and ((err < lz77ErrNonFatalFirstErr) or (err > lz77ErrNonFatalLastErr));
  149. end;
  150. end.