Beispiel #1
0
static int
_lzo1a_do_compress ( const lzo_bytep in,  lzo_uint  in_len,
                           lzo_bytep out, lzo_uintp out_len,
                           lzo_voidp wrkmem,
                           lzo_compress_t func )
{
    int r;

    /* don't try to compress a block that's too short */
    if (in_len == 0)
    {
        *out_len = 0;
        r = LZO_E_OK;
    }
    else if (in_len <= MIN_LOOKAHEAD + 1)
    {
#if defined(LZO_RETURN_IF_NOT_COMPRESSIBLE)
        *out_len = 0;
        r = LZO_E_NOT_COMPRESSIBLE;
#else
        *out_len = pd(STORE_RUN(out,in,in_len), out);
        r = (*out_len > in_len) ? LZO_E_OK : LZO_E_ERROR;
#endif
    }
    else
        r = func(in,in_len,out,out_len,wrkmem);

    return r;
}
Beispiel #2
0
_lzo1c_do_compress ( const lzo_bytep in,  lzo_uint  in_len,
                           lzo_bytep out, lzo_uintp out_len,
                           lzo_voidp wrkmem,
                           lzo_compress_t func )
{
    int r;
#if defined(LZO_TEST_COMPRESS_OVERRUN)
    lzo_uint avail_out = *out_len;
#endif


#if (LZO_COLLECT_STATS)
    _lzo1c_stats_init(lzo_stats);
    lzo_stats->in_len = in_len;
#endif


    /* don't try to compress a block that's too short */
    if (in_len == 0)
    {
        *out_len = 0;
        r = LZO_E_OK;
    }
    else if (in_len <= MIN_LOOKAHEAD + 1)
    {
#if defined(LZO_RETURN_IF_NOT_COMPRESSIBLE)
        *out_len = 0;
        r = LZO_E_NOT_COMPRESSIBLE;
#else
        *out_len = pd(STORE_RUN(out,in,in_len), out);
        r = (*out_len > in_len) ? LZO_E_OK : LZO_E_ERROR;
#endif
    }
    else
        r = func(in,in_len,out,out_len,wrkmem);


#if defined(LZO_EOF_CODE)
#if defined(LZO_TEST_COMPRESS_OVERRUN)
    if (r == LZO_E_OK && avail_out - *out_len < 3)
        r = LZO_E_COMPRESS_OVERRUN;
#endif
    if (r == LZO_E_OK)
    {
        lzo_bytep op = out + *out_len;
        op[0] = M3_MARKER | 1;
        op[1] = 0;
        op[2] = 0;
        *out_len += 3;
    }
#endif


#if (LZO_COLLECT_STATS)
    lzo_stats->out_len = *out_len;
    lzo_stats->match_bytes =
       1 * lzo_stats->m1_matches + 2 * lzo_stats->m2_matches +
       3 * lzo_stats->m3_matches + 4 * lzo_stats->m4_matches;
    _lzo1c_stats_calc(lzo_stats);
#endif

    return r;
}