/* testmini.c -- very simple test program for the miniLZO library

    This file is part of the LZO real-time data compression library.

    Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved. The LZO library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version. The LZO library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. You should have received a copy of the GNU General Public License
along with the LZO library; see the file COPYING.
If not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/opensource/lzo/
*/ #include <stdio.h>
#include <stdlib.h> /*************************************************************************
// This program shows the basic usage of the LZO library.
// We will compress a block of data and decompress again.
//
// For more information, documentation, example programs and other support
// files (like Makefiles and build scripts) please download the full LZO
// package from
// http://www.oberhumer.com/opensource/lzo/
**************************************************************************/ /* First let's include "minizo.h". */ #include "minilzo.h" /* 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.
*/ #define IN_LEN (128*1024ul)
#define OUT_LEN (IN_LEN + IN_LEN / 16 + 64 + 3) static unsigned char __LZO_MMODEL in [ IN_LEN ];
static unsigned char __LZO_MMODEL out [ OUT_LEN ]; /* Work-memory needed for compression. Allocate memory in units
* of 'lzo_align_t' (instead of 'char') to make sure it is properly aligned.
*/ #define HEAP_ALLOC(var,size) \
lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - )) / sizeof(lzo_align_t) ] static HEAP_ALLOC(wrkmem, LZO1X_1_MEM_COMPRESS); /*************************************************************************
//
**************************************************************************/ int main(int argc, char *argv[])
{
int r;
lzo_uint in_len;
lzo_uint out_len;
lzo_uint new_len; if (argc < && argv == NULL) /* avoid warning about unused args */
return ; printf("\nLZO real-time data compression library (v%s, %s).\n",
lzo_version_string(), lzo_version_date());
printf("Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); /*
* Step 1: initialize the LZO library
*/
if (lzo_init() != LZO_E_OK)
{
printf("internal error - lzo_init() failed !!!\n");
printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n");
return ;
} /*
* Step 2: 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.
*/
in_len = IN_LEN;
lzo_memset(in,,in_len); /*
* Step 3: compress from 'in' to 'out' with LZO1X-1
*/
r = lzo1x_1_compress(in,in_len,out,&out_len,wrkmem);
if (r == LZO_E_OK)
printf("compressed %lu bytes into %lu bytes\n",
(unsigned long) in_len, (unsigned long) out_len);
else
{
/* this should NEVER happen */
printf("internal error - compression failed: %d\n", r);
return ;
}
/* check for an incompressible block */
if (out_len >= in_len)
{
printf("This block contains incompressible data.\n");
return ;
} /*
* Step 4: decompress again, now going from 'out' to 'in'
*/
new_len = in_len;
r = lzo1x_decompress(out,out_len,in,&new_len,NULL);
if (r == LZO_E_OK && new_len == in_len)
printf("decompressed %lu bytes back into %lu bytes\n",
(unsigned long) out_len, (unsigned long) in_len);
else
{
/* this should NEVER happen */
printf("internal error - decompression failed: %d\n", r);
return ;
} printf("\nminiLZO simple compression test passed.\n");
return ;
} /* vim:set ts=4 sw=4 et: */

testmini.c

首先需要准备好数组,然后知道长度。

第一步:初始化LZO库

    if (lzo_init() != LZO_E_OK) {
...
}

lzo_init

第二步:清空数组,准备存放的缓存

    in_len = IN_LEN;
lzo_memset(in,,in_len);

lzo_memset

第三步:压缩后数据放入缓存中

    r = lzo1x_1_compress(in,in_len,out,&out_len,wrkmem);
if (r == LZO_E_OK)
printf("compressed %lu bytes into %lu bytes\n",
(unsigned long) in_len, (unsigned long) out_len);
else {
/* this should NEVER happen */
printf("internal error - compression failed: %d\n", r);
return ;
} /* check for an incompressible block */
if (out_len >= in_len) {
printf("This block contains incompressible data.\n");
return ;
}

lzo1x_1_compress

最新文章

  1. 第四章 HTML与JavaScript
  2. vs xamarin android StartActivity
  3. XML序列化的时候如何支持Namespace
  4. 利用sqlserver日志恢复数据
  5. Unit testing Cmockery 简单使用
  6. java中的多线程——进度1
  7. HighCharts基本使用实例(入门)
  8. 300M无线路由器 TL-WR842N - TP-LINK官方网站
  9. Android 墙纸设置代码 详细说明
  10. H5 拖放事件详解
  11. ecos的setting
  12. IDEA2019激活码集合(非盈利)
  13. React Native踩坑之旅
  14. 大数据学习笔记4 - Hadoop的优化与发展(Hadoop 2.0)
  15. 能ping通外网的域名,浏览器不能上网的解决办法
  16. 使用ffmpeg从mp4文件中提取视频流到h264文件中
  17. python 类之间的关系
  18. Groovy 学习手册(3)
  19. 百度地图Api进阶教程-点聚合9.html
  20. SNMP学习笔记之SNMP简单概述

热门文章

  1. 整理一下go的ci工具
  2. 正则表达式——Unicode 属性列表
  3. 【Linux开发】OpenCV在ARM上的移植
  4. Docker Toolbox虚拟机文件地址修改 以及镜像加速
  5. c++ k^1
  6. JExcel - 学习总结(1)
  7. win10无法开启网络发现怎么办 如何启用网络发现
  8. ECCV2014 Accepted paper
  9. 简洁的Asp.net菜单控件
  10. 自我笔记,Rides介绍