home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 March / PCO3_97.ISO / filesbbs / os2 / lzo026.arj / LZO026.ZIP / lzo-0.26 / src / lzo1_99.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-27  |  3.2 KB  |  125 lines

  1. /* lzo1_99.c -- implementation of the LZO1-99 algorithm
  2.  
  3.    This file is part of the LZO real-time data compression library.
  4.  
  5.    Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
  6.  
  7.    The LZO library is free software; you can redistribute it and/or
  8.    modify it under the terms of the GNU General Public License as
  9.    published by the Free Software Foundation; either version 2 of
  10.    the License, or (at your option) any later version.
  11.  
  12.    The LZO library is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with the LZO library; see the file COPYING.
  19.    If not, write to the Free Software Foundation, Inc.,
  20.    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21.  
  22.    Markus F.X.J. Oberhumer
  23.    markus.oberhumer@jk.uni-linz.ac.at
  24.  */
  25.  
  26.  
  27.  
  28. #include <lzoconf.h>
  29. #if !defined(LZO_99_UNSUPPORTED)
  30.  
  31. #define COMPRESS_ID        99
  32.  
  33. #define DDBITS            3
  34. #define CLEVEL            9
  35.  
  36.  
  37. /***********************************************************************
  38. // 
  39. ************************************************************************/
  40.  
  41. #define LZO_NEED_DICT_H
  42. #include "config1.h"
  43.  
  44.  
  45. /***********************************************************************
  46. // compression internal entry point.
  47. ************************************************************************/
  48.  
  49. static int
  50. _lzo1_do_compress ( const lzo_byte *in,  lzo_uint  in_len,
  51.                           lzo_byte *out, lzo_uint *out_len,
  52.                           lzo_voidp wrkmem,
  53.                           lzo_compress_t func )
  54. {
  55.     int r;
  56.  
  57.     /* sanity check */
  58.     if (!lzo_assert(LZO1_99_MEM_COMPRESS >= D_SIZE * lzo_sizeof(lzo_byte *)))
  59.         return LZO_E_ERROR;
  60.  
  61.     /* don't try to compress a block that's too short */
  62.     if (in_len <= 0)
  63.     {
  64.         *out_len = 0;
  65.         r = LZO_E_OK;
  66.     }
  67.     else if (in_len <= MIN_LOOKAHEAD + 1)
  68.     {
  69. #if defined(LZO_RETURN_IF_NOT_COMPRESSIBLE)
  70.         *out_len = 0;
  71.         r = LZO_E_NOT_COMPRESSIBLE;
  72. #else
  73.         *out_len = STORE_RUN(out,in,in_len) - out;
  74.         r = (*out_len > in_len) ? LZO_E_OK : LZO_E_ERROR;
  75. #endif
  76.     }
  77.     else
  78.         r = func(in,in_len,out,out_len,wrkmem);
  79.  
  80.     return r;
  81. }
  82.  
  83.  
  84. /***********************************************************************
  85. // 
  86. ************************************************************************/
  87.  
  88. #if !defined(COMPRESS_ID)
  89. #define COMPRESS_ID        _LZO_ECONCAT2(DD_BITS,CLEVEL)
  90. #endif
  91.  
  92.  
  93. #define LZO_CODE_MATCH_INCLUDE_FILE        "lzo1_cm.ch"
  94. #include "lzo1b_c.ch"
  95.  
  96.  
  97. /***********************************************************************
  98. // 
  99. ************************************************************************/
  100.  
  101. #define LZO_COMPRESS \
  102.     _LZO_ECONCAT3(lzo1_,COMPRESS_ID,_compress)
  103.  
  104. #define LZO_COMPRESS_FUNC \
  105.     _LZO_ECONCAT3(_lzo1_,COMPRESS_ID,_compress_func)
  106.  
  107.  
  108. /***********************************************************************
  109. // 
  110. ************************************************************************/
  111.  
  112. LZO_PUBLIC(int)
  113. LZO_COMPRESS ( const lzo_byte *src, lzo_uint  src_len,
  114.                      lzo_byte *dst, lzo_uint *dst_len,
  115.                      lzo_voidp wrkmem )
  116. {
  117.     return _lzo1_do_compress(src,src_len,dst,dst_len,wrkmem,do_compress);
  118. }
  119.  
  120. #endif
  121.  
  122. /*
  123. vi:ts=4
  124. */
  125.