예제 #1
0
int64_t lzbench_ucl_nrv2b_compress(char *inbuf, size_t insize, char *outbuf, size_t outsize, size_t level, size_t, char*)
{
	ucl_uint complen;
	int res = ucl_nrv2b_99_compress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &complen, NULL, level, NULL, NULL);

	if (res != UCL_E_OK) return 0;
	return complen;
}
예제 #2
0
int upx_ucl_compress       ( const upx_bytep src, unsigned  src_len,
                                   upx_bytep dst, unsigned* dst_len,
                                   upx_callback_p cb_parm,
                                   int method, int level,
                             const upx_compress_config_t *cconf_parm,
                                   upx_compress_result_t *cresult )
{
    int r;
    assert(level > 0); assert(cresult != NULL);

    COMPILE_TIME_ASSERT(sizeof(ucl_compress_config_t) == sizeof(REAL_ucl_compress_config_t))

    ucl_progress_callback_t cb;
    cb.callback = 0;
    cb.user = NULL;
    if (cb_parm && cb_parm->nprogress) {
        cb.callback = wrap_nprogress_ucl;
        cb.user = cb_parm;
    }

    ucl_compress_config_t cconf; cconf.reset();
    if (cconf_parm)
        memcpy(&cconf, &cconf_parm->conf_ucl, sizeof(cconf)); // cconf = cconf_parm->conf_ucl; // struct copy

    ucl_uint *res = cresult->result_ucl.result;
    // assume no info available - fill in worst case results
    //res[0] = 1;                 // min_offset_found - NOT USED
    res[1] = src_len - 1;       // max_offset_found
    //res[2] = 2;                 // min_match_found - NOT USED
    res[3] = src_len - 1;       // max_match_found
    //res[4] = 1;                 // min_run_found - NOT USED
    res[5] = src_len;           // max_run_found
    res[6] = 1;                 // first_offset_found
    //res[7] = 999999;            // same_match_offsets_found - NOT USED

    // prepare bit-buffer settings
    cconf.bb_endian = 0;
    cconf.bb_size = 0;
    if (method >= M_NRV2B_LE32 && method <= M_NRV2E_LE16)
    {
        static const unsigned char sizes[3] = {32, 8, 16};
        cconf.bb_size = sizes[(method - M_NRV2B_LE32) % 3];
    }
    else {
        throwInternalError("unknown compression method");
        return UPX_E_ERROR;
    }

    // optimize compression parms
    if (level <= 3 && cconf.max_offset == UCL_UINT_MAX)
        cconf.max_offset = 8*1024-1;
    else if (level == 4 && cconf.max_offset == UCL_UINT_MAX)
        cconf.max_offset = 32*1024-1;

    if M_IS_NRV2B(method)
        r = ucl_nrv2b_99_compress(src, src_len, dst, dst_len,
                                  &cb, level, &cconf, res);
    else if M_IS_NRV2D(method)
예제 #3
0
파일: zbin.c 프로젝트: 42wim/ipxe
static int process_zinfo_pack ( struct input_file *input,
				struct output_file *output,
				union zinfo_record *zinfo ) {
	struct zinfo_pack *pack = &zinfo->pack;
	size_t offset = pack->offset;
	size_t len = pack->len;
	unsigned long packed_len;

	if ( ( offset + len ) > input->len ) {
		fprintf ( stderr, "Input buffer overrun on pack\n" );
		return -1;
	}

	output->len = align ( output->len, pack->align );
	if ( output->len > output->max_len ) {
		fprintf ( stderr, "Output buffer overrun on pack\n" );
		return -1;
	}

	if ( ucl_nrv2b_99_compress ( ( input->buf + offset ), len,
				     ( output->buf + output->len ),
				     &packed_len, 0 ) != UCL_E_OK ) {
		fprintf ( stderr, "Compression failure\n" );
		return -1;
	}

	if ( DEBUG ) {
		fprintf ( stderr, "PACK [%#zx,%#zx) to [%#zx,%#zx)\n",
			  offset, ( offset + len ), output->len,
			  ( size_t )( output->len + packed_len ) );
	}

	output->len += packed_len;
	if ( output->len > output->max_len ) {
		fprintf ( stderr, "Output buffer overrun on pack\n" );
		return -1;
	}

	return 0;
}
예제 #4
0
int64_t lzbench_ucl_compress(char *inbuf, size_t insize, char *outbuf, size_t outsize, size_t algo, size_t level, size_t)
{
    ucl_uint complen;
    int res;

    switch (algo)
    {
    default:
    case 1:
        res = ucl_nrv2b_99_compress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &complen, NULL, level, NULL, NULL);
        break;
    case 2:
        res = ucl_nrv2d_99_compress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &complen, NULL, level, NULL, NULL);
        break;
    case 3:
        res = ucl_nrv2e_99_compress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &complen, NULL, level, NULL, NULL);
        break;
    }

    if (res != UCL_E_OK) return 0;
    return complen;
}
예제 #5
0
int Compression::DoCompression(void *src, unsigned int lenSrc, void *dst, unsigned int lenDst)
{
#ifndef STAND_ALONE_GAME
	//Compress buf and put in src	
	/*in.ir(src, lenSrc);
	out.iw(dst, lenDst);
	
	  comp();
	  
	return out.getNBytes();*/
	
	
	//Fast lzo compression
	//HEAP_ALLOC(wrkmem,LZO1X_1_MEM_COMPRESS);
	//lzo1x_1_compress((unsigned char *)src, lenSrc, (unsigned char *)dst, &lenDst, wrkmem);
	
	//Ucl
	if(!bUclOk) return lenSrc;
	
	
	if(ucl_nrv2b_99_compress((const unsigned char *)src, lenSrc, (unsigned char *)dst, (unsigned int *)&lenDst, NULL, 10, NULL, NULL) != UCL_E_OK)
	{
		return lenSrc;
	}
	
	if(lenDst >= lenSrc)
	{
		//No compression
		return lenSrc;
	}
	
	return lenDst;
#else
	return lenSrc;
#endif
}
예제 #6
0
파일: simple.c 프로젝트: cbenning/Maitland
int main(int argc, char *argv[])
{
    int r;
    ucl_bytep in;
    ucl_bytep out;
    ucl_uint in_len;
    ucl_uint out_len;
    ucl_uint new_len;
    int level = 5;                  /* compression level (1-10) */

    if (argc < 0 && argv == NULL)   /* avoid warning about unused args */
        return 0;

    printf("\nUCL data compression library (v%s, %s).\n",
            ucl_version_string(), ucl_version_date());
    printf("Copyright (C) 1996-2003 Markus Franz Xaver Johannes Oberhumer\n");
    printf("http://www.oberhumer.com/opensource/ucl/\n\n");


/*
 * Step 1: initialize the UCL library
 */
    if (ucl_init() != UCL_E_OK)
    {
        printf("internal error - ucl_init() failed !!!\n");
        printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable `-DUCL_DEBUG' for diagnostics)\n");
        return 1;
    }


/*
 * Step 2: setup memory
 *
 * We want to compress the data block at `in' with length `in_len' to
 * the block at `out'. Because the input block may be incompressible,
 * we must provide a little more output space in case that compression
 * is not possible.
 */
    in_len = 256 * 1024L;

#if defined(ACC_MM_AHSHIFT)
    /* reduce memory requirements for ancient 640kB DOS real-mode */
    if (ACC_MM_AHSHIFT != 3)
        in_len = 16 * 1024L;
#endif

    out_len = in_len + in_len / 8 + 256;

    in = (ucl_bytep) ucl_malloc(in_len);
    out = (ucl_bytep) ucl_malloc(out_len);
    if (in == NULL || out == NULL)
    {
        printf("out of memory\n");
        return 2;
    }


/*
 * Step 3: prepare the input block that will get compressed.
 *         We just fill it with zeros in this example program,
 *         but you would use your real-world data here.
 */
    ucl_memset(in, 0, in_len);


/*
 * Step 4: compress from `in' to `out' with UCL NRV2B
 */
    r = ucl_nrv2b_99_compress(in,in_len,out,&out_len,NULL,level,NULL,NULL);
    if (r == UCL_E_OUT_OF_MEMORY)
    {
        printf("out of memory in compress\n");
        return 3;
    }
    if (r == UCL_E_OK)
        printf("compressed %lu bytes into %lu bytes\n",
            (long) in_len, (long) out_len);
    else
    {
        /* this should NEVER happen */
        printf("internal error - compression failed: %d\n", r);
        return 4;
    }
    /* check for an incompressible block */
    if (out_len >= in_len)
    {
        printf("This block contains incompressible data.\n");
        return 0;
    }


/*
 * Step 5: decompress again, now going back from `out' to `in'
 */
    new_len = in_len;
#if defined(UCL_USE_ASM)
    r = ucl_nrv2b_decompress_asm_8(out,out_len,in,&new_len,NULL);
#else
    r = ucl_nrv2b_decompress_8(out,out_len,in,&new_len,NULL);
#endif
    if (r == UCL_E_OK && new_len == in_len)
        printf("decompressed %lu bytes back into %lu bytes\n",
            (long) out_len, (long) in_len);
    else
    {
        /* this should NEVER happen */
        printf("internal error - decompression failed: %d\n", r);
        return 5;
    }

    ucl_free(out);
    ucl_free(in);
    printf("\n");
#if defined(UCL_USE_ASM)
    printf("i386 assembler version is enabled.\n");
#endif
    printf("Simple compression test passed.\n");
    return 0;
}