static int fetch_icstream(struct icstream *ics) { #if WITH_LZO int retval; unsigned short int *iptr = ics->ibuf; lzo_uint ilen = 2 * sizeof(*iptr), olen, clen; if (read_istream(ics->impl, iptr, ilen) < ilen) goto fail_io; ilen = *iptr++; olen = *iptr++; if (olen > ics->size) goto fail_size; if (read_istream(ics->impl, iptr, ilen) < ilen) goto fail_io; retval = lzo1x_decompress((unsigned char*)iptr, ilen, ics->obuf, &clen, NULL); if (retval != LZO_E_OK) goto fail_lzo; ics->used = olen; ics->free = 0; return 0; fail_io: return -1; fail_lzo: return -2; fail_size: return -3; #else ics->used = read_istream(ics->impl, ics->obuf, ics->size); ics->free = 0; return 0; #endif }
long lzo_read_file( lzo_archive *archive, lzo_file_info *info, void *pOutData ) { /// read the compress data unsigned char *com_buf = (unsigned char *) malloc( info->com_size ); fseek( archive->fp, info->offset, SEEK_SET ); fread( com_buf, info->com_size, 1, archive->fp ); /// decompress the data lzo_uint tsize; int r = lzo1x_decompress( com_buf, info->com_size, (lzo_bytep) pOutData, &tsize, NULL ); if( r != LZO_E_OK ) { lzo_error_func( _lzo_error( "decompression file %s failed: %d\n", info->name, r ) ); return 0; } else { lzo_error_func( _lzo_error( "%s decompressed file %s %lu bytes back into %lu bytes\n", archive->name, info->name, (lzo_uint)info->com_size, tsize ) ); } /// free resources free( com_buf ); return tsize; }
int bmz_lz_unpack(const void *in, size_t in_len, void *out, size_t *out_len_p) { lzo_uint olen = *out_len_p; int ret = lzo1x_decompress((Byte *)in, in_len, (Byte *)out, &olen, NULL); *out_len_p = olen; return ret; }
void ClientConnection::ReadUltraRect(rfbFramebufferUpdateRectHeader *pfburh) { UINT numpixels = pfburh->r.w * pfburh->r.h; // this assumes at least one byte per pixel. Naughty. UINT numRawBytes = numpixels * m_minPixelBytes; UINT numCompBytes; lzo_uint new_len; rfbZlibHeader hdr; // Read in the rfbZlibHeader omni_mutex_lock l(m_bitmapdcMutex); ReadExact((char *)&hdr, sz_rfbZlibHeader); numCompBytes = Swap32IfLE(hdr.nBytes); // Read in the compressed data CheckBufferSize(numCompBytes); ReadExact(m_netbuf, numCompBytes); CheckZlibBufferSize(numRawBytes); lzo1x_decompress((BYTE*)m_netbuf,numCompBytes,(BYTE*)m_zlibbuf,&new_len,NULL); SoftCursorLockArea(pfburh->r.x, pfburh->r.y,pfburh->r.w,pfburh->r.h); if (!Check_Rectangle_borders(pfburh->r.x, pfburh->r.y,pfburh->r.w,pfburh->r.h)) return; if (m_DIBbits) ConvertAll(pfburh->r.w,pfburh->r.h,pfburh->r.x, pfburh->r.y,m_myFormat.bitsPerPixel/8,(BYTE *)m_zlibbuf,(BYTE *)m_DIBbits,m_si.framebufferWidth); }
bool LzoCompression::DoUncompress(const char* str, size_t length, std::string* out) { try_again_with_a_bigger_buffer: lzo_uint out_len = un_buff_size_; int lzo_ret = lzo1x_decompress(reinterpret_cast<const unsigned char*>(str), length, uncompressed_buff_, &out_len, NULL); if (lzo_ret == LZO_E_OK) { VLOG(28) << "in:" << length << ", out:" << out_len; out->assign(reinterpret_cast<const char*>(uncompressed_buff_), out_len); return true; } else if (lzo_ret == LZO_E_OUTPUT_OVERRUN) { if (un_buff_size_ >= max_unCompressed_size_) { return false; } un_buff_size_ *= 2; delete [] uncompressed_buff_; uncompressed_buff_ = new unsigned char[un_buff_size_]; VLOG(28) << "LZO_E_OUTPUT_OVERRUN, trying again with " << un_buff_size_ << "byte buffer"; goto try_again_with_a_bigger_buffer; } else { LOG(ERROR)<< "fail to Uncompress data!"; return false; } return false; }
uint32 Decompress(const unsigned char* lzoBuff, uint32 lzoBuffLen, iDynamicBuffer& rawBuff) { uint16 hdr; memcpy(&hdr, lzoBuff, sizeof(uint16)); lzoBuffLen -= sizeof(uint16); lzoBuff += sizeof(uint16); if (hdr != LZO_BLOCK_HDR) { check(0); return 0; } unsigned long raw_buf_len; memcpy(&raw_buf_len, lzoBuff, sizeof(unsigned long)); lzoBuffLen -= sizeof(uint32); lzoBuff += sizeof(uint32); if (raw_buf_len <= 0 || raw_buf_len > LZO_MAX_BUF_LEN) { check(0); return 0; } rawBuff.ReInit(raw_buf_len); rawBuff.IncSize( raw_buf_len ); int res = lzo1x_decompress(lzoBuff,lzoBuffLen,(unsigned char*)rawBuff.GetData(),&raw_buf_len,NULL); if (res != LZO_E_OK) { check(0); return 0; } return raw_buf_len; }
JNIEXPORT jint JNICALL Java_com_dynatrace_diagnostics_sdk_io_LZOCompression_dynMemDecompress (JNIEnv *env, jclass, jbyteArray src, jint offset, jint srcLen, jbyteArray dest) { lzo_uint destLen=0; jbyte *srcBuf = (jbyte*)malloc(srcLen*sizeof(jbyte)); env->GetByteArrayRegion(src, offset, srcLen, srcBuf); if (env->ExceptionOccurred()) { return -1; } int destArraySize=env->GetArrayLength(dest); jbyte *destBuf = (jbyte*)malloc(destArraySize*sizeof(jbyte)); int result = lzo1x_decompress((unsigned char*)srcBuf,srcLen, (unsigned char*)destBuf, &destLen, wrkmem); if (result!=LZO_E_OK) { free(srcBuf); free(destBuf); return -1; } env->SetByteArrayRegion(dest, 0, (jsize)destLen, destBuf); if (env->ExceptionOccurred()) { return -1; } free(srcBuf); free(destBuf); return (jsize)destLen; }
/********************************************************* Decompress Method *********************************************************/ int Compression::decompress(void *dest, int destLen, int sourceLen) { void *source = getBuf(); int compressingMethod = gConfig->networkCompression; uLongf newSource = sourceLen; uLongf newDest = destLen; int ret = 0; if(sourceLen > 4) { if(compressingMethod == 1) ret = uncompress((Bytef*) dest, (uLongf*) &newDest, (const Bytef*)source, newSource); else if(compressingMethod == 2) ret = lzo1b_decompress((const Bytef*)source, newSource, (Bytef*) dest, &newDest, NULL); else if(compressingMethod == 3) ret = lzo1x_decompress((const Bytef*)source, newSource, (Bytef*) dest, &newDest, NULL); if(compressingMethod == 1) { if(ret != Z_OK) { if(ret == Z_MEM_ERROR){ LOG("ERROR decompressing: memory error\n"); }else if(ret == Z_BUF_ERROR){ LOG("ERROR decompressing: buffer error\n"); }else if(ret == Z_DATA_ERROR){ LOG("ERROR decompressing: data error,\n"); } } } } else { memcpy(dest, source, sourceLen); } return (int)newDest; }
bool LZOCompressedReaderAdapter::fill_buffer() { size_t buffer_size; if (read_uint64(m_file, buffer_size) == 0) return false; ensure_minimum_size(m_buffer, buffer_size); lzo_uint compressed_buffer_size; read_uint64(m_file, compressed_buffer_size); ensure_minimum_size(m_compressed_buffer, compressed_buffer_size); m_file.read(&m_compressed_buffer[0], compressed_buffer_size); lzo_uint new_buffer_end; lzo1x_decompress( &m_compressed_buffer[0], compressed_buffer_size, &m_buffer[0], &new_buffer_end, &m_working_memory[0]); m_buffer_index = 0; m_buffer_end = static_cast<size_t>(new_buffer_end); return true; }
static int lzo_decompress_buf(struct stream *s, i64 c_len) { uchar *c_buf; lzo_uint dlen = s->buflen; int lzerr; c_buf = s->buf; s->buf = malloc(dlen); if (!s->buf) { err_msg("Failed to allocate %d bytes for decompression\n", dlen); return -1; } lzerr = lzo1x_decompress((uchar*)c_buf,c_len,(uchar*)s->buf,&dlen,NULL); if (lzerr != LZO_E_OK) { err_msg("Failed to decompress buffer - lzerr=%d\n", lzerr); return -1; } if ((i64)dlen != s->buflen) { err_msg("Inconsistent length after decompression. Got %d bytes, expected %d\n", dlen, s->buflen); return -1; } free(c_buf); return 0; }
static void unlzo(pbuf_t *pbuf) { uint8_t out[2048]; lzo_uint olen; lzo1x_decompress(pbuf->payload, pbuf->len, out, &olen, NULL); memcpy(pbuf->payload, out, olen); pbuf->len = olen; }
int64_t lzbench_lzo1x_decompress(char *inbuf, size_t insize, char *outbuf, size_t outsize, size_t level, size_t, char*) { lzo_uint decomplen = 0; if (lzo1x_decompress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &decomplen, NULL) != LZO_E_OK) return 0; return decomplen; }
int ckptReadChunkData(ckptImage * image, void *data) { #ifdef ENABLE_COMPRESSION size_t processed = 0; lzo_uint decompressed_len; compressed_header c_header; if (image->is_compressed) { while (processed < image->next) { if (F_REAL_READ(image->fd, &c_header, sizeof(c_header)) != sizeof(c_header)) { ckptLog(CKPT_LOG_ERROR, "Error reading compression header"); return 0; } if (F_REAL_READ(image->fd, compress_temp, c_header.compressed_size) != c_header.compressed_size) { ckptLog(CKPT_LOG_ERROR, "Error reading compressed data"); return 0; } if (lzo1x_decompress(compress_temp, c_header.compressed_size, data, &decompressed_len, NULL) != LZO_E_OK || decompressed_len != c_header.size) { ckptLog(CKPT_LOG_ERROR, "Error while decompressing"); return 0; } processed += c_header.compressed_size + sizeof(c_header); data = (char *)data + c_header.size; } } else { if (F_REAL_READ(image->fd, data, image->next) != image->next) { ckptLog(CKPT_LOG_ERROR, "Error reading chunk, offset %p, size %x: %m", data, image->next); return 0; } } #else if (F_REAL_READ(image->fd, data, image->next) != image->next) { ckptLog(CKPT_LOG_ERROR, "Error reading chunk, offset %p, size %x: %m", data, image->next); return 0; } #endif return 1; }
static void lzo_uncompress_chunk(void *fptr) { struct lzo_data *ld = fptr; int r; r = lzo1x_decompress(ld->out, ld->out_len, ld->in, &ld->in_len, NULL); if (r != LZO_E_OK) bail("LZO decompression error: %d", r); assert(ld->in_len <= IN_LEN); ld->in_used = 0; }
BOOL KScriptServer::Accept(KPlayer* pPlayer, const char cszFunction[], BYTE* pbyData, size_t uDataLen) { BOOL bResult = false; BOOL bRetCode = false; int nRetCode = 0; int nIndex = 0; ILuaScriptEx* piScript = NULL; Lua_State* L = NULL; BYTE* pbyNext = NULL; BYTE* pbyTail = NULL; size_t uSrcLen = sizeof(m_byOriginalBuffer); assert(pPlayer); assert(pPlayer->m_pScene); g_pSO3World->m_ScriptCenter.SafeCallBegin(&nIndex); nRetCode = lzo1x_decompress(pbyData, (lzo_uint)uDataLen, m_byOriginalBuffer, (lzo_uint*)&uSrcLen, NULL); KGLOG_PROCESS_ERROR(nRetCode == LZO_E_OK); pbyNext = m_byOriginalBuffer; pbyTail = m_byOriginalBuffer + uSrcLen; bRetCode = g_pSO3World->m_ScriptCenter.IsScriptExist(m_dwScript); KG_PROCESS_ERROR(bRetCode); bRetCode = g_pSO3World->m_ScriptCenter.IsFuncExist(m_dwScript, cszFunction); KG_PROCESS_ERROR(bRetCode); piScript = g_pSO3World->m_ScriptCenter.GetScriptHolder(); KGLOG_PROCESS_ERROR(piScript); L = piScript->GetLuaState(); KGLOG_PROCESS_ERROR(L); pPlayer->LuaGetObj(L); piScript->AddParamCount(); while (pbyNext < pbyTail) { pbyNext = LuaUnpack(L, pbyNext, (size_t)(pbyTail - pbyNext)); KGLOG_PROCESS_ERROR(pbyNext); piScript->AddParamCount(); } g_pSO3World->m_ScriptCenter.CallFunction(m_dwScript, cszFunction, 0); bResult = true; Exit0: g_pSO3World->m_ScriptCenter.SafeCallEnd(nIndex); return bResult; }
bool Compress::FromLZO( U8* pSrcData, UInt uiSrcSize, U8* pDstData, U32* uiDstSize){ int r = lzo1x_decompress(pSrcData,uiSrcSize,pDstData,uiDstSize,NULL); if (r == LZO_E_OK && uiSrcSize == *uiDstSize){ return true; }else{ return false; } return true; }
T_STATUS I_ZL_LZO_uncompress ( OUT void *dest, OUT long *destLen, IN void *source, IN long sourceLen ) { #if defined(HAVE_LZO_H) int r ; /* * check lzo_init was called. */ if (I_ZL_LZO_isInit == FALSE) { r = lzo_init() ; if (r != LZO_E_OK) return STATUS_ERROR ; I_ZL_LZO_isInit = TRUE ; } /* * decompress */ r = lzo1x_decompress ( source, (lzo_uint)sourceLen, dest, (lzo_uint *)destLen, NULL ) ; /* * return 'r' */ return (r == LZO_E_OK) ? ZL_OK : STATUS_ERROR ; #else X_ALLOC_MemMove(dest, source, MIN((*destLen),sourceLen)) ; /* * return 'r' */ return ZL_OK ; #endif }
void ClientConnection::ReadUltraZip(rfbFramebufferUpdateRectHeader *pfburh,HRGN *prgn) { UINT nNbCacheRects = pfburh->r.x; UINT numRawBytes = pfburh->r.y+pfburh->r.w*65535; UINT numCompBytes; lzo_uint new_len; rfbZlibHeader hdr; // Read in the rfbZlibHeader omni_mutex_lock l(m_bitmapdcMutex); ReadExact((char *)&hdr, sz_rfbZlibHeader); numCompBytes = Swap32IfLE(hdr.nBytes); // Check the net buffer CheckBufferSize(numCompBytes); // Read the compressed data ReadExact((char *)m_netbuf, numCompBytes); // Verify buffer space for cache rects list CheckZlibBufferSize(numRawBytes+500); lzo1x_decompress((BYTE*)m_netbuf,numCompBytes,(BYTE*)m_zlibbuf,&new_len,NULL); BYTE* pzipbuf = m_zlibbuf; for (UINT i = 0 ; i < nNbCacheRects; i++) { rfbFramebufferUpdateRectHeader surh; memcpy((char *) &surh,pzipbuf, sz_rfbFramebufferUpdateRectHeader); surh.r.x = Swap16IfLE(surh.r.x); surh.r.y = Swap16IfLE(surh.r.y); surh.r.w = Swap16IfLE(surh.r.w); surh.r.h = Swap16IfLE(surh.r.h); surh.encoding = Swap32IfLE(surh.encoding); pzipbuf += sz_rfbFramebufferUpdateRectHeader; RECT rect; rect.left = surh.r.x; rect.right = surh.r.x + surh.r.w; rect.top = surh.r.y; rect.bottom = surh.r.y + surh.r.h; //border check if (!Check_Rectangle_borders(rect.left,rect.top,surh.r.w,surh.r.h)) return; SoftCursorLockArea(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); if ( surh.encoding==rfbEncodingRaw) { UINT numpixels = surh.r.w * surh.r.h; if (m_DIBbits) ConvertAll(surh.r.w,surh.r.h,surh.r.x, surh.r.y,m_myFormat.bitsPerPixel/8,(BYTE *)pzipbuf,(BYTE *)m_DIBbits,m_si.framebufferWidth); pzipbuf +=numpixels*m_myFormat.bitsPerPixel/8; if (!m_opts.m_Directx)InvalidateRegion(&rect,prgn); } } }
int decomp_lzo(int len, char *in, char **out) { unsigned int zlen = 0; int err; if( (err=lzo1x_decompress((void *)in,len,zbuf,&zlen,wmem)) != LZO_E_OK ){ vtun_syslog(LOG_ERR,"Decompress error %d",err); return -1; } *out = (void *) zbuf; return zlen; }
MemDataChunk* ImageMDCodec::decompression(MemDataChunk* compressed_payload, Uint16 payload_size) const { if (lzo_init() != LZO_E_OK) { LOG_ERROR("LZO initialization failed for decompression procedure!\n"); return 0; } lzo_uint data_size; Uint8* output_data = new Uint8[65535]; lzo1x_decompress(compressed_payload->get_data(), payload_size, output_data, &data_size, NULL); MemDataChunk* decompressed_payload = new MemDataChunk(); decompressed_payload->append_data((Uint32)data_size, output_data); delete [] output_data; return decompressed_payload; }
int lzode(char *srcfile, char *destfile) { int result; int fd; struct stat s; lzo_bytep in=RT_NULL; lzo_bytep out=RT_NULL; lzo_uint in_len, out_len; rt_memset(&s, 0, sizeof(struct stat)); stat(srcfile, &s); in_len = s.st_size; fd = open(srcfile, O_RDONLY, 0); if(fd < 0) return 0; read(fd, &out_len, sizeof(lzo_uint)); /* source file len */ in_len -= sizeof(lzo_uint); in = rt_malloc(in_len); if (in == RT_NULL) return -1; out = rt_malloc(out_len); if (out == RT_NULL) return -1; read(fd, in, in_len); close(fd); result = lzo1x_decompress(in, in_len, out, &out_len, RT_NULL); if(result != LZO_E_OK) { rt_kprintf("internal error - decompression failed: \nerr_code:(%d) %s, %s.\n", result, parse_lzo_error_code(result), "Please use the binary access"); goto _exit; } fd = open(destfile, O_WRONLY | O_BINARY | O_CREAT, 0); if(fd < 0) { result = -1; goto _exit; } write(fd, out, out_len); close(fd); rt_kprintf("decompress lzo ok!\n"); result = 0; _exit: rt_free(in); rt_free(out); return result; }
void Decompress(const lzo_bytep data, size_t size, std::vector<T>& out) { lzo_uint countBsLZO=size*sizeof(T); int32_t r = lzo1x_decompress( data, size, reinterpret_cast<lzo_bytep>(&out.front()), &countBsLZO, NULL); if (r != LZO_E_OK) { Util::fire_exception("lzo decompress failed", r); } }
int r3dFSCompress::DecompressLzo(const BYTE* in_data, const DWORD in_csize, const DWORD in_size, BYTE* out_data, DWORD* out_size) { initLzoLib(); lzo_uint new_len = 0; int err = lzo1x_decompress(in_data, in_csize, out_data, &new_len, NULL); if (err != LZO_E_OK || new_len != in_size) { r3dOutToLog("LZO: lzo1x_decompress failed %d\n", err); return 0; } *out_size = new_len; return 1; }
bool CTextureBundleXBT::ConvertFrameToTexture(const CStdString& name, CXBTFFrame& frame, CBaseTexture** ppTexture) { // found texture - allocate the necessary buffers squish::u8 *buffer = new squish::u8[(size_t)frame.GetPackedSize()]; if (buffer == NULL) { CLog::Log(LOGERROR, "Out of memory loading texture: %s (need %"PRIu64" bytes)", name.c_str(), frame.GetPackedSize()); return false; } // load the compressed texture if (!m_XBTFReader.Load(frame, buffer)) { CLog::Log(LOGERROR, "Error loading texture: %s", name.c_str()); delete[] buffer; return false; } // check if it's packed with lzo if (frame.IsPacked()) { // unpack squish::u8 *unpacked = new squish::u8[(size_t)frame.GetUnpackedSize()]; if (unpacked == NULL) { CLog::Log(LOGERROR, "Out of memory unpacking texture: %s (need %"PRIu64" bytes)", name.c_str(), frame.GetUnpackedSize()); delete[] buffer; return false; } lzo_uint s = (lzo_uint)frame.GetUnpackedSize(); if (lzo1x_decompress(buffer, (lzo_uint)frame.GetPackedSize(), unpacked, &s, NULL) != LZO_E_OK || s != frame.GetUnpackedSize()) { CLog::Log(LOGERROR, "Error loading texture: %s: Decompression error", name.c_str()); delete[] buffer; delete[] unpacked; return false; } delete[] buffer; buffer = unpacked; } // create an xbmc texture *ppTexture = new CTexture(); (*ppTexture)->LoadFromMemory(frame.GetWidth(), frame.GetHeight(), 0, frame.GetFormat(), buffer); delete[] buffer; return true; }
bool DecompressBufferLZO( char* szOutBuffer,size_t stOrgDataSize,const char* szData,size_t stSize ) { //FILE* fp=fopen("decompress.txt","a"); //fwrite(szData,1,stSize,fp); //fclose(fp); lzo_uint uOutSize=lzo_uint(stOrgDataSize); bool bResult=( LZO_E_OK == lzo1x_decompress( reinterpret_cast<const lzo_bytep>( szData ) , lzo_uint( stSize ) ,reinterpret_cast<lzo_bytep>( szOutBuffer ), &uOutSize,NULL ) ); Ast( stOrgDataSize >= uOutSize ); return bResult; }
MpalHandle RMResUpdate::queryResource(uint32 dwRes) { // If there isn't an update file, return NULL if (!_hFile.isOpen()) return NULL; uint32 i; for (i = 0; i < _numUpd; ++i) if (_infos[i]._dwRes == dwRes) // Found the index break; if (i == _numUpd) // Couldn't find a matching resource, so return NULL return NULL; const ResUpdInfo &info = _infos[i]; byte *cmpBuf = new byte[info._cmpSize]; uint32 dwRead; // Move to the correct offset and read in the compressed data _hFile.seek(info._offset); dwRead = _hFile.read(cmpBuf, info._cmpSize); if (info._cmpSize > dwRead) { // Error occurred reading data, so return NULL delete[] cmpBuf; return NULL; } // Allocate space for the output resource MpalHandle destBuf = globalAllocate(0, info._size); byte *lpDestBuf = (byte *)globalLock(destBuf); uint32 dwSize; // Decompress the data lzo1x_decompress(cmpBuf, info._cmpSize, lpDestBuf, &dwSize); // Delete buffer for compressed data delete [] cmpBuf; // Return the resource globalUnlock(destBuf); return destBuf; }
rt_private size_t parsing_retrieve_read_with_compression (void) { RT_GET_CONTEXT void* dcmps_in_ptr = (char *)0; void* dcmps_out_ptr = (char *)0; lzo_uint dcmps_in_size = 0; lzo_uint dcmps_out_size = (lzo_uint) cmp_buffer_size; char* ptr = (char *)0; int read_size = 0; int part_read = 0; int l_bytes_read; REQUIRE("cmp_buffer_size not too big", cmp_buffer_size <= 0xFFFFFFFF); ptr = cmps_general_buffer; l_bytes_read = char_read_func ((char *) &read_size, sizeof(int)); if ((l_bytes_read < 0) || ((size_t) l_bytes_read < sizeof(int))) { eio(); } dcmps_in_size = read_size; while (read_size > 0) { part_read = char_read_func (ptr, read_size); if (part_read <= 0) /* If we read 0 bytes, it means that we reached the end of file, * so we are missing something, instead of going further we stop */ eio(); read_size -= part_read; ptr += part_read; } dcmps_in_ptr = cmps_general_buffer; dcmps_out_ptr = general_buffer; lzo1x_decompress (dcmps_in_ptr, dcmps_in_size, dcmps_out_ptr, &dcmps_out_size, NULL); CHECK("dcmps_out_size_positive", dcmps_out_size > 0); return dcmps_out_size; }
int64_t lzbench_lzo_decompress(char *inbuf, size_t insize, char *outbuf, size_t outsize, size_t level, size_t, size_t) { lzo_uint decomplen = 0; switch (level) { default: case 1: case 9: case 99: case 999: if (lzo1b_decompress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &decomplen, NULL) != LZO_E_OK) return 0; break; case 1001: case 1009: case 1099: case 1999: if (lzo1c_decompress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &decomplen, NULL) != LZO_E_OK) return 0; break; case 2001: case 2999: if (lzo1f_decompress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &decomplen, NULL) != LZO_E_OK) return 0; break; case 3001: case 3999: if (lzo1x_decompress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &decomplen, NULL) != LZO_E_OK) return 0; break; case 4001: case 4999: if (lzo1y_decompress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &decomplen, NULL) != LZO_E_OK) return 0; break; case 5999: if (lzo1z_decompress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &decomplen, NULL) != LZO_E_OK) return 0; break; case 6999: if (lzo2a_decompress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &decomplen, NULL) != LZO_E_OK) return 0; break; } return decomplen; }
int lcdLoadLZOImage(char *fname) { unsigned char img[864]; UINT readbytes; FRESULT ret; FIL file; uint16_t sz; lzo_uint len; ret=f_open(&file, fname, FA_OPEN_EXISTING|FA_READ); if(ret) return 1; ret = lzo_init(); if(ret) return 2; ret = f_read(&file, &sz, 2, &readbytes); if(ret || readbytes != 2) { return 3; } if(sz == 0) { // uncompressed ret = f_read(&file, (unsigned char *)lcdBuffer, 864, &readbytes); if(ret) return 4; } else { ret = f_read(&file, img, sz, &readbytes); if(ret || readbytes != sz) { return 5; } lzo1x_decompress(img, sz, (unsigned char *)lcdBuffer, &len, NULL); } f_close(&file); return 0; }
bool Compression::Decompression(void *src, unsigned int lenSrc, void *dst, unsigned int lenDst, bool bCheckVersion) { if(bCheckVersion) { if(GameControl::Get()->GetGameFileVersion() < 19) { ind.ir(src, lenSrc); outd.iw(dst, lenDst); decomp(); } else if(GameControl::Get()->GetGameFileVersion() < 20) { //Fast lzo decompression lzo1x_decompress((unsigned char *)src, lenSrc, (unsigned char *)dst, &lenDst, NULL); } else { //Ucl if(!bUclOk) return false; return ucl_nrv2b_decompress_8((const unsigned char *)src, lenSrc, (unsigned char *)dst, (unsigned int *)&lenDst, NULL) == UCL_E_OK; } } else { //Ucl if(!bUclOk) return false; return ucl_nrv2b_decompress_8((const unsigned char *)src, lenSrc, (unsigned char *)dst, (unsigned int *)&lenDst, NULL) == UCL_E_OK; } return true; }