wrapmisc.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /* wrapmisc.h -- misc wrapper functions for the test driver
  2. This file is part of the LZO real-time data compression library.
  3. Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer
  4. All Rights Reserved.
  5. The LZO library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of
  8. the License, or (at your option) any later version.
  9. The LZO 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
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with the LZO library; see the file COPYING.
  15. If not, write to the Free Software Foundation, Inc.,
  16. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. Markus F.X.J. Oberhumer
  18. <markus@oberhumer.com>
  19. http://www.oberhumer.com/opensource/lzo/
  20. */
  21. /*************************************************************************
  22. // compression levels of zlib
  23. **************************************************************************/
  24. #if defined(ALG_ZLIB)
  25. #define ZLIB_MEM_COMPRESS 0
  26. #define ZLIB_MEM_DECOMPRESS 0
  27. static
  28. int zlib_compress ( const m_bytep src, m_uint src_len,
  29. m_bytep dst, m_uintp dst_len,
  30. m_voidp wrkmem,
  31. int method, int compression_level )
  32. {
  33. int err;
  34. uLong destLen;
  35. assert(method == Z_DEFLATED);
  36. destLen = (uLong) *dst_len;
  37. err = compress2(dst, &destLen, src, (uLong) src_len, compression_level);
  38. *dst_len = destLen;
  39. LZO_UNUSED(method);
  40. LZO_UNUSED(wrkmem);
  41. return err;
  42. }
  43. M_PRIVATE(int)
  44. zlib_decompress ( const m_bytep src, m_uint src_len,
  45. m_bytep dst, m_uintp dst_len,
  46. m_voidp wrkmem )
  47. {
  48. int err;
  49. uLong destLen;
  50. destLen = (uLong) *dst_len;
  51. err = uncompress(dst, &destLen, src, (uLong) src_len);
  52. *dst_len = destLen;
  53. LZO_UNUSED(wrkmem);
  54. return err;
  55. }
  56. M_PRIVATE(int)
  57. zlib_8_1_compress ( const m_bytep src, m_uint src_len,
  58. m_bytep dst, m_uintp dst_len,
  59. m_voidp wrkmem )
  60. { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,1); }
  61. M_PRIVATE(int)
  62. zlib_8_2_compress ( const m_bytep src, m_uint src_len,
  63. m_bytep dst, m_uintp dst_len,
  64. m_voidp wrkmem )
  65. { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,2); }
  66. M_PRIVATE(int)
  67. zlib_8_3_compress ( const m_bytep src, m_uint src_len,
  68. m_bytep dst, m_uintp dst_len,
  69. m_voidp wrkmem )
  70. { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,3); }
  71. M_PRIVATE(int)
  72. zlib_8_4_compress ( const m_bytep src, m_uint src_len,
  73. m_bytep dst, m_uintp dst_len,
  74. m_voidp wrkmem )
  75. { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,4); }
  76. M_PRIVATE(int)
  77. zlib_8_5_compress ( const m_bytep src, m_uint src_len,
  78. m_bytep dst, m_uintp dst_len,
  79. m_voidp wrkmem )
  80. { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,5); }
  81. M_PRIVATE(int)
  82. zlib_8_6_compress ( const m_bytep src, m_uint src_len,
  83. m_bytep dst, m_uintp dst_len,
  84. m_voidp wrkmem )
  85. { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,6); }
  86. M_PRIVATE(int)
  87. zlib_8_7_compress ( const m_bytep src, m_uint src_len,
  88. m_bytep dst, m_uintp dst_len,
  89. m_voidp wrkmem )
  90. { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,7); }
  91. M_PRIVATE(int)
  92. zlib_8_8_compress ( const m_bytep src, m_uint src_len,
  93. m_bytep dst, m_uintp dst_len,
  94. m_voidp wrkmem )
  95. { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,8); }
  96. M_PRIVATE(int)
  97. zlib_8_9_compress ( const m_bytep src, m_uint src_len,
  98. m_bytep dst, m_uintp dst_len,
  99. m_voidp wrkmem )
  100. { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,9); }
  101. #endif /* ALG_ZLIB */
  102. /*************************************************************************
  103. // compression levels of bzip2
  104. **************************************************************************/
  105. #if defined(ALG_BZIP2)
  106. #define BZIP2_MEM_COMPRESS 0
  107. #define BZIP2_MEM_DECOMPRESS 0
  108. static
  109. int bzip2_compress ( const m_bytep src, m_uint src_len,
  110. m_bytep dst, m_uintp dst_len,
  111. m_voidp wrkmem,
  112. int compression_level )
  113. {
  114. int err;
  115. unsigned destLen;
  116. union { const m_bytep csrc; char *src; } u;
  117. u.csrc = src; /* UNCONST */
  118. destLen = *dst_len;
  119. err = BZ2_bzBuffToBuffCompress((char*)dst, &destLen, u.src, src_len, compression_level, 0, 0);
  120. *dst_len = destLen;
  121. LZO_UNUSED(wrkmem);
  122. return err;
  123. }
  124. M_PRIVATE(int)
  125. bzip2_decompress ( const m_bytep src, m_uint src_len,
  126. m_bytep dst, m_uintp dst_len,
  127. m_voidp wrkmem )
  128. {
  129. int err;
  130. unsigned destLen;
  131. union { const m_bytep csrc; char *src; } u;
  132. u.csrc = src; /* UNCONST */
  133. destLen = *dst_len;
  134. err = BZ2_bzBuffToBuffDecompress((char*)dst, &destLen, u.src, src_len, 0, 0);
  135. *dst_len = destLen;
  136. LZO_UNUSED(wrkmem);
  137. return err;
  138. }
  139. M_PRIVATE(int)
  140. bzip2_1_compress ( const m_bytep src, m_uint src_len,
  141. m_bytep dst, m_uintp dst_len,
  142. m_voidp wrkmem )
  143. { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,1); }
  144. M_PRIVATE(int)
  145. bzip2_2_compress ( const m_bytep src, m_uint src_len,
  146. m_bytep dst, m_uintp dst_len,
  147. m_voidp wrkmem )
  148. { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,2); }
  149. M_PRIVATE(int)
  150. bzip2_3_compress ( const m_bytep src, m_uint src_len,
  151. m_bytep dst, m_uintp dst_len,
  152. m_voidp wrkmem )
  153. { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,3); }
  154. M_PRIVATE(int)
  155. bzip2_4_compress ( const m_bytep src, m_uint src_len,
  156. m_bytep dst, m_uintp dst_len,
  157. m_voidp wrkmem )
  158. { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,4); }
  159. M_PRIVATE(int)
  160. bzip2_5_compress ( const m_bytep src, m_uint src_len,
  161. m_bytep dst, m_uintp dst_len,
  162. m_voidp wrkmem )
  163. { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,5); }
  164. M_PRIVATE(int)
  165. bzip2_6_compress ( const m_bytep src, m_uint src_len,
  166. m_bytep dst, m_uintp dst_len,
  167. m_voidp wrkmem )
  168. { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,6); }
  169. M_PRIVATE(int)
  170. bzip2_7_compress ( const m_bytep src, m_uint src_len,
  171. m_bytep dst, m_uintp dst_len,
  172. m_voidp wrkmem )
  173. { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,7); }
  174. M_PRIVATE(int)
  175. bzip2_8_compress ( const m_bytep src, m_uint src_len,
  176. m_bytep dst, m_uintp dst_len,
  177. m_voidp wrkmem )
  178. { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,8); }
  179. M_PRIVATE(int)
  180. bzip2_9_compress ( const m_bytep src, m_uint src_len,
  181. m_bytep dst, m_uintp dst_len,
  182. m_voidp wrkmem )
  183. { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,9); }
  184. #endif /* ALG_BZIP2 */
  185. /*************************************************************************
  186. // other wrappers (for benchmarking the checksum algorithms)
  187. **************************************************************************/
  188. #if defined(ALG_ZLIB)
  189. M_PRIVATE(int)
  190. zlib_adler32_x_compress ( const m_bytep src, m_uint src_len,
  191. m_bytep dst, m_uintp dst_len,
  192. m_voidp wrkmem )
  193. {
  194. uLong adler;
  195. adler = adler32(1L, src, (uInt) src_len);
  196. *dst_len = src_len;
  197. LZO_UNUSED(adler);
  198. LZO_UNUSED(dst);
  199. LZO_UNUSED(wrkmem);
  200. return 0;
  201. }
  202. M_PRIVATE(int)
  203. zlib_crc32_x_compress ( const m_bytep src, m_uint src_len,
  204. m_bytep dst, m_uintp dst_len,
  205. m_voidp wrkmem )
  206. {
  207. uLong crc;
  208. crc = crc32(0L, src, (uInt) src_len);
  209. *dst_len = src_len;
  210. LZO_UNUSED(crc);
  211. LZO_UNUSED(dst);
  212. LZO_UNUSED(wrkmem);
  213. return 0;
  214. }
  215. #endif /* ALG_ZLIB */
  216. /* vim:set ts=4 sw=4 et: */