lz77mgr.pp 7.4 KB

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