📄 bz2.c
字号:
/*********************************************************************
*
* Copyright:
* MOTOROLA, INC. All Rights Reserved.
* You are hereby granted a copyright license to use, modify, and
* distribute the SOFTWARE so long as this entire notice is
* retained without alteration in any modified and/or redistributed
* versions, and that such modified versions are clearly identified
* as such. No licenses are granted by implication, estoppel or
* otherwise under any patents or trademarks of Motorola, Inc. This
* software is provided on an "AS IS" basis and without warranty.
*
* To the maximum extent permitted by applicable law, MOTOROLA
* DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED, INCLUDING
* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
* PURPOSE AND ANY WARRANTY AGAINST INFRINGEMENT WITH REGARD TO THE
* SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF) AND ANY
* ACCOMPANYING WRITTEN MATERIALS.
*
* To the maximum extent permitted by applicable law, IN NO EVENT
* SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING
* WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS
* INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY
* LOSS) ARISING OF THE USE OR INABILITY TO USE THE SOFTWARE.
*
* Motorola assumes no responsibility for the maintenance and support
* of this software
********************************************************************/
/*
* File: bz2.c
* Purpose: Data definitions and routines for decompress bz2 files.
*
* Notes:
*
*
* Modifications:
* 06-17-99 EJD Use Section Headers rather than Program Headers
*
*/
#include "bzlib.h"
#include "bz2.h"
#include "util.h"
#include "mem_mgr.h"#define BZ2_INPUT_BUFFER_SIZE 4096
#define BZ2_OUTPUT_BUFFER_SIZE (10 * 1024 * 1024)
/********************************************************************/
BUFFER_INTERFACE bufitf;/********************************************************************/
staticvoid* bz2alloc ( void* opaque, int items, int size ){ return bufitf.alloc(opaque, items * size, NULL);}staticvoid bz2free ( void* opaque, void* addr ){ if (addr != NULL) bufitf.free (addr);}/********************************************************************/
void* bz2LoadImage(DataFunctions dataFunctions, const char* fileName)
{
void* entryPoint = (void*) 0; void *mem = (void *)0x82000000; char *bufin, *bufout;
bz_stream strm; int bytesRead, ret; showProgress(0);
if(dataFunctions.open(fileName)) { // initialize buffer GetBufferInterface(&bufitf); bufitf.init(mem, 0x02000000); bufin = (char *)bufitf.alloc(mem, BZ2_INPUT_BUFFER_SIZE, NULL); if (bufin == NULL) goto error; bufout = (char *)bufitf.alloc(mem, BZ2_OUTPUT_BUFFER_SIZE, NULL); if (bufout == NULL) goto error; // check header bytesRead = dataFunctions.read(bufin, BZ2_INPUT_BUFFER_SIZE);
if (bytesRead < 2) goto error; if ((bufin[0] != 'B') || ((bufin[1] != 'Z'))) goto error; // initialize decoder strm.bzalloc = bz2alloc; strm.bzfree = bz2free; strm.opaque = mem; strm.next_in = bufin; strm.avail_in = bytesRead; strm.total_in_lo32 = 0; strm.total_in_hi32 = 0; strm.next_out = bufout; strm.avail_out = BZ2_OUTPUT_BUFFER_SIZE; strm.total_out_lo32 = 0; strm.total_out_hi32 = 0; if (BZ2_bzDecompressInit ( &strm, 0, 0 ) != BZ_OK) goto error; // initialize display showProgress(1);
printf("\n---------------------------------------------\n");
printf("Decompressing Image: %12s (Format = bz2)\n", fileName);
while(1) { // decode ret = BZ2_bzDecompress ( &strm ); if (ret == BZ_OK) { // update display updateProgress(bytesRead);
// read bytesRead = dataFunctions.read(bufin, BZ2_INPUT_BUFFER_SIZE);
if (bytesRead == 0) goto error; strm.next_in = bufin; strm.avail_in = bytesRead; } else if (ret == BZ_STREAM_END) { // update display updateProgress(bytesRead); printf("\nImage Decompressed Successfully.\n"); // return entry point entryPoint = bufout; break; }
else {
// return error printf("\nError Decompressing Image File. \n"); break; }
}
printf("---------------------------------------------\n"); }
error: dataFunctions.close();
return entryPoint;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -