diff options
Diffstat (limited to 'src/lib')
56 files changed, 693 insertions, 693 deletions
diff --git a/src/lib/formats/pc_dsk.c b/src/lib/formats/pc_dsk.c index 0841c66ebff..7ef11bfb861 100644 --- a/src/lib/formats/pc_dsk.c +++ b/src/lib/formats/pc_dsk.c @@ -300,7 +300,7 @@ bool pc_format::load(io_generic *io, UINT32 form_factor, floppy_image *image) const format &f = formats[type]; if(!f.desc) return false; - + UINT8 sectdata[36*512]; desc_s sectors[36]; for(int i=0; i<f.sector_count; i++) { diff --git a/src/lib/lib7z/7z.h b/src/lib/lib7z/7z.h index 01c4cac6a7b..91c8b3ff021 100644 --- a/src/lib/lib7z/7z.h +++ b/src/lib/lib7z/7z.h @@ -136,17 +136,17 @@ void SzAr_Free(CSzAr *p, ISzAlloc *alloc); *outBufferSize You can consider "*outBuffer" as cache of solid block. If your archive is solid, it will increase decompression speed. - + If you use external function, you can declare these 3 cache variables (blockIndex, outBuffer, outBufferSize) as static in that external function. - + Free *outBuffer and set *outBuffer to 0, if you want to flush cache. */ typedef struct { CSzAr db; - + UInt64 startPosAfterHeader; UInt64 dataPos; diff --git a/src/lib/lib7z/7zCrc.c b/src/lib/lib7z/7zCrc.c index cd94201be97..d82bc7ec5af 100644 --- a/src/lib/lib7z/7zCrc.c +++ b/src/lib/lib7z/7zCrc.c @@ -52,11 +52,11 @@ void MY_FAST_CALL CrcGenerateTable() UInt32 r = g_CrcTable[i - 256]; g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8); } - + #ifdef MY_CPU_LE g_CrcUpdate = CrcUpdateT4; - + #if CRC_NUM_TABLES == 8 if (!CPU_Is_InOrder()) g_CrcUpdate = CrcUpdateT8; diff --git a/src/lib/lib7z/7zIn.c b/src/lib/lib7z/7zIn.c index ec93a43ffec..d7256dde718 100644 --- a/src/lib/lib7z/7zIn.c +++ b/src/lib/lib7z/7zIn.c @@ -537,12 +537,12 @@ static SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc) { UInt32 numCoders, numBindPairs, numPackStreams, i; UInt32 numInStreams = 0, numOutStreams = 0; - + RINOK(SzReadNumber32(sd, &numCoders)); if (numCoders > NUM_FOLDER_CODERS_MAX) return SZ_ERROR_UNSUPPORTED; folder->NumCoders = numCoders; - + MY_ALLOC(CSzCoderInfo, folder->Coders, (size_t)numCoders, alloc); for (i = 0; i < numCoders; i++) @@ -810,7 +810,7 @@ static SRes SzReadSubStreamsInfo( numDigests += numSubstreams; } - + si = 0; for (;;) { @@ -963,8 +963,8 @@ static SRes SzReadHeader2( RINOK(SzReadArchiveProperties(sd)); RINOK(SzReadID(sd, &type)); } - - + + if (type == k7zIdMainStreamsInfo) { RINOK(SzReadStreamsInfo(sd, @@ -982,7 +982,7 @@ static SRes SzReadHeader2( return SZ_OK; if (type != k7zIdFilesInfo) return SZ_ERROR_ARCHIVE; - + RINOK(SzReadNumber32(sd, &numFiles)); p->db.NumFiles = numFiles; @@ -1165,19 +1165,19 @@ static SRes SzReadAndDecodePackedStreams2( RINOK(SzReadStreamsInfo(sd, &dataStartPos, p, &numUnpackStreams, unpackSizes, digestsDefined, digests, allocTemp, allocTemp)); - + dataStartPos += baseOffset; if (p->NumFolders != 1) return SZ_ERROR_ARCHIVE; folder = p->Folders; unpackSize = SzFolder_GetUnpackSize(folder); - + RINOK(LookInStream_SeekTo(inStream, dataStartPos)); if (!Buf_Create(outBuffer, (size_t)unpackSize, allocTemp)) return SZ_ERROR_MEM; - + res = SzFolder_Decode(folder, p->PackSizes, inStream, dataStartPos, outBuffer->data, (size_t)unpackSize, allocTemp); @@ -1240,7 +1240,7 @@ static SRes SzArEx_Open2( nextHeaderCRC = GetUi32(header + 28); p->startPosAfterHeader = startArcPos + k7zStartHeaderSize; - + if (CrcCalc(header + 12, 20) != GetUi32(header + 8)) return SZ_ERROR_CRC; @@ -1356,9 +1356,9 @@ SRes SzArEx_Extract( *blockIndex = folderIndex; IAlloc_Free(allocMain, *outBuffer); *outBuffer = 0; - + RINOK(LookInStream_SeekTo(inStream, startOffset)); - + if (res == SZ_OK) { *outBufferSize = unpackSize; diff --git a/src/lib/lib7z/Aes.c b/src/lib/lib7z/Aes.c index e7221cd2b2e..2bdfc9b9af9 100644 --- a/src/lib/lib7z/Aes.c +++ b/src/lib/lib7z/Aes.c @@ -228,9 +228,9 @@ void MY_FAST_CALL AesCbc_Encode(UInt32 *p, Byte *data, size_t numBlocks) p[1] ^= GetUi32(data + 4); p[2] ^= GetUi32(data + 8); p[3] ^= GetUi32(data + 12); - + Aes_Encode(p + 4, p, p); - + SetUi32(data, p[0]); SetUi32(data + 4, p[1]); SetUi32(data + 8, p[2]); @@ -254,7 +254,7 @@ void MY_FAST_CALL AesCbc_Decode(UInt32 *p, Byte *data, size_t numBlocks) SetUi32(data + 4, p[1] ^ out[1]); SetUi32(data + 8, p[2] ^ out[2]); SetUi32(data + 12, p[3] ^ out[3]); - + p[0] = in[0]; p[1] = in[1]; p[2] = in[2]; diff --git a/src/lib/lib7z/Alloc.c b/src/lib/lib7z/Alloc.c index df7412afe79..651ada46961 100644 --- a/src/lib/lib7z/Alloc.c +++ b/src/lib/lib7z/Alloc.c @@ -99,7 +99,7 @@ void *BigAlloc(size_t size) #ifdef _SZ_ALLOC_DEBUG fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++); #endif - + #ifdef _7ZIP_LARGE_PAGES if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18)) { @@ -118,7 +118,7 @@ void BigFree(void *address) if (address != 0) fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig); #endif - + if (address == 0) return; VirtualFree(address, 0, MEM_RELEASE); diff --git a/src/lib/lib7z/Bra.c b/src/lib/lib7z/Bra.c index 2e47b1413c1..e78e6f97b37 100644 --- a/src/lib/lib7z/Bra.c +++ b/src/lib/lib7z/Bra.c @@ -48,14 +48,14 @@ SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) ((UInt32)data[i + 0] << 11) | (((UInt32)data[i + 3] & 0x7) << 8) | (data[i + 2]); - + src <<= 1; if (encoding) dest = ip + (UInt32)i + src; else dest = src - (ip + (UInt32)i); dest >>= 1; - + data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7)); data[i + 0] = (Byte)(dest >> 11); data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7)); @@ -80,7 +80,7 @@ SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) ((UInt32)data[i + 1] << 16) | ((UInt32)data[i + 2] << 8) | ((UInt32)data[i + 3] & (~3)); - + UInt32 dest; if (encoding) dest = ip + (UInt32)i + src; @@ -113,14 +113,14 @@ SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) ((UInt32)data[i + 2] << 8) | ((UInt32)data[i + 3]); UInt32 dest; - + src <<= 2; if (encoding) dest = ip + i + src; else dest = src - (ip + i); dest >>= 2; - + dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000; data[i + 0] = (Byte)(dest >> 24); diff --git a/src/lib/lib7z/Bra.h b/src/lib/lib7z/Bra.h index 5748c1c051d..aac20a6961d 100644 --- a/src/lib/lib7z/Bra.h +++ b/src/lib/lib7z/Bra.h @@ -13,23 +13,23 @@ extern "C" { /* These functions convert relative addresses to absolute addresses in CALL instructions to increase the compression ratio. - + In: data - data buffer size - size of data ip - current virtual Instruction Pinter (IP) value state - state variable for x86 converter encoding - 0 (for decoding), 1 (for encoding) - + Out: state - state variable for x86 converter Returns: The number of processed bytes. If you call these functions with multiple calls, you must start next call with first byte after block of processed bytes. - + Type Endian Alignment LookAhead - + x86 little 1 4 ARMT little 2 2 ARM little 4 0 diff --git a/src/lib/lib7z/BraIA64.c b/src/lib/lib7z/BraIA64.c index 0b4ee85bc76..07fa7ba40fa 100644 --- a/src/lib/lib7z/BraIA64.c +++ b/src/lib/lib7z/BraIA64.c @@ -42,20 +42,20 @@ SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF); UInt32 dest; src |= ((UInt32)(instNorm >> 36) & 1) << 20; - + src <<= 4; - + if (encoding) dest = ip + (UInt32)i + src; else dest = src - (ip + (UInt32)i); - + dest >>= 4; - + instNorm &= ~((UInt64)(0x8FFFFF) << 13); instNorm |= ((UInt64)(dest & 0xFFFFF) << 13); instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20)); - + instruction &= (1 << bitRes) - 1; instruction |= (instNorm << bitRes); for (j = 0; j < 6; j++) diff --git a/src/lib/lib7z/BwtSort.c b/src/lib/lib7z/BwtSort.c index 207305072d7..482f41285f0 100644 --- a/src/lib/lib7z/BwtSort.c +++ b/src/lib/lib7z/BwtSort.c @@ -96,7 +96,7 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group gPrev = Groups[sp]; temp[0] = (gPrev << NumRefBits); } - + for (j = 1; j < groupSize; j++) { UInt32 sp = ind2[j] + NumSortedBytes; @@ -114,11 +114,11 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group return 1; } } - + HeapSort(temp, groupSize); mask = ((1 << NumRefBits) - 1); thereAreGroups = 0; - + group = groupOffset; cg = (temp[0] >> NumRefBits); temp[0] = ind2[temp[0] & mask]; @@ -129,12 +129,12 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group #else UInt32 prevGroupStart = 0; #endif - + for (j = 1; j < groupSize; j++) { UInt32 val = temp[j]; UInt32 cgCur = (val >> NumRefBits); - + if (cgCur != cg) { cg = cgCur; @@ -398,7 +398,7 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize) for (i = 0; i < blockSize - 1; i++) Indices[counters[((UInt32)data[i] << 8) | data[i + 1]]++] = i; Indices[counters[((UInt32)data[i] << 8) | data[0]]++] = i; - + #ifndef BLOCK_SORT_EXTERNAL_FLAGS { UInt32 prev = 0; @@ -441,7 +441,7 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize) for (groupSize = 1; (Flags[(i + groupSize) >> kNumFlagsBits] & (1 << ((i + groupSize) & kFlagsMask))) != 0; groupSize++); - + groupSize++; #else @@ -473,7 +473,7 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize) } #endif - + if (NumSortedBytes >= blockSize) { UInt32 j; diff --git a/src/lib/lib7z/CpuArch.c b/src/lib/lib7z/CpuArch.c index 787af6e62fc..2896300d235 100644 --- a/src/lib/lib7z/CpuArch.c +++ b/src/lib/lib7z/CpuArch.c @@ -81,7 +81,7 @@ static void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d) : "0" (function)) ; #endif - + #else int CPUInfo[4]; diff --git a/src/lib/lib7z/HuffEnc.c b/src/lib/lib7z/HuffEnc.c index 561c7e5da82..9e6a139506f 100644 --- a/src/lib/lib7z/HuffEnc.c +++ b/src/lib/lib7z/HuffEnc.c @@ -18,9 +18,9 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb /* if (maxLen > 10) maxLen = 10; */ { UInt32 i; - + #ifdef HUFFMAN_SPEED_OPT - + UInt32 counters[NUM_COUNTERS]; for (i = 0; i < NUM_COUNTERS; i++) counters[i] = 0; @@ -29,7 +29,7 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb UInt32 freq = freqs[i]; counters[(freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1]++; } - + for (i = 1; i < NUM_COUNTERS; i++) { UInt32 temp = counters[i]; @@ -47,7 +47,7 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb } counters[0] = 0; HeapSort(p + counters[NUM_COUNTERS - 2], counters[NUM_COUNTERS - 1] - counters[NUM_COUNTERS - 2]); - + #else for (i = 0; i < numSymbols; i++) @@ -78,10 +78,10 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb lens[minCode] = lens[maxCode] = 1; return; } - + { UInt32 b, e, i; - + i = b = e = 0; do { @@ -96,12 +96,12 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb e++; } while (num - e > 1); - + { UInt32 lenCounters[kMaxLen + 1]; for (i = 0; i <= kMaxLen; i++) lenCounters[i] = 0; - + p[--e] &= MASK; lenCounters[1] = 2; while (e > 0) @@ -113,7 +113,7 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb lenCounters[len]--; lenCounters[len + 1] += 2; } - + { UInt32 len; i = 0; @@ -124,7 +124,7 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb lens[p[i++] & MASK] = (Byte)len; } } - + { UInt32 nextCodes[kMaxLen + 1]; { diff --git a/src/lib/lib7z/HuffEnc.h b/src/lib/lib7z/HuffEnc.h index 9cf4bfde817..d0aa13cdc8d 100644 --- a/src/lib/lib7z/HuffEnc.h +++ b/src/lib/lib7z/HuffEnc.h @@ -17,7 +17,7 @@ Conditions: maxLen <= 16 = kMaxLen Num_Items(p) >= HUFFMAN_TEMP_SIZE(num) */ - + void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 num, UInt32 maxLen); #ifdef __cplusplus diff --git a/src/lib/lib7z/LzFind.c b/src/lib/lib7z/LzFind.c index e3ecb05420e..e753d04c692 100644 --- a/src/lib/lib7z/LzFind.c +++ b/src/lib/lib7z/LzFind.c @@ -512,7 +512,7 @@ static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) delta2 = p->pos - p->hash[hash2Value]; curMatch = p->hash[kFix3HashSize + hashValue]; - + p->hash[hash2Value] = p->hash[kFix3HashSize + hashValue] = p->pos; @@ -546,7 +546,7 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) delta2 = p->pos - p->hash[ hash2Value]; delta3 = p->pos - p->hash[kFix3HashSize + hash3Value]; curMatch = p->hash[kFix4HashSize + hashValue]; - + p->hash[ hash2Value] = p->hash[kFix3HashSize + hash3Value] = p->hash[kFix4HashSize + hashValue] = p->pos; diff --git a/src/lib/lib7z/LzFindMt.c b/src/lib/lib7z/LzFindMt.c index aa41ed98a57..0f7b314f4c5 100644 --- a/src/lib/lib7z/LzFindMt.c +++ b/src/lib/lib7z/LzFindMt.c @@ -58,7 +58,7 @@ void MtSync_StopWriting(CMtSync *p) p->csWasEntered = False; } Semaphore_Release1(&p->freeSemaphore); - + Event_Wait(&p->wasStopped); while (myNumBlocks++ != p->numProcessedBlocks) @@ -108,12 +108,12 @@ static SRes MtSync_Create2(CMtSync *p, unsigned (MY_STD_CALL *startAddress)(void RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart)); RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted)); RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped)); - + RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks)); RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks)); p->needStart = True; - + RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj)); p->wasCreated = True; return SZ_OK; @@ -385,7 +385,7 @@ void BtFillBlock(CMatchFinderMt *p, UInt32 globalBlockIndex) CriticalSection_Enter(&sync->cs); sync->csWasEntered = True; } - + BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize); if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize) @@ -561,7 +561,7 @@ UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances) const Byte *cur = p->pointerToCurPos; UInt32 lzPos = p->lzPos; MT_HASH2_CALC - + curMatch2 = hash[hash2Value]; hash[hash2Value] = lzPos; @@ -584,7 +584,7 @@ UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances) curMatch2 = hash[ hash2Value]; curMatch3 = hash[kFix3HashSize + hash3Value]; - + hash[ hash2Value] = hash[kFix3HashSize + hash3Value] = lzPos; @@ -616,11 +616,11 @@ UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances) const Byte *cur = p->pointerToCurPos; UInt32 lzPos = p->lzPos; MT_HASH4_CALC - + curMatch2 = hash[ hash2Value]; curMatch3 = hash[kFix3HashSize + hash3Value]; curMatch4 = hash[kFix4HashSize + hash4Value]; - + hash[ hash2Value] = hash[kFix3HashSize + hash3Value] = hash[kFix4HashSize + hash4Value] = diff --git a/src/lib/lib7z/LzFindMt.h b/src/lib/lib7z/LzFindMt.h index b985af5fee2..63133b1b909 100644 --- a/src/lib/lib7z/LzFindMt.h +++ b/src/lib/lib7z/LzFindMt.h @@ -62,7 +62,7 @@ typedef struct _CMatchFinderMt const UInt32 *crc; Mf_Mix_Matches MixMatchesFunc; - + /* LZ + BT */ CMtSync btSync; Byte btDummy[kMtCacheLineDummy]; @@ -85,7 +85,7 @@ typedef struct _CMatchFinderMt /* BT + Hash */ CMtSync hashSync; /* Byte hashDummy[kMtCacheLineDummy]; */ - + /* Hash */ Mf_GetHeads GetHeadsFunc; CMatchFinder *MatchFinder; diff --git a/src/lib/lib7z/Lzma2Dec.c b/src/lib/lib7z/Lzma2Dec.c index f3a6b821daf..d2f8c8884c9 100644 --- a/src/lib/lib7z/Lzma2Dec.c +++ b/src/lib/lib7z/Lzma2Dec.c @@ -114,17 +114,17 @@ static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec *p, Byte b) else p->unpackSize = (UInt32)(p->control & 0x1F) << 16; return LZMA2_STATE_UNPACK0; - + case LZMA2_STATE_UNPACK0: p->unpackSize |= (UInt32)b << 8; return LZMA2_STATE_UNPACK1; - + case LZMA2_STATE_UNPACK1: p->unpackSize |= (UInt32)b; p->unpackSize++; PRF(printf(" %8d", p->unpackSize)); return (LZMA2_IS_UNCOMPRESSED_STATE(p)) ? LZMA2_STATE_DATA : LZMA2_STATE_PACK0; - + case LZMA2_STATE_PACK0: p->packSize = (UInt32)b << 8; return LZMA2_STATE_PACK1; @@ -199,7 +199,7 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit, SizeT destSizeCur = dicLimit - dicPos; SizeT srcSizeCur = inSize - *srcLen; ELzmaFinishMode curFinishMode = LZMA_FINISH_ANY; - + if (p->unpackSize <= destSizeCur) { destSizeCur = (SizeT)p->unpackSize; @@ -250,7 +250,7 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit, Bool initState = (mode > 0); if ((!initDic && p->needInitDic) || (!initState && p->needInitState)) return SZ_ERROR_DATA; - + LzmaDec_InitDicAndState(&p->decoder, initDic, initState); p->needInitDic = False; p->needInitState = False; @@ -258,9 +258,9 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit, } if (srcSizeCur > p->packSize) srcSizeCur = (SizeT)p->packSize; - + res = LzmaDec_DecodeToDic(&p->decoder, dicPos + destSizeCur, src, &srcSizeCur, curFinishMode, status); - + src += srcSizeCur; *srcLen += srcSizeCur; p->packSize -= (UInt32)srcSizeCur; diff --git a/src/lib/lib7z/Lzma2Enc.c b/src/lib/lib7z/Lzma2Enc.c index e97597f63d5..86869551668 100644 --- a/src/lib/lib7z/Lzma2Enc.c +++ b/src/lib/lib7z/Lzma2Enc.c @@ -83,11 +83,11 @@ static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf, if (packSize < lzHeaderSize) return SZ_ERROR_OUTPUT_EOF; packSize -= lzHeaderSize; - + LzmaEnc_SaveState(p->enc); res = LzmaEnc_CodeOneMemBlock(p->enc, p->needInitState, outBuf + lzHeaderSize, &packSize, LZMA2_PACK_SIZE_MAX, &unpackSize); - + PRF(printf("\npackSize = %7d unpackSize = %7d ", packSize, unpackSize)); if (unpackSize == 0) @@ -146,10 +146,10 @@ static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf, outBuf[destPos++] = (Byte)u; outBuf[destPos++] = (Byte)(pm >> 8); outBuf[destPos++] = (Byte)pm; - + if (p->needInitProp) outBuf[destPos++] = p->props; - + p->needInitProp = False; p->needInitState = False; destPos += packSize; @@ -244,7 +244,7 @@ typedef struct { Byte propEncoded; CLzma2EncProps props; - + Byte *outBuf; ISzAlloc *alloc; @@ -322,10 +322,10 @@ static SRes MtCallbackImp_Code(void *pp, unsigned index, Byte *dest, size_t *des if (srcSize != 0) { RINOK(Lzma2EncInt_Init(p, &mainEncoder->props)); - + RINOK(LzmaEnc_MemPrepare(p->enc, src, srcSize, LZMA2_KEEP_WINDOW_SIZE, mainEncoder->alloc, mainEncoder->allocBig)); - + while (p->srcPos < srcSize) { size_t packSize = destLim - *destSize; @@ -460,7 +460,7 @@ SRes Lzma2Enc_Encode(CLzma2EncHandle pp, mtCallback.funcTable.Code = MtCallbackImp_Code; mtCallback.lzma2Enc = p; - + p->mtCoder.progress = progress; p->mtCoder.inStream = inStream; p->mtCoder.outStream = outStream; @@ -470,7 +470,7 @@ SRes Lzma2Enc_Encode(CLzma2EncHandle pp, p->mtCoder.blockSize = p->props.blockSize; p->mtCoder.destBlockSize = p->props.blockSize + (p->props.blockSize >> 10) + 16; p->mtCoder.numThreads = p->props.numBlockThreads; - + return MtCoder_Code(&p->mtCoder); } #endif diff --git a/src/lib/lib7z/Lzma86Enc.c b/src/lib/lib7z/Lzma86Enc.c index 2ea4ac2da45..45b96b68e43 100644 --- a/src/lib/lib7z/Lzma86Enc.c +++ b/src/lib/lib7z/Lzma86Enc.c @@ -26,7 +26,7 @@ int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen, LzmaEncProps_Init(&props); props.level = level; props.dictSize = dictSize; - + *destLen = 0; if (outSize2 < LZMA86_HEADER_SIZE) return SZ_ERROR_OUTPUT_EOF; @@ -78,12 +78,12 @@ int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen, break; if (useFilter && i == 0) curModeIsFiltered = True; - + curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed, curModeIsFiltered ? filteredStream : src, srcLen, &props, dest + 1, &outPropsSize, 0, NULL, &g_Alloc, &g_Alloc); - + if (curRes != SZ_ERROR_OUTPUT_EOF) { if (curRes != SZ_OK) diff --git a/src/lib/lib7z/LzmaDec.c b/src/lib/lib7z/LzmaDec.c index a85edb7dfd0..14d0f2d3250 100644 --- a/src/lib/lib7z/LzmaDec.c +++ b/src/lib/lib7z/LzmaDec.c @@ -141,7 +141,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte Byte *dic = p->dic; SizeT dicBufSize = p->dicBufSize; SizeT dicPos = p->dicPos; - + UInt32 processedPos = p->processedPos; UInt32 checkDicSize = p->checkDicSize; unsigned len = 0; @@ -324,7 +324,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte { NORMALIZE range >>= 1; - + { UInt32 t; code -= range; @@ -723,7 +723,7 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr SizeT inSize = *srcLen; (*srcLen) = 0; LzmaDec_WriteRem(p, dicLimit); - + *status = LZMA_STATUS_NOT_SPECIFIED; while (p->remainLen != kMatchSpecLenStart) @@ -769,7 +769,7 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr if (p->needInitState) LzmaDec_InitStateReal(p); - + if (p->tempBufSize == 0) { SizeT processed; @@ -900,12 +900,12 @@ SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size) { UInt32 dicSize; Byte d; - + if (size < LZMA_PROPS_SIZE) return SZ_ERROR_UNSUPPORTED; else dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24); - + if (dicSize < LZMA_DIC_MIN) dicSize = LZMA_DIC_MIN; p->dicSize = dicSize; diff --git a/src/lib/lib7z/LzmaDec.h b/src/lib/lib7z/LzmaDec.h index bf7f084ba3d..7927acd0d4e 100644 --- a/src/lib/lib7z/LzmaDec.h +++ b/src/lib/lib7z/LzmaDec.h @@ -130,7 +130,7 @@ LzmaDec_Allocate* can return: SZ_ERROR_MEM - Memory allocation error SZ_ERROR_UNSUPPORTED - Unsupported properties */ - + SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc); void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc); @@ -159,7 +159,7 @@ void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc); */ /* LzmaDec_DecodeToDic - + The decoding to internal dictionary buffer (CLzmaDec::dic). You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!! diff --git a/src/lib/lib7z/LzmaEnc.c b/src/lib/lib7z/LzmaEnc.c index ef26e0cfdbd..17d63f38cd2 100644 --- a/src/lib/lib7z/LzmaEnc.c +++ b/src/lib/lib7z/LzmaEnc.c @@ -119,7 +119,7 @@ void LzmaEnc_FastPosInit(Byte *g_FastPos) int c = 2, slotFast; g_FastPos[0] = 0; g_FastPos[1] = 1; - + for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++) { UInt32 k = (1 << ((slotFast >> 1) - 1)); @@ -256,7 +256,7 @@ typedef struct CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits]; CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex]; CLzmaProb posAlignEncoder[1 << kNumAlignBits]; - + CLenPriceEnc lenEnc; CLenPriceEnc repLenEnc; @@ -279,7 +279,7 @@ typedef struct #ifndef _7ZIP_ST Byte pad[128]; #endif - + UInt32 optimumEndIndex; UInt32 optimumCurrentIndex; @@ -287,7 +287,7 @@ typedef struct UInt32 numPairs; UInt32 numAvail; COptimal opt[kNumOpts]; - + #ifndef LZMA_LOG_BSR Byte g_FastPos[1 << kNumLogBits]; #endif @@ -321,14 +321,14 @@ typedef struct CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits]; CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex]; CLzmaProb posAlignEncoder[1 << kNumAlignBits]; - + CLenPriceEnc lenEnc; CLenPriceEnc repLenEnc; unsigned lclp; Bool fastMode; - + CRangeEnc rc; Bool writeEndMark; @@ -917,10 +917,10 @@ static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur) { UInt32 posPrev = posMem; UInt32 backCur = backMem; - + backMem = p->opt[posPrev].backPrev; posMem = p->opt[posPrev].posPrev; - + p->opt[posPrev].backPrev = backCur; p->opt[posPrev].posPrev = cur; cur = posPrev; @@ -951,7 +951,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) return lenRes; } p->optimumCurrentIndex = p->optimumEndIndex = 0; - + if (p->additionalOffset == 0) mainLen = ReadMatchDistances(p, &numPairs); else @@ -1249,7 +1249,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]); repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]); - + if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0)) { UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState); @@ -1311,7 +1311,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) } } } - + startLen = 2; /* speed optimization */ { UInt32 repIndex; @@ -1342,10 +1342,10 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) } while (--lenTest >= 2); lenTest = lenTestTemp; - + if (repIndex == 0) startLen = lenTest + 1; - + /* if (_maxMode) */ { UInt32 lenTest2 = lenTest + 1; @@ -1369,7 +1369,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) nextRepMatchPrice = curAndLenCharPrice + GET_PRICE_1(p->isMatch[state2][posStateNext]) + GET_PRICE_1(p->isRep[state2]); - + /* for (; lenTest2 >= 2; lenTest2--) */ { UInt32 curAndLenPrice; @@ -1424,7 +1424,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) curAndLenPrice += p->distancesPrices[lenToPosState][curBack]; else curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask]; - + opt = &p->opt[cur + lenTest]; if (curAndLenPrice < opt->price) { @@ -1458,7 +1458,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) nextRepMatchPrice = curAndLenCharPrice + GET_PRICE_1(p->isMatch[state2][posStateNext]) + GET_PRICE_1(p->isRep[state2]); - + /* for (; lenTest2 >= 2; lenTest2--) */ { UInt32 offset = cur + lenTest + 1 + lenTest2; @@ -1570,7 +1570,7 @@ static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes) MovePos(p, repLen - 1); return repLen; } - + if (mainLen < 2 || numAvail <= 2) return 1; @@ -1584,7 +1584,7 @@ static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes) (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist))) return 1; } - + data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; for (i = 0; i < LZMA_NUM_REPS; i++) { @@ -1845,7 +1845,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize pos -= LZMA_NUM_REPS; GetPosSlot(pos, posSlot); RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot); - + if (posSlot >= kStartPosModelIndex) { UInt32 footerBits = ((posSlot >> 1) - 1); @@ -2150,7 +2150,7 @@ SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit, p->rc.outStream = &outStream.funcTable; res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize); - + *unpackSize = (UInt32)(p->nowPos64 - nowPos64); *destLen -= outStream.rem; if (outStream.overflow) diff --git a/src/lib/lib7z/LzmaLib.h b/src/lib/lib7z/LzmaLib.h index 76c99ce758d..2a3efe161c1 100644 --- a/src/lib/lib7z/LzmaLib.h +++ b/src/lib/lib7z/LzmaLib.h @@ -38,7 +38,7 @@ outPropsSize - LZMA Encoder will use defult values for any parameter, if it is -1 for any from: level, loc, lp, pb, fb, numThreads 0 for dictSize - + level - compression level: 0 <= level <= 9; level dictSize algo fb @@ -50,7 +50,7 @@ level - compression level: 0 <= level <= 9; 5: 16 MB 1 32 6: 32 MB 1 32 7+: 64 MB 1 64 - + The default value for "level" is 5. algo = 0 means fast method diff --git a/src/lib/lib7z/MtCoder.c b/src/lib/lib7z/MtCoder.c index 946fbbc7076..c6a992a64ba 100644 --- a/src/lib/lib7z/MtCoder.c +++ b/src/lib/lib7z/MtCoder.c @@ -190,9 +190,9 @@ static SRes MtThread_Process(CMtThread *p, Bool *stop) *stop = True; if (Event_Wait(&p->canRead) != 0) return SZ_ERROR_THREAD; - + next = GET_NEXT_THREAD(p); - + if (p->stopReading) { next->stopReading = True; diff --git a/src/lib/lib7z/MtCoder.h b/src/lib/lib7z/MtCoder.h index f0f06da281f..e2cbdc3ab2e 100644 --- a/src/lib/lib7z/MtCoder.h +++ b/src/lib/lib7z/MtCoder.h @@ -14,7 +14,7 @@ typedef struct CAutoResetEvent startEvent; CAutoResetEvent finishedEvent; int stop; - + THREAD_FUNC_TYPE func; LPVOID param; THREAD_FUNC_RET_TYPE res; @@ -75,7 +75,7 @@ typedef struct _CMtCoder size_t blockSize; size_t destBlockSize; unsigned numThreads; - + ISeqInStream *inStream; ISeqOutStream *outStream; ICompressProgress *progress; diff --git a/src/lib/lib7z/Ppmd.h b/src/lib/lib7z/Ppmd.h index 9cbc46647b8..db8a16d6371 100644 --- a/src/lib/lib7z/Ppmd.h +++ b/src/lib/lib7z/Ppmd.h @@ -82,5 +82,5 @@ typedef p[i+7] = p[i+6] = p[i+5] = p[i+4] = p[i+3] = p[i+2] = p[i+1] = p[i+0] = ~(size_t)0; }} EXTERN_C_END - + #endif diff --git a/src/lib/lib7z/Ppmd7.c b/src/lib/lib7z/Ppmd7.c index bba4d06f0ab..58244e13610 100644 --- a/src/lib/lib7z/Ppmd7.c +++ b/src/lib/lib7z/Ppmd7.c @@ -148,7 +148,7 @@ static void GlueFreeBlocks(CPpmd7 *p) #else CPpmd7_Node_Ref head = p->AlignOffset + p->Size; #endif - + CPpmd7_Node_Ref n = head; unsigned i; @@ -175,7 +175,7 @@ static void GlueFreeBlocks(CPpmd7 *p) NODE(n)->Prev = head; if (p->LoUnit != p->HiUnit) ((CPpmd7_Node *)p->LoUnit)->Stamp = 1; - + /* Glue free blocks */ while (n != head) { @@ -193,7 +193,7 @@ static void GlueFreeBlocks(CPpmd7 *p) } n = node->Next; } - + /* Fill lists of free blocks */ for (n = NODE(head)->Next; n != head;) { @@ -319,7 +319,7 @@ static void RestartModel(CPpmd7 *p) for (m = 0; m < 64; m += 8) dest[m] = val; } - + for (i = 0; i < 25; i++) for (k = 0; k < 16; k++) { @@ -345,10 +345,10 @@ static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip) CPpmd_Byte_Ref upBranch = (CPpmd_Byte_Ref)SUCCESSOR(p->FoundState); CPpmd_State *ps[PPMD7_MAX_ORDER]; unsigned numPs = 0; - + if (!skip) ps[numPs++] = p->FoundState; - + while (c->Suffix) { CPpmd_Void_Ref successor; @@ -370,10 +370,10 @@ static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip) } ps[numPs++] = s; } - + upState.Symbol = *(const Byte *)Ppmd7_GetPtr(p, upBranch); SetSuccessor(&upState, upBranch + 1); - + if (c->NumStats == 1) upState.Freq = ONE_STATE(c)->Freq; else @@ -407,7 +407,7 @@ static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip) c = c1; } while (numPs != 0); - + return c; } @@ -423,11 +423,11 @@ static void UpdateModel(CPpmd7 *p) CPpmd_Void_Ref successor, fSuccessor = SUCCESSOR(p->FoundState); CTX_PTR c; unsigned s0, ns; - + if (p->FoundState->Freq < MAX_FREQ / 4 && p->MinContext->Suffix != 0) { c = SUFFIX(p->MinContext); - + if (c->NumStats == 1) { CPpmd_State *s = ONE_STATE(c); @@ -465,7 +465,7 @@ static void UpdateModel(CPpmd7 *p) SetSuccessor(p->FoundState, REF(p->MinContext)); return; } - + *p->Text++ = p->FoundState->Symbol; successor = REF(p->Text); if (p->Text >= p->UnitsStart) @@ -473,7 +473,7 @@ static void UpdateModel(CPpmd7 *p) RestartModel(p); return; } - + if (fSuccessor) { if (fSuccessor <= successor) @@ -497,9 +497,9 @@ static void UpdateModel(CPpmd7 *p) SetSuccessor(p->FoundState, successor); fSuccessor = REF(p->MinContext); } - + s0 = p->MinContext->SummFreq - (ns = p->MinContext->NumStats) - (p->FoundState->Freq - 1); - + for (c = p->MaxContext; c != p->MinContext; c = SUFFIX(c)) { unsigned ns1; @@ -566,7 +566,7 @@ static void UpdateModel(CPpmd7 *p) } p->MaxContext = p->MinContext = CTX(fSuccessor); } - + static void Rescale(CPpmd7 *p) { unsigned i, adder, sumFreq, escFreq; @@ -583,7 +583,7 @@ static void Rescale(CPpmd7 *p) adder = (p->OrderFall != 0); s->Freq = (Byte)((s->Freq + adder) >> 1); sumFreq = s->Freq; - + i = p->MinContext->NumStats - 1; do { @@ -601,7 +601,7 @@ static void Rescale(CPpmd7 *p) } } while (--i); - + if (s->Freq == 0) { unsigned numStats = p->MinContext->NumStats; diff --git a/src/lib/lib7z/Ppmd7.h b/src/lib/lib7z/Ppmd7.h index 96521c31f11..fa4225e2d35 100644 --- a/src/lib/lib7z/Ppmd7.h +++ b/src/lib/lib7z/Ppmd7.h @@ -136,5 +136,5 @@ void Ppmd7z_RangeEnc_FlushData(CPpmd7z_RangeEnc *p); void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol); EXTERN_C_END - + #endif diff --git a/src/lib/lib7z/Ppmd7Dec.c b/src/lib/lib7z/Ppmd7Dec.c index 68438d5ce4e..dc31b4f3a82 100644 --- a/src/lib/lib7z/Ppmd7Dec.c +++ b/src/lib/lib7z/Ppmd7Dec.c @@ -160,11 +160,11 @@ int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc) i -= k; } while (i != num); - + see = Ppmd7_MakeEscFreq(p, numMasked, &freqSum); freqSum += hiCnt; count = rc->GetThreshold(rc, freqSum); - + if (count < hiCnt) { Byte symbol; diff --git a/src/lib/lib7z/Ppmd7Enc.c b/src/lib/lib7z/Ppmd7Enc.c index 8247757d09d..51a36b0178d 100644 --- a/src/lib/lib7z/Ppmd7Enc.c +++ b/src/lib/lib7z/Ppmd7Enc.c @@ -104,7 +104,7 @@ void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol) sum += s->Freq; } while (--i); - + p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]; PPMD_SetAllBitsIn256Bytes(charMask); MASK(s->Symbol) = 0; @@ -149,7 +149,7 @@ void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol) p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix); } while (p->MinContext->NumStats == numMasked); - + see = Ppmd7_MakeEscFreq(p, numMasked, &escFreq); s = Ppmd7_GetStats(p, p->MinContext); sum = 0; @@ -178,7 +178,7 @@ void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol) s++; } while (--i); - + RangeEnc_Encode(rc, sum, escFreq, sum + escFreq); see->Summ = (UInt16)(see->Summ + sum + escFreq); } diff --git a/src/lib/lib7z/Ppmd8.c b/src/lib/lib7z/Ppmd8.c index 9187a88ef1e..8bec6f560f1 100644 --- a/src/lib/lib7z/Ppmd8.c +++ b/src/lib/lib7z/Ppmd8.c @@ -146,7 +146,7 @@ static void GlueFreeBlocks(CPpmd8 *p) p->GlueCount = 1 << 13; memset(p->Stamps, 0, sizeof(p->Stamps)); - + /* Order-0 context is always at top UNIT, so we don't need guard NODE at the end. All blocks up to p->LoUnit can be free, so we need guard NODE at LoUnit. */ if (p->LoUnit != p->HiUnit) @@ -175,7 +175,7 @@ static void GlueFreeBlocks(CPpmd8 *p) } } *prev = 0; - + /* Fill lists of free blocks */ while (head != 0) { @@ -298,7 +298,7 @@ static void ExpandTextArea(CPpmd8 *p) memset(count, 0, sizeof(count)); if (p->LoUnit != p->HiUnit) ((CPpmd8_Node *)p->LoUnit)->Stamp = 0; - + { CPpmd8_Node *node = (CPpmd8_Node *)p->UnitsStart; for (; node->Stamp == EMPTY_NODE; node += node->NU) @@ -308,7 +308,7 @@ static void ExpandTextArea(CPpmd8 *p) } p->UnitsStart = (Byte *)node; } - + for (i = 0; i < PPMD_NUM_INDEXES; i++) { CPpmd8_Node_Ref *next = (CPpmd8_Node_Ref *)&p->FreeList[i]; @@ -440,7 +440,7 @@ static CPpmd_Void_Ref CutOff(CPpmd8 *p, CTX_PTR ctx, unsigned order) int i; unsigned tmp; CPpmd_State *s; - + if (!ctx->NumStats) { s = ONE_STATE(ctx); @@ -470,7 +470,7 @@ static CPpmd_Void_Ref CutOff(CPpmd8 *p, CTX_PTR ctx, unsigned order) SetSuccessor(s, CutOff(p, CTX(SUCCESSOR(s)), order + 1)); else SetSuccessor(s, 0); - + if (i != ctx->NumStats && order) { ctx->NumStats = (Byte)i; @@ -521,7 +521,7 @@ static CPpmd_Void_Ref RemoveBinContexts(CPpmd8 *p, CTX_PTR ctx, unsigned order) SetSuccessor(s, RemoveBinContexts(p, CTX(SUCCESSOR(s)), order + 1)); else SetSuccessor(s, 0); - + return REF(ctx); } #endif @@ -561,7 +561,7 @@ static void RestoreModel(CPpmd8 *p, CTX_PTR c1 } else Refresh(p, c, (c->NumStats+3) >> 1, 0); - + for (; c != p->MinContext; c = SUFFIX(c)) if (!c->NumStats) ONE_STATE(c)->Freq -= ONE_STATE(c)->Freq >> 1; @@ -610,10 +610,10 @@ static CTX_PTR CreateSuccessors(CPpmd8 *p, Bool skip, CPpmd_State *s1, CTX_PTR c /* fixed over Shkarin's code. Maybe it could work without + 1 too. */ CPpmd_State *ps[PPMD8_MAX_ORDER + 1]; unsigned numPs = 0; - + if (!skip) ps[numPs++] = p->FoundState; - + while (c->Suffix) { CPpmd_Void_Ref successor; @@ -648,7 +648,7 @@ static CTX_PTR CreateSuccessors(CPpmd8 *p, Bool skip, CPpmd_State *s1, CTX_PTR c } ps[numPs++] = s; } - + upState.Symbol = *(const Byte *)Ppmd8_GetPtr(p, upBranch); SetSuccessor(&upState, upBranch + 1); flags = 0x10 * (p->FoundState->Symbol >= 0x40) + 0x08 * (upState.Symbol >= 0x40); @@ -687,7 +687,7 @@ static CTX_PTR CreateSuccessors(CPpmd8 *p, Bool skip, CPpmd_State *s1, CTX_PTR c c = c1; } while (numPs != 0); - + return c; } @@ -696,7 +696,7 @@ static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c) CPpmd_State *s = NULL; CTX_PTR c1 = c; CPpmd_Void_Ref upBranch = REF(p->Text); - + #ifdef PPMD8_FREEZE_SUPPORT /* The BUG in Shkarin's code was fixed: ps could overflow in CUT_OFF mode. */ CPpmd_State *ps[PPMD8_MAX_ORDER + 1]; @@ -754,7 +754,7 @@ static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c) SetSuccessor(s, upBranch); p->OrderFall++; } - + #ifdef PPMD8_FREEZE_SUPPORT if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE) { @@ -779,7 +779,7 @@ static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c) SetSuccessor(s, REF(successor)); p->FoundState = s1; } - + if (p->OrderFall == 1 && c1 == p->MaxContext) { SetSuccessor(p->FoundState, SUCCESSOR(s)); @@ -797,11 +797,11 @@ static void UpdateModel(CPpmd8 *p) unsigned s0, ns, fFreq = p->FoundState->Freq; Byte flag, fSymbol = p->FoundState->Symbol; CPpmd_State *s = NULL; - + if (p->FoundState->Freq < MAX_FREQ / 4 && p->MinContext->Suffix != 0) { c = SUFFIX(p->MinContext); - + if (c->NumStats == 0) { s = ONE_STATE(c); @@ -827,7 +827,7 @@ static void UpdateModel(CPpmd8 *p) } } } - + c = p->MaxContext; if (p->OrderFall == 0 && fSuccessor) { @@ -844,7 +844,7 @@ static void UpdateModel(CPpmd8 *p) } return; } - + *p->Text++ = p->FoundState->Symbol; successor = REF(p->Text); if (p->Text >= p->UnitsStart) @@ -852,7 +852,7 @@ static void UpdateModel(CPpmd8 *p) RESTORE_MODEL(c, CTX(fSuccessor)); /* check it */ return; } - + if (!fSuccessor) { CTX_PTR cs = ReduceOrder(p, s, p->MinContext); @@ -873,7 +873,7 @@ static void UpdateModel(CPpmd8 *p) } fSuccessor = REF(cs); } - + if (--p->OrderFall == 0) { successor = fSuccessor; @@ -887,10 +887,10 @@ static void UpdateModel(CPpmd8 *p) p->OrderFall = 0; } #endif - + s0 = p->MinContext->SummFreq - (ns = p->MinContext->NumStats) - fFreq; flag = 0x08 * (fSymbol >= 0x40); - + for (; c != p->MinContext; c = SUFFIX(c)) { unsigned ns1; @@ -958,7 +958,7 @@ static void UpdateModel(CPpmd8 *p) } p->MaxContext = p->MinContext = CTX(fSuccessor); } - + static void Rescale(CPpmd8 *p) { unsigned i, adder, sumFreq, escFreq; @@ -979,7 +979,7 @@ static void Rescale(CPpmd8 *p) ); s->Freq = (Byte)((s->Freq + adder) >> 1); sumFreq = s->Freq; - + i = p->MinContext->NumStats; do { @@ -997,7 +997,7 @@ static void Rescale(CPpmd8 *p) } } while (--i); - + if (s->Freq == 0) { unsigned numStats = p->MinContext->NumStats; diff --git a/src/lib/lib7z/Ppmd8.h b/src/lib/lib7z/Ppmd8.h index 7dcfc91613b..813254cd462 100644 --- a/src/lib/lib7z/Ppmd8.h +++ b/src/lib/lib7z/Ppmd8.h @@ -133,5 +133,5 @@ void Ppmd8_RangeEnc_FlushData(CPpmd8 *p); void Ppmd8_EncodeSymbol(CPpmd8 *p, int symbol); /* symbol = -1 means EndMarker */ EXTERN_C_END - + #endif diff --git a/src/lib/lib7z/Ppmd8Dec.c b/src/lib/lib7z/Ppmd8Dec.c index c54e02ab205..12fd7ec0d79 100644 --- a/src/lib/lib7z/Ppmd8Dec.c +++ b/src/lib/lib7z/Ppmd8Dec.c @@ -128,11 +128,11 @@ int Ppmd8_DecodeSymbol(CPpmd8 *p) i -= k; } while (i != num); - + see = Ppmd8_MakeEscFreq(p, numMasked, &freqSum); freqSum += hiCnt; count = RangeDec_GetThreshold(p, freqSum); - + if (count < hiCnt) { Byte symbol; diff --git a/src/lib/lib7z/Ppmd8Enc.c b/src/lib/lib7z/Ppmd8Enc.c index 8da727eb25a..f433fe9ee0a 100644 --- a/src/lib/lib7z/Ppmd8Enc.c +++ b/src/lib/lib7z/Ppmd8Enc.c @@ -81,7 +81,7 @@ void Ppmd8_EncodeSymbol(CPpmd8 *p, int symbol) sum += s->Freq; } while (--i); - + PPMD_SetAllBitsIn256Bytes(charMask); MASK(s->Symbol) = 0; i = p->MinContext->NumStats; @@ -125,7 +125,7 @@ void Ppmd8_EncodeSymbol(CPpmd8 *p, int symbol) p->MinContext = Ppmd8_GetContext(p, p->MinContext->Suffix); } while (p->MinContext->NumStats == numMasked); - + see = Ppmd8_MakeEscFreq(p, numMasked, &escFreq); s = Ppmd8_GetStats(p, p->MinContext); sum = 0; @@ -154,7 +154,7 @@ void Ppmd8_EncodeSymbol(CPpmd8 *p, int symbol) s++; } while (--i); - + RangeEnc_Encode(p, sum, escFreq, sum + escFreq); see->Summ = (UInt16)(see->Summ + sum + escFreq); } diff --git a/src/lib/lib7z/Sha256.c b/src/lib/lib7z/Sha256.c index eb4fc61fc9d..8b824744ced 100644 --- a/src/lib/lib7z/Sha256.c +++ b/src/lib/lib7z/Sha256.c @@ -133,7 +133,7 @@ static void Sha256_Transform(UInt32 *state, const UInt32 *data) for (j = 0; j < 8; j++) state[j] += T[j]; #endif - + /* Wipe variables */ /* memset(W, 0, sizeof(W)); */ /* memset(T, 0, sizeof(T)); */ diff --git a/src/lib/lib7z/Xz.h b/src/lib/lib7z/Xz.h index 0f7a822c37e..45481cfdf6d 100644 --- a/src/lib/lib7z/Xz.h +++ b/src/lib/lib7z/Xz.h @@ -199,7 +199,7 @@ typedef struct unsigned indexPreSize; CXzStreamFlags streamFlags; - + UInt32 blockHeaderSize; UInt64 packSize; UInt64 unpackSize; diff --git a/src/lib/lib7z/XzDec.c b/src/lib/lib7z/XzDec.c index 113e2cdf0f0..5a4a9a1ca0e 100644 --- a/src/lib/lib7z/XzDec.c +++ b/src/lib/lib7z/XzDec.c @@ -421,7 +421,7 @@ SRes MixCoder_Code(CMixCoder *p, Byte *dest, SizeT *destLen, const Byte *srcCur; int srcFinishedCur; int encodingWasFinished; - + if (i == 0) { srcCur = src; @@ -434,7 +434,7 @@ SRes MixCoder_Code(CMixCoder *p, Byte *dest, SizeT *destLen, srcLenCur = p->size[i - 1] - p->pos[i - 1]; srcFinishedCur = p->finished[i - 1]; } - + if (i == p->numCoders - 1) { destCur = dest; @@ -447,7 +447,7 @@ SRes MixCoder_Code(CMixCoder *p, Byte *dest, SizeT *destLen, destCur = p->buf + (CODER_BUF_SIZE * i); destLenCur = CODER_BUF_SIZE; } - + res = coder->Code(coder->p, destCur, &destLenCur, srcCur, &srcLenCur, srcFinishedCur, finishMode, &encodingWasFinished); if (!encodingWasFinished) @@ -474,7 +474,7 @@ SRes MixCoder_Code(CMixCoder *p, Byte *dest, SizeT *destLen, p->pos[i] = 0; p->finished[i] = encodingWasFinished; } - + if (res != SZ_OK) return res; @@ -637,20 +637,20 @@ SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen, *status = CODER_STATUS_NOT_FINISHED; return SZ_OK; } - + res = MixCoder_Code(&p->decoder, dest, &destLen2, src, &srcLen2, False, finishMode, status); XzCheck_Update(&p->check, dest, destLen2); - + (*srcLen) += srcLen2; src += srcLen2; p->packSize += srcLen2; - + (*destLen) += destLen2; dest += destLen2; p->unpackSize += destLen2; - + RINOK(res); - + if (*status == CODER_STATUS_FINISHED_WITH_MARK) { Byte temp[32]; @@ -659,14 +659,14 @@ SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen, Sha256_Update(&p->sha, temp, num); p->indexSize += num; p->numBlocks++; - + p->state = XZ_STATE_BLOCK_FOOTER; p->pos = 0; p->alignPos = 0; } else if (srcLen2 == 0 && destLen2 == 0) return SZ_OK; - + continue; } @@ -872,7 +872,7 @@ SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen, } break; } - + case XZ_STATE_BLOCK: break; /* to disable GCC warning */ } } diff --git a/src/lib/lib7z/XzEnc.c b/src/lib/lib7z/XzEnc.c index 56cfd579c69..8a206f4b9af 100644 --- a/src/lib/lib7z/XzEnc.c +++ b/src/lib/lib7z/XzEnc.c @@ -409,10 +409,10 @@ static SRes Xz_Compress(CXzStream *xz, CLzma2WithFilters *lzmaf, int filterIndex = 0; CXzFilter *filter = NULL; const CXzFilterProps *fp = props->filterProps; - + XzBlock_ClearFlags(&block); XzBlock_SetNumFilters(&block, 1 + (fp ? 1 : 0)); - + if (fp) { filter = &block.filters[filterIndex++]; @@ -440,13 +440,13 @@ static SRes Xz_Compress(CXzStream *xz, CLzma2WithFilters *lzmaf, seqSizeOutStream.p.Write = MyWrite; seqSizeOutStream.realStream = outStream; seqSizeOutStream.processed = 0; - + RINOK(XzBlock_WriteHeader(&block, &seqSizeOutStream.p)); - + checkInStream.p.Read = SeqCheckInStream_Read; checkInStream.realStream = inStream; SeqCheckInStream_Init(&checkInStream, XzFlags_GetCheckType(xz->flags)); - + if (fp) { #ifdef USE_SUBBLOCK diff --git a/src/lib/lib7z/XzIn.c b/src/lib/lib7z/XzIn.c index 4ba87a2cfc6..adb24c0eaac 100644 --- a/src/lib/lib7z/XzIn.c +++ b/src/lib/lib7z/XzIn.c @@ -88,7 +88,7 @@ static SRes Xz_ReadIndex2(CXzStream *p, const Byte *buf, size_t size, ISzAlloc * if (numBlocks != numBlocks64 || numBlocks * 2 > size) return SZ_ERROR_ARCHIVE; } - + crcStartPos = pos; Xz_Free(p, alloc); if (numBlocks != 0) @@ -149,7 +149,7 @@ static SRes Xz_ReadBackward(CXzStream *p, ILookInStream *stream, Int64 *startOff RINOK(SeekFromCur(stream, startOffset)); RINOK(LookInStream_Read2(stream, buf, XZ_STREAM_FOOTER_SIZE, SZ_ERROR_NO_ARCHIVE)); - + if (memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) != 0) { UInt32 total = 0; @@ -185,7 +185,7 @@ static SRes Xz_ReadBackward(CXzStream *p, ILookInStream *stream, Int64 *startOff if (memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) != 0) return SZ_ERROR_NO_ARCHIVE; } - + p->flags = (CXzStreamFlags)GetBe16(buf + 8); if (!XzFlags_IsSupported(p->flags)) diff --git a/src/lib/lib7z/x7zFile.c b/src/lib/lib7z/x7zFile.c index a66c9e9d08e..8eb02b5020c 100644 --- a/src/lib/lib7z/x7zFile.c +++ b/src/lib/lib7z/x7zFile.c @@ -120,12 +120,12 @@ WRes File_Read(CSzFile *p, void *data, size_t *size) return 0; #else - + *size = fread(data, 1, originalSize, p->file); if (*size == originalSize) return 0; return ferror(p->file); - + #endif } @@ -134,7 +134,7 @@ WRes File_Write(CSzFile *p, const void *data, size_t *size) size_t originalSize = *size; if (originalSize == 0) return 0; - + #ifdef USE_WINDOWS_FILE *size = 0; @@ -160,7 +160,7 @@ WRes File_Write(CSzFile *p, const void *data, size_t *size) if (*size == originalSize) return 0; return ferror(p->file); - + #endif } @@ -190,7 +190,7 @@ WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin) return 0; #else - + int moveMethod; int res; switch (origin) @@ -203,14 +203,14 @@ WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin) res = fseek(p->file, (long)*pos, moveMethod); *pos = ftell(p->file); return res; - + #endif } WRes File_GetLength(CSzFile *p, UInt64 *length) { #ifdef USE_WINDOWS_FILE - + DWORD sizeHigh; DWORD sizeLow = GetFileSize(p->handle, &sizeHigh); if (sizeLow == 0xFFFFFFFF) @@ -221,15 +221,15 @@ WRes File_GetLength(CSzFile *p, UInt64 *length) } *length = (((UInt64)sizeHigh) << 32) + sizeLow; return 0; - + #else - + long pos = ftell(p->file); int res = fseek(p->file, 0, SEEK_END); *length = ftell(p->file); fseek(p->file, pos, SEEK_SET); return res; - + #endif } diff --git a/src/lib/util/avhuff.c b/src/lib/util/avhuff.c index 3e1126abea6..753d839b4c9 100644 --- a/src/lib/util/avhuff.c +++ b/src/lib/util/avhuff.c @@ -60,8 +60,8 @@ +02 = samples (2 bytes) - number of samples per audio stream +04 = width (2 bytes) - width of video data +06 = height (2 bytes) - height of video data - +08 = audio huffman size (2 bytes) - size of audio huffman tables - (0x0000 => uncompressed deltas are used) + +08 = audio huffman size (2 bytes) - size of audio huffman tables + (0x0000 => uncompressed deltas are used) +0A = str0size (2 bytes) - compressed size of stream 0 +0C = str1size (2 bytes) - compressed size of stream 1 ... @@ -214,7 +214,7 @@ m_flac_encoder.set_strip_metadata(true); //------------------------------------------------- -// encode_data - encode a block of data into a +// encode_data - encode a block of data into a // compressed data stream //------------------------------------------------- @@ -343,12 +343,12 @@ avhuff_error avhuff_encoder::assemble_data(UINT8 *dest, UINT32 dlength, bitmap_y *dest++ = bitmap.width() & 0xff; *dest++ = bitmap.height() >> 8; *dest++ = bitmap.height() & 0xff; - + // copy the metadata if (metadatasize > 0) memcpy(dest, metadata, metadatasize); dest += metadatasize; - + // copy the audio streams for (UINT8 curchan = 0; curchan < channels; curchan++) for (UINT32 cursamp = 0; cursamp < numsamples; cursamp++) @@ -356,7 +356,7 @@ avhuff_error avhuff_encoder::assemble_data(UINT8 *dest, UINT32 dlength, bitmap_y *dest++ = samples[curchan][cursamp] >> 8; *dest++ = samples[curchan][cursamp] & 0xff; } - + // copy the video data for (INT32 y = 0; y < bitmap.height(); y++) { @@ -372,7 +372,7 @@ avhuff_error avhuff_encoder::assemble_data(UINT8 *dest, UINT32 dlength, bitmap_y //------------------------------------------------- -// encode_audio - encode raw audio data to the +// encode_audio - encode raw audio data to the // destination //------------------------------------------------- @@ -384,20 +384,20 @@ avhuff_error avhuff_encoder::encode_audio(const UINT8 *source, int channels, int UINT16 be_test = 0; *(UINT8 *)&be_test = 1; bool swap_endian = (be_test == 1); - + // set huffman tree size to 0xffff to indicate FLAC sizes[0] = 0xff; sizes[1] = 0xff; - + // set the block size for this round and iterate over channels m_flac_encoder.set_block_size(samples); - for (int chnum = 0; chnum < channels; chnum++) + for (int chnum = 0; chnum < channels; chnum++) { // encode the data m_flac_encoder.reset(dest, samples * 2); if (!m_flac_encoder.encode_interleaved(reinterpret_cast<const INT16 *>(source) + chnum * samples, samples, swap_endian)) return AVHERR_COMPRESSION_ERROR; - + // set the size for this channel UINT32 cursize = m_flac_encoder.finish(); sizes[chnum * 2 + 2] = cursize >> 8; @@ -495,7 +495,7 @@ avhuff_error avhuff_encoder::encode_audio(const UINT8 *source, int channels, int //------------------------------------------------- -// encode_video - encode raw video data to the +// encode_video - encode raw video data to the // destination //------------------------------------------------- @@ -516,7 +516,7 @@ avhuff_error avhuff_encoder::encode_video_lossless(const UINT8 *source, int widt // set up the output; first byte is 0x80 to indicate lossless encoding bitstream_out bitbuf(dest, width * height * 2); bitbuf.write(0x80, 8); - + // compute the histograms for the data UINT16 *yrle = m_ycontext.rle_and_histo_bitmap(source + 0, width, 2, height); UINT16 *cbrle = m_cbcontext.rle_and_histo_bitmap(source + 1, width / 2, 4, height); @@ -563,7 +563,7 @@ avhuff_error avhuff_encoder::encode_video_lossless(const UINT8 *source, int widt //************************************************************************** //------------------------------------------------- -// rle_and_histo_bitmap - RLE compress and +// rle_and_histo_bitmap - RLE compress and // histogram a bitmap's worth of data //------------------------------------------------- @@ -584,12 +584,12 @@ UINT16 *avhuff_encoder::deltarle_encoder::rle_and_histo_bitmap(const UINT8 *sour // fetch current data UINT8 curdelta = *source - prevdata; prevdata = *source; - + // 0 deltas scan forward for a count if (curdelta == 0) { int zerocount = 1; - + // count the number of consecutive values const UINT8 *scandata; for (scandata = source + item_advance; scandata < end; scandata += item_advance) @@ -597,7 +597,7 @@ UINT16 *avhuff_encoder::deltarle_encoder::rle_and_histo_bitmap(const UINT8 *sour zerocount++; else break; - + // if we hit the end of a row, maximize the count if (scandata >= end && zerocount >= 8) zerocount = 100000; @@ -609,16 +609,16 @@ UINT16 *avhuff_encoder::deltarle_encoder::rle_and_histo_bitmap(const UINT8 *sour // advance past the run source += (code_to_rlecount(rlecode) - 1) * item_advance; } - + // otherwise, encode the actual data else m_encoder.histo_one(*dest++ = curdelta); } - + // advance to the next row source = end; } - + // compute the tree for our histogram m_encoder.compute_tree_from_histo(); return m_rlebuffer; @@ -787,7 +787,7 @@ avhuff_error avhuff_decoder::decode_data(const UINT8 *source, UINT32 complength, //------------------------------------------------- -// decode_audio - decode audio from a compressed +// decode_audio - decode audio from a compressed // data stream //------------------------------------------------- @@ -827,7 +827,7 @@ avhuff_error avhuff_decoder::decode_audio(int channels, int samples, const UINT8 // finish up m_flac_decoder.finish(); } - + // advance to the next channel's data source += size; } @@ -881,7 +881,7 @@ avhuff_error avhuff_decoder::decode_audio(int channels, int samples, const UINT8 curdest += 2; } } - + // otherwise, Huffman-decode the data else { @@ -902,7 +902,7 @@ avhuff_error avhuff_decoder::decode_audio(int channels, int samples, const UINT8 return AVHERR_INVALID_DATA; } } - + // advance to the next channel's data source += size; } @@ -911,7 +911,7 @@ avhuff_error avhuff_decoder::decode_audio(int channels, int samples, const UINT8 //------------------------------------------------- -// decode_video - decode video from a compressed +// decode_video - decode video from a compressed // data stream //------------------------------------------------- @@ -969,7 +969,7 @@ avhuff_error avhuff_decoder::decode_video_lossless(int width, int height, const m_cbcontext.flush_rle(); m_crcontext.flush_rle(); } - + // check for errors if we overflowed or decoded too little data if (bitbuf.overflow() || bitbuf.flush() != complength) return AVHERR_INVALID_DATA; diff --git a/src/lib/util/avhuff.h b/src/lib/util/avhuff.h index 6b192d3338e..e4425837c88 100644 --- a/src/lib/util/avhuff.h +++ b/src/lib/util/avhuff.h @@ -129,7 +129,7 @@ private: // construction/destruction deltarle_encoder() : m_rlecount(0) { } - + // histogramming UINT16 *rle_and_histo_bitmap(const UINT8 *source, UINT32 items_per_row, UINT32 item_advance, UINT32 row_count); @@ -150,10 +150,10 @@ private: avhuff_error encode_video(const UINT8 *source, int width, int height, UINT8 *dest, UINT32 &complength); avhuff_error encode_video_lossless(const UINT8 *source, int width, int height, UINT8 *dest, UINT32 &complength); - // video encoding contexts - deltarle_encoder m_ycontext; - deltarle_encoder m_cbcontext; - deltarle_encoder m_crcontext; + // video encoding contexts + deltarle_encoder m_ycontext; + deltarle_encoder m_cbcontext; + deltarle_encoder m_crcontext; // audio encoding contexts dynamic_buffer m_audiobuffer; @@ -189,7 +189,7 @@ private: // construction/destruction deltarle_decoder() : m_rlecount(0), m_prevdata(0) { } - + // general void reset() { m_rlecount = m_prevdata = 0; } @@ -212,12 +212,12 @@ private: avhuff_error decode_video_lossless(int width, int height, const UINT8 *source, UINT32 complength, UINT8 *dest, UINT32 dstride, UINT32 dxor); // internal state - avhuff_decompress_config m_config; + avhuff_decompress_config m_config; // video decoding contexts - deltarle_decoder m_ycontext; - deltarle_decoder m_cbcontext; - deltarle_decoder m_crcontext; + deltarle_decoder m_ycontext; + deltarle_decoder m_cbcontext; + deltarle_decoder m_crcontext; // audio decoding contexts huffman_8bit_decoder m_audiohi_decoder; diff --git a/src/lib/util/bitstream.h b/src/lib/util/bitstream.h index e8aa8fa1184..1c1859199d7 100644 --- a/src/lib/util/bitstream.h +++ b/src/lib/util/bitstream.h @@ -55,11 +55,11 @@ class bitstream_in public: // construction/destruction bitstream_in(const void *src, UINT32 srclength); - + // getters bool overflow() const { return ((m_doffset - m_bits / 8) > m_dlength); } UINT32 read_offset() const; - + // operations UINT32 read(int numbits); UINT32 peek(int numbits); @@ -82,10 +82,10 @@ class bitstream_out public: // construction/destruction bitstream_out(void *dest, UINT32 destlength); - + // getters bool overflow() const { return (m_doffset > m_dlength); } - + // operations void write(UINT32 newbits, int numbits); UINT32 flush(); diff --git a/src/lib/util/cdrom.c b/src/lib/util/cdrom.c index 47e5c9ff627..d0977a1f534 100644 --- a/src/lib/util/cdrom.c +++ b/src/lib/util/cdrom.c @@ -380,7 +380,7 @@ UINT32 cdrom_read_subcode(cdrom_file *file, UINT32 lbasector, void *buffer) UINT32 chdsector = physical_to_chd_lba(file, lbasector, tracknum); if (file->cdtoc.tracks[tracknum].subsize == 0) return 1; - + // read the data chd_error err = read_partial_sector(file, buffer, chdsector, tracknum, file->cdtoc.tracks[tracknum].datasize, file->cdtoc.tracks[tracknum].subsize); return (err == CHDERR_NONE); diff --git a/src/lib/util/chd.c b/src/lib/util/chd.c index 53665056ea3..61fc8641ef4 100644 --- a/src/lib/util/chd.c +++ b/src/lib/util/chd.c @@ -90,7 +90,7 @@ enum COMPRESSION_NONE = 4, // no compression; implicit length = hunkbytes COMPRESSION_SELF = 5, // same as another block in this chd COMPRESSION_PARENT = 6, // same as a hunk's worth of units in the parent chd - + // these additional pseudo-types are used for compressed encodings: COMPRESSION_RLE_SMALL, // start of small RLE run (4-bit length) COMPRESSION_RLE_LARGE, // start of large RLE run (8-bit length) @@ -125,8 +125,8 @@ struct chd_file::metadata_entry struct chd_file::metadata_hash { - UINT8 tag[4]; // tag of the metadata in big-endian - sha1_t sha1; // hash data + UINT8 tag[4]; // tag of the metadata in big-endian + sha1_t sha1; // hash data }; @@ -179,7 +179,7 @@ inline sha1_t chd_file::be_read_sha1(const UINT8 *base) //------------------------------------------------- -// be_write_sha1 - write a sha1_t to a data +// be_write_sha1 - write a sha1_t to a data // stream in bigendian order //------------------------------------------------- @@ -199,7 +199,7 @@ inline void chd_file::file_read(UINT64 offset, void *dest, UINT32 length) // no file = failure if (m_file == NULL) throw CHDERR_NOT_OPEN; - + // seek and read core_fseek(m_file, offset, SEEK_SET); UINT32 count = core_fread(m_file, dest, length); @@ -218,7 +218,7 @@ inline void chd_file::file_write(UINT64 offset, const void *source, UINT32 lengt // no file = failure if (m_file == NULL) throw CHDERR_NOT_OPEN; - + // seek and write core_fseek(m_file, offset, SEEK_SET); UINT32 count = core_fwrite(m_file, source, length); @@ -229,7 +229,7 @@ inline void chd_file::file_write(UINT64 offset, const void *source, UINT32 lengt //------------------------------------------------- // file_append - append to the file at the given -// offset, ensuring we start at the given +// offset, ensuring we start at the given // alignment; on failure throw an error //------------------------------------------------- @@ -346,7 +346,7 @@ sha1_t chd_file::raw_sha1() // determine offset within the file for data-only if (m_rawsha1_offset == 0) throw CHDERR_UNSUPPORTED_VERSION; - + // read the big-endian version UINT8 rawbuf[sizeof(sha1_t)]; file_read(m_rawsha1_offset, rawbuf, sizeof(rawbuf)); @@ -371,7 +371,7 @@ sha1_t chd_file::parent_sha1() // determine offset within the file if (m_parentsha1_offset == 0) throw CHDERR_UNSUPPORTED_VERSION; - + // read the big-endian version UINT8 rawbuf[sizeof(sha1_t)]; file_read(m_parentsha1_offset, rawbuf, sizeof(rawbuf)); @@ -395,7 +395,7 @@ chd_error chd_file::hunk_info(UINT32 hunknum, chd_codec_type &compressor, UINT32 // error if invalid if (hunknum >= m_hunkcount) return CHDERR_HUNK_OUT_OF_RANGE; - + // get the map pointer UINT8 *rawmap; switch (m_version) @@ -410,17 +410,17 @@ chd_error chd_file::hunk_info(UINT32 hunknum, chd_codec_type &compressor, UINT32 compressor = CHD_CODEC_ZLIB; compbytes = be_read(&rawmap[12], 2) + (rawmap[14] << 16); break; - + case V34_MAP_ENTRY_TYPE_UNCOMPRESSED: compressor = CHD_CODEC_NONE; compbytes = m_hunkbytes; break; - + case V34_MAP_ENTRY_TYPE_MINI: compressor = CHD_CODEC_MINI; compbytes = 0; break; - + case V34_MAP_ENTRY_TYPE_SELF_HUNK: compressor = CHD_CODEC_SELF; compbytes = 0; @@ -432,7 +432,7 @@ chd_error chd_file::hunk_info(UINT32 hunknum, chd_codec_type &compressor, UINT32 break; } break; - + // v5 map entries case 5: rawmap = m_rawmap + m_mapentrybytes * hunknum; @@ -452,7 +452,7 @@ chd_error chd_file::hunk_info(UINT32 hunknum, chd_codec_type &compressor, UINT32 } break; } - + // compressed case switch (rawmap[0]) { @@ -473,7 +473,7 @@ chd_error chd_file::hunk_info(UINT32 hunknum, chd_codec_type &compressor, UINT32 compressor = CHD_CODEC_SELF; compbytes = 0; break; - + case COMPRESSION_PARENT: compressor = CHD_CODEC_PARENT; compbytes = 0; @@ -494,12 +494,12 @@ void chd_file::set_raw_sha1(sha1_t rawdata) // create a big-endian version UINT8 rawbuf[sizeof(sha1_t)]; be_write_sha1(rawbuf, rawdata); - + // write to the header UINT64 offset = (m_rawsha1_offset != 0) ? m_rawsha1_offset : m_sha1_offset; assert(offset != 0); file_write(offset, rawbuf, sizeof(rawbuf)); - + // if we have a separate rawsha1_offset, update the full sha1 as well if (m_rawsha1_offset != 0) metadata_update_hash(); @@ -519,7 +519,7 @@ void chd_file::set_parent_sha1(sha1_t parent) // create a big-endian version UINT8 rawbuf[sizeof(sha1_t)]; be_write_sha1(rawbuf, parent); - + // write to the header assert(m_parentsha1_offset != 0); file_write(m_parentsha1_offset, rawbuf, sizeof(rawbuf)); @@ -602,7 +602,7 @@ chd_error chd_file::create(const char *filename, UINT64 logicalbytes, UINT32 hun // create the file normally, then claim the file chd_error chderr = create(*file, logicalbytes, hunkbytes, unitbytes, compression); m_owns_file = true; - + // if an error happened, close and delete the file if (chderr != CHDERR_NONE) { @@ -633,7 +633,7 @@ chd_error chd_file::create(const char *filename, UINT64 logicalbytes, UINT32 hun // create the file normally, then claim the file chd_error chderr = create(*file, logicalbytes, hunkbytes, compression, parent); m_owns_file = true; - + // if an error happened, close and delete the file if (chderr != CHDERR_NONE) { @@ -669,7 +669,7 @@ chd_error chd_file::open(const char *filename, bool writeable, chd_file *parent) core_fclose(file); return err; } - + // we now own this file m_owns_file = true; return err; @@ -708,7 +708,7 @@ void chd_file::close() m_owns_file = false; m_allow_reads = false; m_allow_writes = false; - + // reset core parameters from the header m_version = HEADER_VERSION; m_logicalbytes = 0; @@ -759,7 +759,7 @@ chd_error chd_file::read_hunk(UINT32 hunknum, void *buffer) // punt if no file if (m_file == NULL) throw CHDERR_NOT_OPEN; - + // return an error if out of range if (hunknum >= m_hunkcount) throw CHDERR_HUNK_OUT_OF_RANGE; @@ -787,13 +787,13 @@ chd_error chd_file::read_hunk(UINT32 hunknum, void *buffer) if (!(rawmap[15] & V34_MAP_ENTRY_FLAG_NO_CRC) && dest != NULL && crc32_creator::simple(dest, m_hunkbytes) != blockcrc) throw CHDERR_DECOMPRESSION_ERROR; return CHDERR_NONE; - + case V34_MAP_ENTRY_TYPE_UNCOMPRESSED: file_read(blockoffs, dest, m_hunkbytes); if (!(rawmap[15] & V34_MAP_ENTRY_FLAG_NO_CRC) && crc32_creator::simple(dest, m_hunkbytes) != blockcrc) throw CHDERR_DECOMPRESSION_ERROR; return CHDERR_NONE; - + case V34_MAP_ENTRY_TYPE_MINI: be_write(dest, blockoffs, 8); for (UINT32 bytes = 8; bytes < m_hunkbytes; bytes++) @@ -801,7 +801,7 @@ chd_error chd_file::read_hunk(UINT32 hunknum, void *buffer) if (!(rawmap[15] & V34_MAP_ENTRY_FLAG_NO_CRC) && crc32_creator::simple(dest, m_hunkbytes) != blockcrc) throw CHDERR_DECOMPRESSION_ERROR; return CHDERR_NONE; - + case V34_MAP_ENTRY_TYPE_SELF_HUNK: return read_hunk(blockoffs, dest); @@ -811,7 +811,7 @@ chd_error chd_file::read_hunk(UINT32 hunknum, void *buffer) return m_parent->read_hunk(blockoffs, dest); } break; - + // v5 map entries case 5: rawmap = m_rawmap + m_mapentrybytes * hunknum; @@ -819,7 +819,7 @@ chd_error chd_file::read_hunk(UINT32 hunknum, void *buffer) // uncompressed case if (!compressed()) { - blockoffs = UINT64(be_read(rawmap, 4)) * UINT64(m_hunkbytes); + blockoffs = UINT64(be_read(rawmap, 4)) * UINT64(m_hunkbytes); if (blockoffs != 0) file_read(blockoffs, dest, m_hunkbytes); else if (m_parent_missing) @@ -830,7 +830,7 @@ chd_error chd_file::read_hunk(UINT32 hunknum, void *buffer) memset(dest, 0, m_hunkbytes); return CHDERR_NONE; } - + // compressed case blocklen = be_read(&rawmap[1], 3); blockoffs = be_read(&rawmap[4], 6); @@ -857,7 +857,7 @@ chd_error chd_file::read_hunk(UINT32 hunknum, void *buffer) case COMPRESSION_SELF: return read_hunk(blockoffs, dest); - + case COMPRESSION_PARENT: if (m_parent_missing) throw CHDERR_REQUIRES_PARENT; @@ -865,11 +865,11 @@ chd_error chd_file::read_hunk(UINT32 hunknum, void *buffer) } break; } - + // if we get here, something was wrong throw CHDERR_READ_ERROR; } - + // just return errors catch (chd_error &err) { @@ -902,7 +902,7 @@ chd_error chd_file::write_hunk(UINT32 hunknum, const void *buffer) // uncompressed writes only via this interface if (compressed()) throw CHDERR_FILE_NOT_WRITEABLE; - + // see if we have allocated the space on disk for this hunk UINT8 *rawmap = m_rawmap + hunknum * 4; UINT32 rawentry = be_read(rawmap, 4); @@ -919,29 +919,29 @@ chd_error chd_file::write_hunk(UINT32 hunknum, const void *buffer) all_zeros = false; break; } - + // if it's all zeros, do nothing more if (all_zeros) return CHDERR_NONE; - + // append new data to the end of the file, aligning the first chunk rawentry = file_append(buffer, m_hunkbytes, m_hunkbytes) / m_hunkbytes; - + // write the map entry back be_write(rawmap, rawentry, 4); file_write(m_mapoffset + hunknum * 4, rawmap, 4); - + // update the cached hunk if we just wrote it if (hunknum == m_cachehunk && buffer != m_cache) memcpy(m_cache, buffer, m_hunkbytes); } - + // otherwise, just overwrite else file_write(UINT64(rawentry) * UINT64(m_hunkbytes), buffer, m_hunkbytes); return CHDERR_NONE; } - + // just return errors catch (chd_error &err) { @@ -973,7 +973,7 @@ chd_error chd_file::write_units(UINT64 unitnum, const void *buffer, UINT32 count //------------------------------------------------- -// read_bytes - read from the CHD at a byte level, +// read_bytes - read from the CHD at a byte level, // using the cache to handle partial hunks //------------------------------------------------- @@ -988,12 +988,12 @@ chd_error chd_file::read_bytes(UINT64 offset, void *buffer, UINT32 bytes) // determine start/end boundaries UINT32 startoffs = (curhunk == first_hunk) ? (offset % m_hunkbytes) : 0; UINT32 endoffs = (curhunk == last_hunk) ? ((offset + bytes - 1) % m_hunkbytes) : (m_hunkbytes - 1); - + // if it's a full block, just read directly from disk unless it's the cached hunk chd_error err = CHDERR_NONE; if (startoffs == 0 && endoffs == m_hunkbytes - 1 && curhunk != m_cachehunk) err = read_hunk(curhunk, dest); - + // otherwise, read from the cache else { @@ -1032,12 +1032,12 @@ chd_error chd_file::write_bytes(UINT64 offset, const void *buffer, UINT32 bytes) // determine start/end boundaries UINT32 startoffs = (curhunk == first_hunk) ? (offset % m_hunkbytes) : 0; UINT32 endoffs = (curhunk == last_hunk) ? ((offset + bytes - 1) % m_hunkbytes) : (m_hunkbytes - 1); - + // if it's a full block, just write directly to disk unless it's the cached hunk chd_error err = CHDERR_NONE; if (startoffs == 0 && endoffs == m_hunkbytes - 1 && curhunk != m_cachehunk) err = write_hunk(curhunk, source); - + // otherwise, write from the cache else { @@ -1080,7 +1080,7 @@ chd_error chd_file::read_metadata(chd_metadata_tag searchtag, UINT32 searchindex file_read(metaentry.offset + METADATA_HEADER_SIZE, output.stringbuffer(metaentry.length), metaentry.length); return CHDERR_NONE; } - + // just return errors catch (chd_error &err) { @@ -1103,7 +1103,7 @@ chd_error chd_file::read_metadata(chd_metadata_tag searchtag, UINT32 searchindex file_read(metaentry.offset + METADATA_HEADER_SIZE, output, metaentry.length); return CHDERR_NONE; } - + // just return errors catch (chd_error &err) { @@ -1126,7 +1126,7 @@ chd_error chd_file::read_metadata(chd_metadata_tag searchtag, UINT32 searchindex file_read(metaentry.offset + METADATA_HEADER_SIZE, output, MIN(outputlen, resultlen)); return CHDERR_NONE; } - + // just return errors catch (chd_error &err) { @@ -1151,7 +1151,7 @@ chd_error chd_file::read_metadata(chd_metadata_tag searchtag, UINT32 searchindex resultflags = metaentry.flags; return CHDERR_NONE; } - + // just return errors catch (chd_error &err) { @@ -1191,16 +1191,16 @@ chd_error chd_file::write_metadata(chd_metadata_tag metatag, UINT32 metaindex, c be_write(length, inputlen, 3); file_write(metaentry.offset + 5, length, sizeof(length)); } - + // indicate we did everything finished = true; } - + // if it doesn't fit, unlink the current entry else metadata_set_previous_next(metaentry.prev, metaentry.next); } - + // if not yet done, create a new entry and append if (!finished) { @@ -1210,7 +1210,7 @@ chd_error chd_file::write_metadata(chd_metadata_tag metatag, UINT32 metaindex, c raw_meta_header[4] = flags; be_write(&raw_meta_header[5], (inputlen & 0x00ffffff) | (flags << 24), 3); be_write(&raw_meta_header[8], 0, 8); - + // append the new header, then the data UINT64 offset = file_append(raw_meta_header, sizeof(raw_meta_header)); file_append(inputbuf, inputlen); @@ -1223,7 +1223,7 @@ chd_error chd_file::write_metadata(chd_metadata_tag metatag, UINT32 metaindex, c metadata_update_hash(); return CHDERR_NONE; } - + // return any errors catch (chd_error &err) { @@ -1246,12 +1246,12 @@ chd_error chd_file::delete_metadata(chd_metadata_tag metatag, UINT32 metaindex) metadata_entry metaentry; if (!metadata_find(metatag, metaindex, metaentry)) throw CHDERR_METADATA_NOT_FOUND; - + // point the previous to the next, unlinking us metadata_set_previous_next(metaentry.prev, metaentry.next); return CHDERR_NONE; } - + // return any errors catch (chd_error &err) { @@ -1261,7 +1261,7 @@ chd_error chd_file::delete_metadata(chd_metadata_tag metatag, UINT32 metaindex) //------------------------------------------------- -// clone_all_metadata - clone the metadata from +// clone_all_metadata - clone the metadata from // one CHD to a second //------------------------------------------------- @@ -1282,7 +1282,7 @@ chd_error chd_file::clone_all_metadata(chd_file &source) // read the metadata item filedata.resize(metaentry.length); source.file_read(metaentry.offset + METADATA_HEADER_SIZE, filedata, metaentry.length); - + // write it to the destination chd_error err = write_metadata(metaentry.metatag, (UINT32)-1, filedata, metaentry.length, metaentry.flags); if (err != CHDERR_NONE) @@ -1290,7 +1290,7 @@ chd_error chd_file::clone_all_metadata(chd_file &source) } return CHDERR_NONE; } - + // return any errors catch (chd_error &err) { @@ -1363,7 +1363,7 @@ chd_error chd_file::codec_configure(chd_codec_type codec, int param, void *confi } return CHDERR_INVALID_PARAMETER; } - + // return any errors catch (chd_error &err) { @@ -1425,7 +1425,7 @@ const char *chd_file::error_string(chd_error err) //------------------------------------------------- // guess_unitbytes - for older CHD formats, take -// a guess at the bytes/unit based on metadata +// a guess at the bytes/unit based on metadata //------------------------------------------------- UINT32 chd_file::guess_unitbytes() @@ -1441,7 +1441,7 @@ UINT32 chd_file::guess_unitbytes() read_metadata(CDROM_TRACK_METADATA_TAG, 0, metadata) == CHDERR_NONE || read_metadata(CDROM_TRACK_METADATA2_TAG, 0, metadata) == CHDERR_NONE) return CD_FRAME_SIZE; - + // otherwise, just map 1:1 with the hunk size return m_hunkbytes; } @@ -1464,7 +1464,7 @@ void chd_file::parse_v3_header(UINT8 *rawheader, sha1_t &parentsha1) m_metaoffset = be_read(&rawheader[36], 8); m_hunkbytes = be_read(&rawheader[76], 4); m_hunkcount = be_read(&rawheader[24], 4); - + // extract parent SHA-1 UINT32 flags = be_read(&rawheader[16], 4); if ((flags & 2) && m_allow_writes) @@ -1480,21 +1480,21 @@ void chd_file::parse_v3_header(UINT8 *rawheader, sha1_t &parentsha1) default: throw CHDERR_UNKNOWN_COMPRESSION; } m_compression[1] = m_compression[2] = m_compression[3] = CHD_CODEC_NONE; - + // describe the format m_mapoffset_offset = 0; m_metaoffset_offset = 36; m_sha1_offset = 80; m_rawsha1_offset = 0; m_parentsha1_offset = 100; - + // determine properties of map entries m_mapentrybytes = 16; // extract parent SHA-1 if (flags & 1) parentsha1 = be_read_sha1(&rawheader[m_parentsha1_offset]); - + // guess at the units based on snooping the metadata m_unitbytes = guess_unitbytes(); m_unitcount = (m_logicalbytes + m_unitbytes - 1) / m_unitbytes; @@ -1518,7 +1518,7 @@ void chd_file::parse_v4_header(UINT8 *rawheader, sha1_t &parentsha1) m_metaoffset = be_read(&rawheader[36], 8); m_hunkbytes = be_read(&rawheader[44], 4); m_hunkcount = be_read(&rawheader[24], 4); - + // extract parent SHA-1 UINT32 flags = be_read(&rawheader[16], 4); if ((flags & 2) && m_allow_writes) @@ -1534,21 +1534,21 @@ void chd_file::parse_v4_header(UINT8 *rawheader, sha1_t &parentsha1) default: throw CHDERR_UNKNOWN_COMPRESSION; } m_compression[1] = m_compression[2] = m_compression[3] = CHD_CODEC_NONE; - + // describe the format m_mapoffset_offset = 0; m_metaoffset_offset = 36; m_sha1_offset = 48; m_rawsha1_offset = 88; m_parentsha1_offset = 68; - + // determine properties of map entries m_mapentrybytes = 16; // extract parent SHA-1 if (flags & 1) parentsha1 = be_read_sha1(&rawheader[m_parentsha1_offset]); - + // guess at the units based on snooping the metadata m_unitbytes = guess_unitbytes(); m_unitcount = (m_logicalbytes + m_unitbytes - 1) / m_unitbytes; @@ -1574,20 +1574,20 @@ void chd_file::parse_v5_header(UINT8 *rawheader, sha1_t &parentsha1) m_hunkcount = (m_logicalbytes + m_hunkbytes - 1) / m_hunkbytes; m_unitbytes = be_read(&rawheader[60], 4); m_unitcount = (m_logicalbytes + m_unitbytes - 1) / m_unitbytes; - + // determine compression m_compression[0] = be_read(&rawheader[16], 4); m_compression[1] = be_read(&rawheader[20], 4); m_compression[2] = be_read(&rawheader[24], 4); m_compression[3] = be_read(&rawheader[28], 4); - + // describe the format m_mapoffset_offset = 40; m_metaoffset_offset = 48; m_sha1_offset = 84; m_rawsha1_offset = 64; m_parentsha1_offset = 104; - + // determine properties of map entries m_mapentrybytes = compressed() ? 12 : 4; @@ -1608,10 +1608,10 @@ chd_error chd_file::compress_v5_map() // first get a CRC-16 of the original rawmap crc16_t mapcrc = crc16_creator::simple(m_rawmap, m_hunkcount * 12); - // create a buffer to hold the RLE data + // create a buffer to hold the RLE data dynamic_buffer compression_rle(m_hunkcount); UINT8 *dest = compression_rle; - + // use a huffman encoder for 16 different codes, maximum length is 8 bits huffman_encoder<16, 8> encoder; encoder.histo_reset(); @@ -1627,7 +1627,7 @@ chd_error chd_file::compress_v5_map() for (int hunknum = 0; hunknum < m_hunkcount; hunknum++) { UINT8 curcomp = m_rawmap[hunknum * 12 + 0]; - + // promote self block references to more compact forms if (curcomp == COMPRESSION_SELF) { @@ -1655,15 +1655,15 @@ chd_error chd_file::compress_v5_map() max_parent = MAX(max_parent, refunit); last_parent = refunit; } - + // track maximum compressed length else //if (curcomp >= COMPRESSION_TYPE_0 && curcomp <= COMPRESSION_TYPE_3) max_complen = MAX(max_complen, be_read(&m_rawmap[hunknum * 12 + 1], 3)); - + // track repeats if (curcomp == lastcomp) count++; - + // if no repeat, or we're at the end, flush it if (curcomp != lastcomp || hunknum == m_hunkcount - 1) { @@ -1690,7 +1690,7 @@ chd_error chd_file::compress_v5_map() encoder.histo_one(*dest++ = lastcomp = curcomp); } } - + // compute a tree and export it to the buffer dynamic_buffer compressed(m_hunkcount * 6); bitstream_out bitbuf(&compressed[16], compressed.count() - 16); @@ -1704,7 +1704,7 @@ chd_error chd_file::compress_v5_map() // encode the data for (UINT8 *src = compression_rle; src < dest; src++) encoder.encode_one(bitbuf, *src); - + // determine the number of bits we need to hold the a length // and a hunk index UINT8 lengthbits = bits_for_value(max_complen); @@ -1722,7 +1722,7 @@ chd_error chd_file::compress_v5_map() UINT32 length = be_read(&rawmap[1], 3); UINT64 offset = be_read(&rawmap[4], 6); UINT16 crc = be_read(&rawmap[10], 2); - + // if no count remaining, fetch the next entry if (count == 0) { @@ -1736,7 +1736,7 @@ chd_error chd_file::compress_v5_map() } else count--; - + // output additional data needed for this entry switch (lastcomp) { @@ -1750,23 +1750,23 @@ chd_error chd_file::compress_v5_map() if (firstoffs == 0) firstoffs = offset; break; - + case COMPRESSION_NONE: bitbuf.write(crc, 16); if (firstoffs == 0) firstoffs = offset; break; - + case COMPRESSION_SELF: assert(offset < (UINT64(1) << selfbits)); bitbuf.write(offset, selfbits); break; - + case COMPRESSION_PARENT: assert(offset < (UINT64(1) << parentbits)); bitbuf.write(offset, parentbits); break; - + case COMPRESSION_SELF_0: case COMPRESSION_SELF_1: case COMPRESSION_PARENT_SELF: @@ -1775,7 +1775,7 @@ chd_error chd_file::compress_v5_map() break; } } - + // write the map header UINT32 complen = bitbuf.flush(); assert(!bitbuf.overflow()); @@ -1785,10 +1785,10 @@ chd_error chd_file::compress_v5_map() compressed[12] = lengthbits; compressed[13] = selfbits; compressed[14] = parentbits; - + // write the result m_mapoffset = file_append(compressed, complen + 16); - + // then write the map offset UINT8 rawbuf[sizeof(UINT64)]; be_write(rawbuf, m_mapoffset, 8); @@ -1824,12 +1824,12 @@ void chd_file::decompress_v5_map() UINT8 lengthbits = rawbuf[12]; UINT8 selfbits = rawbuf[13]; UINT8 parentbits = rawbuf[14]; - + // now read the map dynamic_buffer compressed(mapbytes); file_read(m_mapoffset + 16, compressed, mapbytes); bitstream_in bitbuf(compressed, compressed.count()); - + // first decode the compression types huffman_decoder<16, 8> decoder; huffman_error err = decoder.import_tree_rle(bitbuf); @@ -1853,7 +1853,7 @@ void chd_file::decompress_v5_map() rawmap[0] = lastcomp = val; } } - + // then iterate through the hunks and extract the needed data UINT64 curoffset = firstoffs; UINT32 last_self = 0; @@ -1874,21 +1874,21 @@ void chd_file::decompress_v5_map() curoffset += length = bitbuf.read(lengthbits); crc = bitbuf.read(16); break; - + case COMPRESSION_NONE: curoffset += length = m_hunkbytes; crc = bitbuf.read(16); break; - + case COMPRESSION_SELF: last_self = offset = bitbuf.read(selfbits); break; - + case COMPRESSION_PARENT: offset = bitbuf.read(parentbits); last_parent = offset; break; - + // pseudo-types; convert into base types case COMPRESSION_SELF_1: last_self++; @@ -1896,12 +1896,12 @@ void chd_file::decompress_v5_map() rawmap[0] = COMPRESSION_SELF; offset = last_self; break; - + case COMPRESSION_PARENT_SELF: rawmap[0] = COMPRESSION_PARENT; last_parent = offset = (UINT64(hunknum) * UINT64(m_hunkbytes)) / m_unitbytes; break; - + case COMPRESSION_PARENT_1: last_parent += m_hunkbytes / m_unitbytes; case COMPRESSION_PARENT_0: @@ -1913,12 +1913,12 @@ void chd_file::decompress_v5_map() be_write(&rawmap[4], offset, 6); be_write(&rawmap[10], crc, 2); } - + // verify the final CRC if (crc16_creator::simple(m_rawmap, m_hunkcount * 12) != mapcrc) throw CHDERR_DECOMPRESSION_ERROR; } - + //------------------------------------------------- // create_common - command path when creating a @@ -1933,17 +1933,17 @@ chd_error chd_file::create_common() // if we have a parent, it must be V3 or later if (m_parent != NULL && m_parent->version() < 3) throw CHDERR_UNSUPPORTED_VERSION; - + // must be an even number of units per hunk if (m_hunkbytes % m_unitbytes != 0) throw CHDERR_INVALID_PARAMETER; if (m_parent != NULL && m_unitbytes != m_parent->unit_bytes()) throw CHDERR_INVALID_PARAMETER; - + // writes are obviously permitted; reads only if uncompressed m_allow_writes = true; m_allow_reads = !compressed(); - + // verify the compression types bool found_zero = false; for (int codecnum = 0; codecnum < ARRAY_LENGTH(m_compression); codecnum++) @@ -1978,11 +1978,11 @@ chd_error chd_file::create_common() // write the resulting header file_write(0, rawheader, sizeof(rawheader)); - + // parse it back out to set up fields appropriately sha1_t parentsha1; parse_v5_header(rawheader, parentsha1); - + // write out the map (if not compressed) if (!compressed()) { @@ -2001,7 +2001,7 @@ chd_error chd_file::create_common() // finish opening the file create_open_common(); } - + // handle errors by closing ourself catch (chd_error &err) { @@ -2030,20 +2030,20 @@ chd_error chd_file::open_common(bool writeable) // reads are always permitted; writes possibly as well m_allow_reads = true; m_allow_writes = writeable; - + // read the raw header UINT8 rawheader[MAX_HEADER_SIZE]; file_read(0, rawheader, sizeof(rawheader)); - + // verify the signature if (memcmp(rawheader, "MComprHD", 8) != 0) throw CHDERR_INVALID_FILE; - + // only allow writes to the most recent version m_version = be_read(&rawheader[12], 4); if (m_allow_writes && m_version < HEADER_VERSION) throw CHDERR_UNSUPPORTED_VERSION; - + // read the header if we support it sha1_t parentsha1 = sha1_t::null; switch (m_version) @@ -2051,9 +2051,9 @@ chd_error chd_file::open_common(bool writeable) case 3: parse_v3_header(rawheader, parentsha1); break; case 4: parse_v4_header(rawheader, parentsha1); break; case 5: parse_v5_header(rawheader, parentsha1); break; - default: throw CHDERR_UNSUPPORTED_VERSION; + default: throw CHDERR_UNSUPPORTED_VERSION; } - + // make sure we have a parent if we need one (and don't if we don't) if (parentsha1 != sha1_t::null) { @@ -2064,12 +2064,12 @@ chd_error chd_file::open_common(bool writeable) } else if (parentsha1 == sha1_t::null && m_parent != NULL) throw CHDERR_INVALID_PARAMETER; - + // finish opening the file create_open_common(); return CHDERR_NONE; } - + // handle errors by closing ourself catch (chd_error &err) { @@ -2093,7 +2093,7 @@ void chd_file::create_open_common() if (m_decompressor[decompnum] == NULL && m_compression[decompnum] != 0) throw CHDERR_UNKNOWN_COMPRESSION; } - + // read the map; v5+ compressed drives need to read and decompress their map m_rawmap.resize(m_hunkcount * m_mapentrybytes); if (m_version >= 5 && compressed()) @@ -2135,16 +2135,16 @@ void chd_file::verify_proper_compression_append(UINT32 hunknum) UINT8 *rawmap = &m_rawmap[hunknum * 12]; if (rawmap[0] != 0xff) throw CHDERR_COMPRESSION_ERROR; - + // if this isn't the first block, only permitted to write immediately // after the previous one if (hunknum != 0 && rawmap[-12] == 0xff) throw CHDERR_COMPRESSION_ERROR; } - + //------------------------------------------------- -// hunk_write_compressed - write a hunk to a +// hunk_write_compressed - write a hunk to a // compressed CHD, discovering the best // technique //------------------------------------------------- @@ -2153,10 +2153,10 @@ void chd_file::hunk_write_compressed(UINT32 hunknum, INT8 compression, const UIN { // verify that we are appending properly to a compressed file verify_proper_compression_append(hunknum); - + // write the final result UINT64 offset = file_append(compressed, complength); - + // update the map entry UINT8 *rawmap = &m_rawmap[hunknum * 12]; rawmap[0] = (compression == -1) ? COMPRESSION_NONE : compression; @@ -2175,10 +2175,10 @@ void chd_file::hunk_copy_from_self(UINT32 hunknum, UINT32 otherhunk) { // verify that we are appending properly to a compressed file verify_proper_compression_append(hunknum); - + // only permitted to reference prior hunks if (otherhunk >= hunknum) - throw CHDERR_INVALID_PARAMETER; + throw CHDERR_INVALID_PARAMETER; // update the map entry UINT8 *rawmap = &m_rawmap[hunknum * 12]; @@ -2273,11 +2273,11 @@ void chd_file::metadata_set_previous_next(UINT64 prevoffset, UINT64 nextoffset) // otherwise, update the link in the previous header else offset = prevoffset + 8; - + // create a big-endian version UINT8 rawbuf[sizeof(UINT64)]; be_write(rawbuf, nextoffset, 8); - + // write to the header and update our local copy file_write(offset, rawbuf, sizeof(rawbuf)); } @@ -2296,11 +2296,11 @@ void chd_file::metadata_update_hash() // compute the new overall hash sha1_t fullsha1 = compute_overall_sha1(raw_sha1()); - + // create a big-endian version UINT8 rawbuf[sizeof(sha1_t)]; be_write_sha1(&rawbuf[0], fullsha1); - + // write to the header file_write(m_sha1_offset, rawbuf, sizeof(rawbuf)); } @@ -2356,7 +2356,7 @@ chd_file_compressor::~chd_file_compressor() // free the work queues osd_work_queue_free(m_read_queue); osd_work_queue_free(m_work_queue); - + // delete allocated arrays for (int codecnum = 0; codecnum < ARRAY_LENGTH(m_codecs); codecnum++) delete m_codecs[codecnum]; @@ -2374,16 +2374,16 @@ void chd_file_compressor::compress_begin() m_total_in = 0; m_total_out = 0; m_compsha1.reset(); - + // reset our maps m_parent_map.reset(); m_current_map.reset(); - + // reset read state m_read_queue_offset = 0; m_read_done_offset = 0; m_read_error = false; - + // reset work item state m_work_buffer.resize(hunk_bytes() * (WORK_BUFFER_HUNKS + 1)); m_compressed_buffer.resize(hunk_bytes() * WORK_BUFFER_HUNKS); @@ -2395,14 +2395,14 @@ void chd_file_compressor::compress_begin() item.m_compressed = m_compressed_buffer + hunk_bytes() * itemnum; item.m_hash.resize(hunk_bytes() / unit_bytes()); } - + // initialize codec instances for (int instance = 0; instance < ARRAY_LENGTH(m_codecs); instance++) { delete m_codecs[instance]; m_codecs[instance] = new chd_compressor_group(*this, m_compression); } - + // reset write state m_write_hunk = 0; } @@ -2429,10 +2429,10 @@ chd_error chd_file_compressor::compress_continue(double &progress, double &ratio if (m_work_item[curitem % WORK_BUFFER_HUNKS].m_status != WS_READY) break; - // if it's not all clear, defer + // if it's not all clear, defer if (curitem != enditem) break; - + // if we're walking the parent, we want one more item to have cleared so we // can read an extra hunk there if (m_walking_parent && m_work_item[curitem % WORK_BUFFER_HUNKS].m_status != WS_READY) @@ -2444,12 +2444,12 @@ chd_error chd_file_compressor::compress_continue(double &progress, double &ratio osd_work_item_queue(m_read_queue, async_read_static, this, WORK_ITEM_FLAG_AUTO_RELEASE); m_read_queue_offset += WORK_BUFFER_HUNKS * hunk_bytes() / 2; } - + // flush out any finished items while (m_work_item[m_write_hunk % WORK_BUFFER_HUNKS].m_status == WS_COMPLETE) { work_item &item = m_work_item[m_write_hunk % WORK_BUFFER_HUNKS]; - + // free any OSD work item if (item.m_osd != NULL) osd_work_item_release(item.m_osd); @@ -2466,22 +2466,22 @@ chd_error chd_file_compressor::compress_continue(double &progress, double &ratio if (m_parent_map.find(item.m_hash[unit].m_crc16, item.m_hash[unit].m_sha1) == hashmap::NOT_FOUND) m_parent_map.add(item.m_hunknum * uph + unit, item.m_hash[unit].m_crc16, item.m_hash[unit].m_sha1); } - + // if we're uncompressed, use regular writes else if (!compressed()) { chd_error err = write_hunk(item.m_hunknum, item.m_data); if (err != CHDERR_NONE) return err; - - // writes of all-0 data don't actually take space, so see if we count this + + // writes of all-0 data don't actually take space, so see if we count this chd_codec_type codec = CHD_CODEC_NONE; UINT32 complen; hunk_info(item.m_hunknum, codec, complen); if (codec == CHD_CODEC_NONE) m_total_out += m_hunkbytes; } - + // for compressing, process the result else do { @@ -2492,7 +2492,7 @@ chd_error chd_file_compressor::compress_continue(double &progress, double &ratio hunk_copy_from_self(item.m_hunknum, selfhunk); break; } - + // if not, see if it's in the parent map if (m_parent != NULL) { @@ -2503,17 +2503,17 @@ chd_error chd_file_compressor::compress_continue(double &progress, double &ratio break; } } - + // otherwise, append it compressed and add to the self map hunk_write_compressed(item.m_hunknum, item.m_compression, item.m_compressed, item.m_complen, item.m_hash[0].m_crc16); m_total_out += item.m_complen; m_current_map.add(item.m_hunknum, item.m_hash[0].m_crc16, item.m_hash[0].m_sha1); } while (0); - + // reset the item and advance item.m_status = WS_READY; m_write_hunk++; - + // if we hit the end, finalize if (m_write_hunk == m_hunkcount) { @@ -2526,7 +2526,7 @@ chd_error chd_file_compressor::compress_continue(double &progress, double &ratio for (int itemnum = 0; itemnum < WORK_BUFFER_HUNKS; itemnum++) m_work_item[itemnum].m_status = WS_READY; } - + // wait for all reads to finish and if we're compressed, write the final SHA1 and map else { @@ -2538,7 +2538,7 @@ chd_error chd_file_compressor::compress_continue(double &progress, double &ratio } } } - + // update progress and ratio if (m_walking_parent) progress = double(m_read_done_offset) / double(logical_bytes()); @@ -2582,7 +2582,7 @@ void chd_file_compressor::async_walk_parent(work_item &item) //------------------------------------------------- -// async_compress_hunk - handle asynchronous +// async_compress_hunk - handle asynchronous // hunk compression //------------------------------------------------- @@ -2615,7 +2615,7 @@ void chd_file_compressor::async_compress_hunk(work_item &item, int threadid) //------------------------------------------------- -// async_read - handle asynchronous source file +// async_read - handle asynchronous source file // reading //------------------------------------------------- @@ -2655,11 +2655,11 @@ void chd_file_compressor::async_read() curdest += hunk_bytes(); } } - + // otherwise, call the virtual function else read_data(dest, m_read_done_offset, numbytes); - + // spawn off work for each hunk for (UINT64 curoffs = m_read_done_offset; curoffs < end_offset; curoffs += hunk_bytes()) { @@ -2678,7 +2678,7 @@ void chd_file_compressor::async_read() m_compsha1.append(dest, numbytes); m_total_in += numbytes; } - + // advance the read pointer m_read_done_offset += numbytes; } @@ -2730,7 +2730,7 @@ void chd_file_compressor::hashmap::reset() delete block; } m_block_list->m_nextalloc = 0; - + // reset the hash memset(m_map, 0, sizeof(m_map)); } diff --git a/src/lib/util/chd.h b/src/lib/util/chd.h index 743d3774b93..4eb54371e09 100644 --- a/src/lib/util/chd.h +++ b/src/lib/util/chd.h @@ -55,7 +55,7 @@ Compressed Hunks of Data header format. All numbers are stored in Motorola (big-endian) byte ordering. - + ========================================================================= V1 header: @@ -78,15 +78,15 @@ 0x00000001 - set if this drive has a parent 0x00000002 - set if this drive allows writes - Compression types: - CHDCOMPRESSION_NONE = 0 - CHDCOMPRESSION_ZLIB = 1 - + Compression types: + CHDCOMPRESSION_NONE = 0 + CHDCOMPRESSION_ZLIB = 1 + V1 map format: - - [ 0] UINT64 offset : 44; // starting offset within the file - [ 0] UINT64 length : 20; // length of data; if == hunksize, data is uncompressed - + + [ 0] UINT64 offset : 44; // starting offset within the file + [ 0] UINT64 length : 20; // length of data; if == hunksize, data is uncompressed + ========================================================================= V2 header: @@ -105,9 +105,9 @@ [ 60] UINT8 parentmd5[16]; // MD5 checksum of parent file [ 76] UINT32 seclen; // number of bytes per sector [ 80] (V2 header length) - + Flags and map format are same as V1 - + ========================================================================= V3 header: @@ -126,21 +126,21 @@ [ 80] UINT8 sha1[20]; // SHA1 checksum of raw data [100] UINT8 parentsha1[20];// SHA1 checksum of parent file [120] (V3 header length) - + Flags are the same as V1 - Compression types: - CHDCOMPRESSION_NONE = 0 - CHDCOMPRESSION_ZLIB = 1 - CHDCOMPRESSION_ZLIB_PLUS = 2 - + Compression types: + CHDCOMPRESSION_NONE = 0 + CHDCOMPRESSION_ZLIB = 1 + CHDCOMPRESSION_ZLIB_PLUS = 2 + V3 map format: [ 0] UINT64 offset; // starting offset within the file - [ 8] UINT32 crc32; // 32-bit CRC of the uncompressed data - [ 12] UINT16 length_lo; // lower 16 bits of length - [ 14] UINT8 length_hi; // upper 8 bits of length - [ 15] UINT8 flags; // flags, indicating compression info + [ 8] UINT32 crc32; // 32-bit CRC of the uncompressed data + [ 12] UINT16 length_lo; // lower 16 bits of length + [ 14] UINT8 length_hi; // upper 8 bits of length + [ 15] UINT8 flags; // flags, indicating compression info ========================================================================= @@ -159,21 +159,21 @@ [ 68] UINT8 parentsha1[20];// combined raw+meta SHA1 of parent [ 88] UINT8 rawsha1[20]; // raw data SHA1 [108] (V4 header length) - + Flags are the same as V1 - - Compression types: - CHDCOMPRESSION_NONE = 0 - CHDCOMPRESSION_ZLIB = 1 - CHDCOMPRESSION_ZLIB_PLUS = 2 - CHDCOMPRESSION_AV = 3 - + + Compression types: + CHDCOMPRESSION_NONE = 0 + CHDCOMPRESSION_ZLIB = 1 + CHDCOMPRESSION_ZLIB_PLUS = 2 + CHDCOMPRESSION_AV = 3 + Map format is the same as V3 - + ========================================================================= V5 header: - + [ 0] char tag[8]; // 'MComprHD' [ 8] UINT32 length; // length of header (including tag and length fields) [ 12] UINT32 version; // drive format version @@ -188,30 +188,30 @@ [104] UINT8 parentsha1[20];// combined raw+meta SHA1 of parent [124] (V5 header length) - If parentsha1 != 0, we have a parent (no need for flags) - If compressors[0] == 0, we are uncompressed (including maps) - + If parentsha1 != 0, we have a parent (no need for flags) + If compressors[0] == 0, we are uncompressed (including maps) + V5 uncompressed map format: - - [ 0] UINT32 offset; // starting offset / hunk size - + + [ 0] UINT32 offset; // starting offset / hunk size + V5 compressed map format header: - - [ 0] UINT32 length; // length of compressed map - [ 4] UINT48 datastart; // offset of first block - [ 10] UINT16 crc; // crc-16 of the map - [ 12] UINT8 lengthbits; // bits used to encode complength - [ 13] UINT8 hunkbits; // bits used to encode self-refs - [ 14] UINT8 parentunitbits; // bits used to encode parent unit refs - [ 15] UINT8 reserved; // future use + + [ 0] UINT32 length; // length of compressed map + [ 4] UINT48 datastart; // offset of first block + [ 10] UINT16 crc; // crc-16 of the map + [ 12] UINT8 lengthbits; // bits used to encode complength + [ 13] UINT8 hunkbits; // bits used to encode self-refs + [ 14] UINT8 parentunitbits; // bits used to encode parent unit refs + [ 15] UINT8 reserved; // future use [ 16] (compressed header length) - + Each compressed map entry, once expanded, looks like: - - [ 0] UINT8 compression; // compression type - [ 1] UINT24 complength; // compressed length - [ 4] UINT48 offset; // offset - [ 10] UINT16 crc; // crc-16 of the data + + [ 0] UINT8 compression; // compression type + [ 1] UINT24 complength; // compressed length + [ 4] UINT48 offset; // offset + [ 10] UINT16 crc; // crc-16 of the data ***************************************************************************/ @@ -222,7 +222,7 @@ // pseudo-codecs returned by hunk_info const chd_codec_type CHD_CODEC_SELF = 1; // copy of another hunk -const chd_codec_type CHD_CODEC_PARENT = 2; // copy of a parent's hunk +const chd_codec_type CHD_CODEC_PARENT = 2; // copy of a parent's hunk const chd_codec_type CHD_CODEC_MINI = 3; // legacy "mini" 8-byte repeat // core types @@ -322,7 +322,7 @@ class chd_file static const UINT32 V4_HEADER_SIZE = 108; static const UINT32 V5_HEADER_SIZE = 124; static const UINT32 MAX_HEADER_SIZE = V5_HEADER_SIZE; - + public: // construction/destruction chd_file(); @@ -360,7 +360,7 @@ public: // file open chd_error open(const char *filename, bool writeable = false, chd_file *parent = NULL); chd_error open(core_file &file, bool writeable = false, chd_file *parent = NULL); - + // file close void close(); @@ -382,20 +382,20 @@ public: chd_error write_metadata(chd_metadata_tag metatag, UINT32 metaindex, const dynamic_buffer &input, UINT8 flags = CHD_MDFLAGS_CHECKSUM) { return write_metadata(metatag, metaindex, input, input.count(), flags = CHD_MDFLAGS_CHECKSUM); } chd_error delete_metadata(chd_metadata_tag metatag, UINT32 metaindex); chd_error clone_all_metadata(chd_file &source); - + // hashing helper sha1_t compute_overall_sha1(sha1_t rawsha1); // codec interfaces chd_error codec_configure(chd_codec_type codec, int param, void *config); - + // static helpers static const char *error_string(chd_error err); private: struct metadata_entry; struct metadata_hash; - + // inline helpers UINT64 be_read(const UINT8 *base, int numbytes); void be_write(UINT8 *base, UINT64 value, int numbytes); @@ -430,7 +430,7 @@ private: bool m_owns_file; // flag indicating if this file should be closed on chd_close() bool m_allow_reads; // permit reads from this CHD? bool m_allow_writes; // permit writes to this CHD? - + // core parameters from the header UINT32 m_version; // version of the header UINT64 m_logicalbytes; // logical size of the raw CHD data in bytes @@ -443,14 +443,14 @@ private: chd_codec_type m_compression[4]; // array of compression types used chd_file * m_parent; // pointer to parent file, or NULL if none bool m_parent_missing; // are we missing our parent? - + // key offsets within the header UINT64 m_mapoffset_offset; // offset of map offset field UINT64 m_metaoffset_offset;// offset of metaoffset field UINT64 m_sha1_offset; // offset of SHA1 field UINT64 m_rawsha1_offset; // offset of raw SHA1 field UINT64 m_parentsha1_offset;// offset of paren SHA1 field - + // map information UINT32 m_mapentrybytes; // length of each entry in a map dynamic_buffer m_rawmap; // raw map data @@ -458,7 +458,7 @@ private: // compression management chd_decompressor * m_decompressor[4]; // array of decompression codecs dynamic_buffer m_compressed; // temporary buffer for compressed data - + // caching dynamic_buffer m_cache; // single-hunk cache for partial reads/writes UINT32 m_cachehunk; // which hunk is in the cache? @@ -474,7 +474,7 @@ public: // construction/destruction chd_file_compressor(); virtual ~chd_file_compressor(); - + // compression management void compress_begin(); chd_error compress_continue(double &progress, double &ratio); @@ -482,7 +482,7 @@ public: protected: // required override: read more data virtual UINT32 read_data(void *dest, UINT64 offset, UINT32 length) = 0; - + private: // hash map for looking up values class hashmap @@ -491,12 +491,12 @@ private: // construction/destruction hashmap(); ~hashmap(); - + // operations void reset(); UINT64 find(crc16_t crc16, sha1_t sha1); void add(UINT64 itemnum, crc16_t crc16, sha1_t sha1); - + // constants static const UINT64 NOT_FOUND = ~UINT64(0); private: @@ -507,13 +507,13 @@ private: UINT64 m_itemnum; // item number sha1_t m_sha1; // SHA-1 of the block }; - + // block of entries struct entry_block { entry_block(entry_block *prev) : m_next(prev), m_nextalloc(0) { } - + entry_block * m_next; // next block in list UINT32 m_nextalloc; // next to be allocated entry_t m_array[16384]; // array of entries @@ -532,7 +532,7 @@ private: WS_QUEUED, WS_COMPLETE }; - + // a CRC-16/SHA-1 pair struct hash_pair { @@ -540,7 +540,7 @@ private: sha1_t m_sha1; // calculated SHA-1 }; - // a single work item + // a single work item struct work_item { osd_work_item * m_osd; // OSD work item running on this block @@ -554,7 +554,7 @@ private: chd_compressor_group *m_codecs; // codec instance dynamic_array<hash_pair> m_hash; // array of hashes }; - + // internal helpers static void *async_walk_parent_static(void *param, int threadid); void async_walk_parent(work_item &item); @@ -563,15 +563,15 @@ private: static void *async_read_static(void *param, int threadid); void async_read(); - // current compression status - bool m_walking_parent; // are we building the parent map? + // current compression status + bool m_walking_parent; // are we building the parent map? UINT64 m_total_in; // total bytes in UINT64 m_total_out; // total bytes out sha1_creator m_compsha1; // running SHA-1 on raw data // hash lookup maps - hashmap m_parent_map; // hash map for parent - hashmap m_current_map; // hash map for current + hashmap m_parent_map; // hash map for parent + hashmap m_current_map; // hash map for current // read I/O thread osd_work_queue * m_read_queue; // work queue for reading diff --git a/src/lib/util/chdcodec.c b/src/lib/util/chdcodec.c index 19c7f14b0cf..45c1727d629 100644 --- a/src/lib/util/chdcodec.c +++ b/src/lib/util/chdcodec.c @@ -64,7 +64,7 @@ public: // construction/destruction chd_zlib_allocator(); ~chd_zlib_allocator(); - + // installation void install(z_stream &stream); @@ -150,7 +150,7 @@ public: // core functionality virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest); - + // helpers static void configure_properties(CLzmaEncProps &props, chd_file &chd); @@ -346,7 +346,7 @@ class chd_avhuff_compressor : public chd_compressor public: // construction/destruction chd_avhuff_compressor(chd_file &chd, bool lossy); - + // core functionality virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest); @@ -368,7 +368,7 @@ class chd_avhuff_decompressor : public chd_decompressor public: // construction/destruction chd_avhuff_decompressor(chd_file &chd, bool lossy); - + // core functionality virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen); virtual void configure(int param, void *config); @@ -420,7 +420,7 @@ chd_codec::chd_codec(chd_file &file, bool lossy) chd_codec::~chd_codec() { } - + //------------------------------------------------- // configure - configuration @@ -597,7 +597,7 @@ INT8 chd_compressor_group::find_best_compressor(const UINT8 *src, UINT8 *compres catch (...) { } - + if (memcmp(src, m_decompressed, m_hunkbytes) != 0) { compbytes = m_compressor[codecnum]->compress(src, m_hunkbytes, m_compress_test); @@ -621,13 +621,13 @@ printf(" codec%d=%d bytes \n", codecnum, compbytes); } catch (...) { } } - + // if the best is none, copy it over if (compression == -1) memcpy(compressed, src, m_hunkbytes); return compression; } - + //************************************************************************** @@ -832,7 +832,7 @@ chd_zlib_decompressor::~chd_zlib_decompressor() //------------------------------------------------- -// decompress - decompress data using the ZLIB +// decompress - decompress data using the ZLIB // codec //------------------------------------------------- @@ -869,7 +869,7 @@ chd_lzma_allocator::chd_lzma_allocator() { // reset pointer list memset(m_allocptr, 0, sizeof(m_allocptr)); - + // set our pointers Alloc = &chd_lzma_allocator::fast_alloc; Free = &chd_lzma_allocator::fast_free; @@ -936,7 +936,7 @@ void chd_lzma_allocator::fast_free(void *p, void *address) { if (address == NULL) return; - + chd_lzma_allocator *codec = reinterpret_cast<chd_lzma_allocator *>(p); // find the hunk @@ -994,7 +994,7 @@ UINT32 chd_lzma_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *des SRes res = LzmaEnc_SetProps(encoder, &m_props); if (res != SZ_OK) throw CHDERR_COMPRESSION_ERROR; - + // run it SizeT complen = srclen; res = LzmaEnc_MemEncode(encoder, dest, &complen, src, srclen, 0, NULL, &m_allocator, &m_allocator); @@ -1046,14 +1046,14 @@ chd_lzma_decompressor::chd_lzma_decompressor(chd_file &chd, bool lossy) // configure the properties like the compressor did CLzmaEncProps encoder_props; chd_lzma_compressor::configure_properties(encoder_props, chd); - + // convert to decoder properties CLzmaProps decoder_props; decoder_props.lc = encoder_props.lc; decoder_props.lp = encoder_props.lp; decoder_props.pb = encoder_props.pb; decoder_props.dicSize = encoder_props.dictSize; - + // do memory allocations SRes res = LzmaDec_Allocate_MAME(&m_decoder, &decoder_props, &m_allocator); if (res != SZ_OK) @@ -1073,7 +1073,7 @@ chd_lzma_decompressor::~chd_lzma_decompressor() //------------------------------------------------- -// decompress - decompress data using the LZMA +// decompress - decompress data using the LZMA // codec //------------------------------------------------- @@ -1081,7 +1081,7 @@ void chd_lzma_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT8 * { // initialize LzmaDec_Init(&m_decoder); - + // decode SizeT consumedlen = complen; SizeT decodedlen = destlen; @@ -1108,7 +1108,7 @@ chd_huffman_compressor::chd_huffman_compressor(chd_file &chd, bool lossy) //------------------------------------------------- -// compress - compress data using the Huffman +// compress - compress data using the Huffman // codec //------------------------------------------------- @@ -1137,7 +1137,7 @@ chd_huffman_decompressor::chd_huffman_decompressor(chd_file &chd, bool lossy) //------------------------------------------------- -// decompress - decompress data using the Huffman +// decompress - decompress data using the Huffman // codec //------------------------------------------------- @@ -1167,7 +1167,7 @@ chd_flac_compressor::chd_flac_compressor(chd_file &chd, bool lossy, bool bigendi m_swap_endian = bigendian; else m_swap_endian = !bigendian; - + // configure the encoder m_encoder.set_sample_rate(44100); m_encoder.set_num_channels(2); @@ -1218,7 +1218,7 @@ chd_flac_decompressor::chd_flac_decompressor(chd_file &chd, bool lossy, bool big //------------------------------------------------- -// decompress - decompress data using the FLAC +// decompress - decompress data using the FLAC // codec //------------------------------------------------- @@ -1256,7 +1256,7 @@ chd_cd_flac_compressor::chd_cd_flac_compressor(chd_file &chd, bool lossy) UINT16 native_endian = 0; *reinterpret_cast<UINT8 *>(&native_endian) = 1; m_swap_endian = (native_endian == 1); - + // configure the encoder m_encoder.set_sample_rate(44100); m_encoder.set_num_channels(2); @@ -1310,7 +1310,7 @@ UINT32 chd_cd_flac_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 * // finish up UINT32 complen = m_encoder.finish(); - + // deflate the subcode data m_deflater.next_in = const_cast<Bytef *>(&m_buffer[frames * CD_MAX_SECTOR_DATA]); m_deflater.avail_in = frames * CD_MAX_SUBCODE_DATA; @@ -1380,7 +1380,7 @@ chd_cd_flac_decompressor::~chd_cd_flac_decompressor() //------------------------------------------------- -// decompress - decompress data using the FLAC +// decompress - decompress data using the FLAC // codec //------------------------------------------------- @@ -1410,7 +1410,7 @@ void chd_cd_flac_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT zerr = inflate(&m_inflater, Z_FINISH); if (m_inflater.total_out != frames * CD_MAX_SUBCODE_DATA) throw CHDERR_DECOMPRESSION_ERROR; - + // reassemble the data for (UINT32 framenum = 0; framenum < frames; framenum++) { @@ -1474,8 +1474,8 @@ UINT32 chd_avhuff_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *d //------------------------------------------------- -// postinit - actual initialization of avhuff -// happens here, on the first attempt to compress +// postinit - actual initialization of avhuff +// happens here, on the first attempt to compress // or decompress data //------------------------------------------------- @@ -1520,7 +1520,7 @@ chd_avhuff_decompressor::chd_avhuff_decompressor(chd_file &chd, bool lossy) //------------------------------------------------- -// decompress - decompress data using the A/V +// decompress - decompress data using the A/V // codec //------------------------------------------------- @@ -1542,7 +1542,7 @@ void chd_avhuff_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT8 //------------------------------------------------- -// config - codec-specific configuration for the +// config - codec-specific configuration for the // A/V codec //------------------------------------------------- @@ -1551,7 +1551,7 @@ void chd_avhuff_decompressor::configure(int param, void *config) // if we're getting the decompression configuration, apply it now if (param == AVHUFF_CODEC_DECOMPRESS_CONFIG) m_decoder.configure(*reinterpret_cast<avhuff_decompress_config *>(config)); - + // anything else is invalid else throw CHDERR_INVALID_PARAMETER; diff --git a/src/lib/util/chdcodec.h b/src/lib/util/chdcodec.h index 1d63c6966be..4f7c7918df5 100644 --- a/src/lib/util/chdcodec.h +++ b/src/lib/util/chdcodec.h @@ -75,7 +75,7 @@ class chd_codec protected: // can't create these directly chd_codec(chd_file &file, bool lossy); - + public: // allow public deletion virtual ~chd_codec(); @@ -133,7 +133,7 @@ public: // create compressors or decompressors static chd_compressor *new_compressor(chd_codec_type type, chd_file &file); static chd_decompressor *new_decompressor(chd_codec_type type, chd_file &file); - + // utilities static bool codec_exists(chd_codec_type type) { return (find_in_list(type) != NULL); } static const char *codec_name(chd_codec_type type); @@ -151,7 +151,7 @@ private: // internal helper functions static const codec_entry *find_in_list(chd_codec_type type); - + template<class _CompressorClass> static chd_compressor *construct_compressor(chd_file &chd, bool lossy) { return new _CompressorClass(chd, lossy); } @@ -172,10 +172,10 @@ public: // construction/destruction chd_compressor_group(chd_file &file, chd_codec_type compressor_list[4]); ~chd_compressor_group(); - + // find the best compressor INT8 find_best_compressor(const UINT8 *src, UINT8 *compressed, UINT32 &complen); - + private: // internal state UINT32 m_hunkbytes; // number of bytes in a hunk @@ -197,10 +197,10 @@ private: const chd_codec_type CHD_CODEC_NONE = 0; const chd_codec_type CHD_CODEC_ZLIB = CHD_MAKE_TAG('z','l','i','b'); const chd_codec_type CHD_CODEC_LZMA = CHD_MAKE_TAG('l','z','m','a'); -const chd_codec_type CHD_CODEC_HUFFMAN = CHD_MAKE_TAG('h','u','f','f'); -const chd_codec_type CHD_CODEC_FLAC_BE = CHD_MAKE_TAG('f','l','c','b'); -const chd_codec_type CHD_CODEC_FLAC_LE = CHD_MAKE_TAG('f','l','c','l'); -const chd_codec_type CHD_CODEC_CD_FLAC = CHD_MAKE_TAG('c','d','f','l'); +const chd_codec_type CHD_CODEC_HUFFMAN = CHD_MAKE_TAG('h','u','f','f'); +const chd_codec_type CHD_CODEC_FLAC_BE = CHD_MAKE_TAG('f','l','c','b'); +const chd_codec_type CHD_CODEC_FLAC_LE = CHD_MAKE_TAG('f','l','c','l'); +const chd_codec_type CHD_CODEC_CD_FLAC = CHD_MAKE_TAG('c','d','f','l'); const chd_codec_type CHD_CODEC_AVHUFF = CHD_MAKE_TAG('a','v','h','u'); // A/V codec configuration parameters diff --git a/src/lib/util/coretmpl.h b/src/lib/util/coretmpl.h index 59e012fe753..7daee5eadff 100644 --- a/src/lib/util/coretmpl.h +++ b/src/lib/util/coretmpl.h @@ -59,7 +59,7 @@ private: public: // construction/destruction - dynamic_array(int initial = 0) + dynamic_array(int initial = 0) : m_array(NULL), m_count(0), m_allocated(0) { if (initial != 0) expand_internal(initial); m_count = initial; } @@ -73,7 +73,7 @@ public: // simple getters int count() const { return m_count; } - + // helpers void append(const _ElementType &element) { if (m_count == m_allocated) expand_internal((m_allocated == 0) ? 16 : (m_allocated << 1), true); m_array[m_count++] = element; } void reset() { delete[] m_array; m_array = NULL; m_count = m_allocated = 0; } diff --git a/src/lib/util/flac.c b/src/lib/util/flac.c index 99c73a11ff5..817e39047d9 100644 --- a/src/lib/util/flac.c +++ b/src/lib/util/flac.c @@ -82,7 +82,7 @@ flac_encoder::~flac_encoder() //------------------------------------------------- -// reset - reset state with the original +// reset - reset state with the original // parameters //------------------------------------------------- @@ -96,7 +96,7 @@ bool flac_encoder::reset() // configure the encoder in a standard way // note we do this on each reset; if we don't, results are NOT consistent! FLAC__stream_encoder_set_verify(m_encoder, false); -// FLAC__stream_encoder_set_do_md5(m_encoder, false); +// FLAC__stream_encoder_set_do_md5(m_encoder, false); FLAC__stream_encoder_set_compression_level(m_encoder, 8); FLAC__stream_encoder_set_channels(m_encoder, m_channels); FLAC__stream_encoder_set_bits_per_sample(m_encoder, 16); @@ -161,7 +161,7 @@ bool flac_encoder::encode_interleaved(const INT16 *samples, UINT32 samples_per_c for (UINT32 sampnum = 0; sampnum < cur_samples; sampnum++) for (int channel = 0; channel < num_channels; channel++, srcindex++) *dest++ = INT16((UINT16(samples[srcindex]) << shift) | (UINT16(samples[srcindex]) >> shift)); - + // process this batch if (!FLAC__stream_encoder_process_interleaved(m_encoder, converted_buffer, cur_samples)) return false; @@ -194,7 +194,7 @@ bool flac_encoder::encode(INT16 *const *samples, UINT32 samples_per_channel, boo for (UINT32 sampnum = 0; sampnum < cur_samples; sampnum++, srcindex++) for (int channel = 0; channel < num_channels; channel++) *dest++ = INT16((UINT16(samples[channel][srcindex]) << shift) | (UINT16(samples[channel][srcindex]) >> shift)); - + // process this batch if (!FLAC__stream_encoder_process_interleaved(m_encoder, converted_buffer, cur_samples)) return false; @@ -205,7 +205,7 @@ bool flac_encoder::encode(INT16 *const *samples, UINT32 samples_per_channel, boo //------------------------------------------------- -// finish - complete encoding and flush the +// finish - complete encoding and flush the // stream //------------------------------------------------- @@ -227,7 +227,7 @@ void flac_encoder::init_common() m_encoder = FLAC__stream_encoder_new(); if (m_encoder == NULL) throw std::bad_alloc(); - + // initialize default state m_file = NULL; m_compressed_offset = 0; @@ -243,7 +243,7 @@ void flac_encoder::init_common() //------------------------------------------------- -// write_callback - handle writes to the +// write_callback - handle writes to the // output stream //------------------------------------------------- @@ -265,7 +265,7 @@ FLAC__StreamEncoderWriteStatus flac_encoder::write_callback(const FLAC__byte buf offset += ignore; m_ignore_bytes -= ignore; } - + // if we haven't hit the end of metadata, process a new piece else if (!m_found_audio) { @@ -275,7 +275,7 @@ FLAC__StreamEncoderWriteStatus flac_encoder::write_callback(const FLAC__byte buf offset += 4; } - // otherwise process as audio data and copy to the output + // otherwise process as audio data and copy to the output else { int count = bytes - offset; @@ -360,21 +360,21 @@ flac_decoder::~flac_decoder() //------------------------------------------------- -// reset - reset state with the original +// reset - reset state with the original // parameters //------------------------------------------------- bool flac_decoder::reset() { m_compressed_offset = 0; - if (FLAC__stream_decoder_init_stream(m_decoder, - &flac_decoder::read_callback_static, - NULL, - &flac_decoder::tell_callback_static, - NULL, - NULL, - &flac_decoder::write_callback_static, - &flac_decoder::metadata_callback_static, + if (FLAC__stream_decoder_init_stream(m_decoder, + &flac_decoder::read_callback_static, + NULL, + &flac_decoder::tell_callback_static, + NULL, + NULL, + &flac_decoder::write_callback_static, + &flac_decoder::metadata_callback_static, &flac_decoder::error_callback_static, this) != FLAC__STREAM_DECODER_INIT_STATUS_OK) return false; return FLAC__stream_decoder_process_until_end_of_metadata(m_decoder); @@ -407,15 +407,15 @@ bool flac_decoder::reset(UINT32 sample_rate, UINT8 num_channels, UINT32 block_si static const UINT8 s_header_template[0x2a] = { 0x66, 0x4C, 0x61, 0x43, // +00: 'fLaC' stream header - 0x80, // +04: metadata block type 0 (STREAMINFO), + 0x80, // +04: metadata block type 0 (STREAMINFO), // flagged as last block - 0x00, 0x00, 0x22, // +05: metadata block length = 0x22 + 0x00, 0x00, 0x22, // +05: metadata block length = 0x22 0x00, 0x00, // +08: minimum block size 0x00, 0x00, // +0A: maximum block size - 0x00, 0x00, 0x00, // +0C: minimum frame size (0 == unknown) - 0x00, 0x00, 0x00, // +0F: maximum frame size (0 == unknown) - 0x0A, 0xC4, 0x42, 0xF0, 0x00, 0x00, 0x00, 0x00, // +12: sample rate (0x0ac44 == 44100), - // numchannels (2), sample bits (16), + 0x00, 0x00, 0x00, // +0C: minimum frame size (0 == unknown) + 0x00, 0x00, 0x00, // +0F: maximum frame size (0 == unknown) + 0x0A, 0xC4, 0x42, 0xF0, 0x00, 0x00, 0x00, 0x00, // +12: sample rate (0x0ac44 == 44100), + // numchannels (2), sample bits (16), // samples in stream (0 == unknown) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // +1A: MD5 signature (0 == none) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // @@ -466,7 +466,7 @@ bool flac_decoder::decode_interleaved(INT16 *samples, UINT32 num_samples, bool s m_uncompressed_offset = 0; m_uncompressed_length = num_samples; m_uncompressed_swap = swap_endian; - + // loop until we get everything we want while (m_uncompressed_offset < m_uncompressed_length) if (!FLAC__stream_decoder_process_single(m_decoder)) @@ -494,7 +494,7 @@ bool flac_decoder::decode(INT16 **samples, UINT32 num_samples, bool swap_endian) m_uncompressed_offset = 0; m_uncompressed_length = num_samples; m_uncompressed_swap = swap_endian; - + // loop until we get everything we want while (m_uncompressed_offset < m_uncompressed_length) if (!FLAC__stream_decoder_process_single(m_decoder)) @@ -513,7 +513,7 @@ UINT32 flac_decoder::finish() FLAC__uint64 position = 0; FLAC__stream_decoder_get_decode_position(m_decoder, &position); FLAC__stream_decoder_finish(m_decoder); - + // adjust position if we provided the header if (position == 0) return 0; @@ -536,11 +536,11 @@ FLAC__StreamDecoderReadStatus flac_decoder::read_callback_static(const FLAC__Str FLAC__StreamDecoderReadStatus flac_decoder::read_callback(FLAC__byte buffer[], size_t *bytes) { UINT32 expected = *bytes; - + // if a file, just read if (m_file != NULL) *bytes = core_fread(m_file, buffer, expected); - + // otherwise, copy from memory else { @@ -553,7 +553,7 @@ FLAC__StreamDecoderReadStatus flac_decoder::read_callback(FLAC__byte buffer[], s outputpos += bytes_to_copy; m_compressed_offset += bytes_to_copy; } - + // once we're out of that, copy from the secondary buffer if (outputpos < *bytes && m_compressed_offset < m_compressed_length + m_compressed2_length) { @@ -579,7 +579,7 @@ void flac_decoder::metadata_callback_static(const FLAC__StreamDecoder *decoder, // ignore all but STREAMINFO metadata if (metadata->type != FLAC__METADATA_TYPE_STREAMINFO) return; - + // parse out the data we care about flac_decoder *fldecoder = reinterpret_cast<flac_decoder *>(client_data); fldecoder->m_sample_rate = metadata->data.stream_info.sample_rate; @@ -613,7 +613,7 @@ FLAC__StreamDecoderWriteStatus flac_decoder::write_callback_static(const FLAC__S FLAC__StreamDecoderWriteStatus flac_decoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) { assert(frame->header.channels == channels()); - + // interleaved case int shift = m_uncompressed_swap ? 8 : 0; int blocksize = frame->header.blocksize; @@ -624,7 +624,7 @@ FLAC__StreamDecoderWriteStatus flac_decoder::write_callback(const ::FLAC__Frame for (int chan = 0; chan < frame->header.channels; chan++) *dest++ = INT16((UINT16(buffer[chan][sampnum]) << shift) | (UINT16(buffer[chan][sampnum]) >> shift)); } - + // non-interleaved case else { diff --git a/src/lib/util/flac.h b/src/lib/util/flac.h index add4e506525..911b7269424 100644 --- a/src/lib/util/flac.h +++ b/src/lib/util/flac.h @@ -67,16 +67,16 @@ public: void set_num_channels(UINT8 num_channels) { m_channels = num_channels; } void set_block_size(UINT32 block_size) { m_block_size = block_size; } void set_strip_metadata(bool strip) { m_strip_metadata = strip; } - + // getters (valid after reset) FLAC__StreamEncoderState state() const { return FLAC__stream_encoder_get_state(m_encoder); } const char *state_string() const { return FLAC__stream_encoder_get_resolved_state_string(m_encoder); } - + // reset bool reset(); bool reset(void *buffer, UINT32 buflength); bool reset(core_file &file); - + // encode a buffer bool encode_interleaved(const INT16 *samples, UINT32 samples_per_channel, bool swap_endian = false); bool encode(INT16 *const *samples, UINT32 samples_per_channel, bool swap_endian = false); @@ -96,14 +96,14 @@ private: UINT32 m_compressed_offset; // current offset with the compressed stream FLAC__byte * m_compressed_start; // start of compressed data UINT32 m_compressed_length; // length of the compressed stream - + // parameters UINT32 m_sample_rate; // sample rate UINT8 m_channels; // number of channels UINT32 m_block_size; // block size // header stripping - bool m_strip_metadata; // strip the the metadata? + bool m_strip_metadata; // strip the the metadata? UINT32 m_ignore_bytes; // how many bytes to ignore when writing bool m_found_audio; // have we hit the audio yet? }; @@ -119,7 +119,7 @@ public: flac_decoder(const void *buffer, UINT32 length, const void *buffer2 = NULL, UINT32 length2 = 0); flac_decoder(core_file &file); ~flac_decoder(); - + // getters (valid after reset) UINT32 sample_rate() const { return m_sample_rate; } UINT8 channels() const { return m_channels; } @@ -127,13 +127,13 @@ public: UINT32 total_samples() const { return FLAC__stream_decoder_get_total_samples(m_decoder); } FLAC__StreamDecoderState state() const { return FLAC__stream_decoder_get_state(m_decoder); } const char *state_string() const { return FLAC__stream_decoder_get_resolved_state_string(m_decoder); } - + // reset bool reset(); bool reset(const void *buffer, UINT32 length, const void *buffer2 = NULL, UINT32 length2 = 0); bool reset(UINT32 sample_rate, UINT8 num_channels, UINT32 block_size, const void *buffer, UINT32 length); bool reset(core_file &file); - + // decode to a buffer; num_samples must be a multiple of the block size bool decode_interleaved(INT16 *samples, UINT32 num_samples, bool swap_endian = false); bool decode(INT16 **samples, UINT32 num_samples, bool swap_endian = false); diff --git a/src/lib/util/hashing.c b/src/lib/util/hashing.c index 3935438bfcb..a1e3112adc6 100644 --- a/src/lib/util/hashing.c +++ b/src/lib/util/hashing.c @@ -1,39 +1,39 @@ /*************************************************************************** - hashing.c + hashing.c - Hashing helper classes. + Hashing helper classes. **************************************************************************** - Copyright Aaron Giles - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - * Neither the name 'MAME' nor the names of its contributors may be - used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. + Copyright Aaron Giles + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name 'MAME' nor the names of its contributors may be + used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. ***************************************************************************/ @@ -57,7 +57,7 @@ const sha1_t sha1_t::null = { { 0 } }; //************************************************************************** //------------------------------------------------- -// char_to_hex - return the hex value of a +// char_to_hex - return the hex value of a // character //------------------------------------------------- @@ -89,7 +89,7 @@ bool sha1_t::from_string(const char *string, int length) length = strlen(string); if (length < 2 * sizeof(m_raw)) return false; - + // iterate through our raw buffer for (int bytenum = 0; bytenum < sizeof(m_raw); bytenum++) { @@ -111,7 +111,7 @@ const char *sha1_t::as_string(astring &buffer) const { buffer.reset(); for (int i = 0; i < ARRAY_LENGTH(m_raw); i++) - buffer.catformat("%02x", m_raw[i]); + buffer.catformat("%02x", m_raw[i]); return buffer; } @@ -131,7 +131,7 @@ bool md5_t::from_string(const char *string, int length) length = strlen(string); if (length < 2 * sizeof(m_raw)) return false; - + // iterate through our raw buffer for (int bytenum = 0; bytenum < sizeof(m_raw); bytenum++) { @@ -153,7 +153,7 @@ const char *md5_t::as_string(astring &buffer) const { buffer.reset(); for (int i = 0; i < ARRAY_LENGTH(m_raw); i++) - buffer.catformat("%02x", m_raw[i]); + buffer.catformat("%02x", m_raw[i]); return buffer; } @@ -174,7 +174,7 @@ bool crc32_t::from_string(const char *string, int length) length = strlen(string); if (length < 2 * sizeof(m_raw)) return false; - + // iterate through our raw buffer m_raw = 0; for (int bytenum = 0; bytenum < sizeof(m_raw) * 2; bytenum++) @@ -199,7 +199,7 @@ const char *crc32_t::as_string(astring &buffer) const //------------------------------------------------- -// append - hash a block of data, appending to +// append - hash a block of data, appending to // the currently-accumulated value //------------------------------------------------- @@ -225,7 +225,7 @@ bool crc16_t::from_string(const char *string, int length) length = strlen(string); if (length < 2 * sizeof(m_raw)) return false; - + // iterate through our raw buffer m_raw = 0; for (int bytenum = 0; bytenum < sizeof(m_raw) * 2; bytenum++) @@ -250,13 +250,13 @@ const char *crc16_t::as_string(astring &buffer) const //------------------------------------------------- -// append - hash a block of data, appending to +// append - hash a block of data, appending to // the currently-accumulated value //------------------------------------------------- void crc16_creator::append(const void *data, UINT32 length) { - static const UINT16 s_table[256] = + static const UINT16 s_table[256] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, @@ -293,7 +293,7 @@ void crc16_creator::append(const void *data, UINT32 length) }; const UINT8 *src = reinterpret_cast<const UINT8 *>(data); - + // fetch the current value into a local and rip through the source data UINT16 crc = m_accum.m_raw; while (length-- != 0) diff --git a/src/lib/util/hashing.h b/src/lib/util/hashing.h index b3976a46415..cebaba95b18 100644 --- a/src/lib/util/hashing.h +++ b/src/lib/util/hashing.h @@ -1,39 +1,39 @@ /*************************************************************************** - hashing.h + hashing.h - Hashing helper classes. + Hashing helper classes. **************************************************************************** - Copyright Aaron Giles - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are - met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - * Neither the name 'MAME' nor the names of its contributors may be - used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. + Copyright Aaron Giles + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name 'MAME' nor the names of its contributors may be + used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. ***************************************************************************/ @@ -73,13 +73,13 @@ class sha1_creator public: // construction/destruction sha1_creator() { reset(); } - + // reset void reset() { sha1_init(&m_context); } - + // append data void append(const void *data, UINT32 length) { sha1_update(&m_context, length, reinterpret_cast<const UINT8 *>(data)); } - + // finalize and compute the final digest sha1_t finish() { @@ -92,8 +92,8 @@ public: // static wrapper to just get the digest from a block static sha1_t simple(const void *data, UINT32 length) { - sha1_creator creator; - creator.append(data, length); + sha1_creator creator; + creator.append(data, length); return creator.finish(); } @@ -124,13 +124,13 @@ class md5_creator public: // construction/destruction md5_creator() { reset(); } - + // reset void reset() { MD5Init(&m_context); } - + // append data void append(const void *data, UINT32 length) { MD5Update(&m_context, reinterpret_cast<const unsigned char *>(data), length); } - + // finalize and compute the final digest md5_t finish() { @@ -142,14 +142,14 @@ public: // static wrapper to just get the digest from a block static md5_t simple(const void *data, UINT32 length) { - md5_creator creator; - creator.append(data, length); + md5_creator creator; + creator.append(data, length); return creator.finish(); } protected: // internal state - struct MD5Context m_context; // internal context + struct MD5Context m_context; // internal context }; @@ -175,21 +175,21 @@ class crc32_creator public: // construction/destruction crc32_creator() { reset(); } - + // reset void reset() { m_accum.m_raw = 0; } - + // append data void append(const void *data, UINT32 length); - + // finalize and compute the final digest crc32_t finish() { return m_accum; } // static wrapper to just get the digest from a block static crc32_t simple(const void *data, UINT32 length) { - crc32_creator creator; - creator.append(data, length); + crc32_creator creator; + creator.append(data, length); return creator.finish(); } @@ -221,21 +221,21 @@ class crc16_creator public: // construction/destruction crc16_creator() { reset(); } - + // reset void reset() { m_accum.m_raw = 0xffff; } - + // append data void append(const void *data, UINT32 length); - + // finalize and compute the final digest crc16_t finish() { return m_accum; } // static wrapper to just get the digest from a block static crc16_t simple(const void *data, UINT32 length) { - crc16_creator creator; - creator.append(data, length); + crc16_creator creator; + creator.append(data, length); return creator.finish(); } diff --git a/src/lib/util/huffman.c b/src/lib/util/huffman.c index b672a7a0d89..21ef7adc029 100644 --- a/src/lib/util/huffman.c +++ b/src/lib/util/huffman.c @@ -165,7 +165,7 @@ huffman_context_base::huffman_context_base(int numcodes, int maxbits, lookup_val //------------------------------------------------- -// import_tree_rle - import an RLE-encoded +// import_tree_rle - import an RLE-encoded // huffman tree from a source data stream //------------------------------------------------- @@ -215,7 +215,7 @@ huffman_error huffman_context_base::import_tree_rle(bitstream_in &bitbuf) huffman_error error = assign_canonical_codes(); if (error != HUFFERR_NONE) return error; - + // build the lookup table build_lookup_table(); @@ -267,7 +267,7 @@ huffman_error huffman_context_base::export_tree_rle(bitstream_out &bitbuf) //------------------------------------------------- -// import_tree_huffman - import a huffman-encoded +// import_tree_huffman - import a huffman-encoded // huffman tree from a source data stream //------------------------------------------------- @@ -288,13 +288,13 @@ huffman_error huffman_context_base::import_tree_huffman(bitstream_in &bitbuf) smallhuff.m_huffnode[index].m_numbits = (count == 7) ? 0 : count; } } - + // then regenerate the tree huffman_error error = smallhuff.assign_canonical_codes(); if (error != HUFFERR_NONE) return error; smallhuff.build_lookup_table(); - + // determine the maximum length of an RLE count UINT32 temp = m_numcodes - 9; UINT8 rlefullbits = 0; @@ -337,7 +337,7 @@ huffman_error huffman_context_base::import_tree_huffman(bitstream_in &bitbuf) //------------------------------------------------- -// export_tree_huffman - export a huffman tree to +// export_tree_huffman - export a huffman tree to // a huffman target data stream //------------------------------------------------- @@ -350,7 +350,7 @@ huffman_error huffman_context_base::export_tree_huffman(bitstream_out &bitbuf) UINT16 *lengths = rle_lengths; int last = ~0; int repcount = 0; - + // use a small huffman context to create a tree (ignoring RLE lengths) huffman_encoder<24, 6> smallhuff; @@ -363,14 +363,14 @@ huffman_error huffman_context_base::export_tree_huffman(bitstream_out &bitbuf) { if (repcount == 1) smallhuff.histo_one(*dest++ = last + 1); - else + else smallhuff.histo_one(*dest++ = 0), *lengths++ = repcount - 2; } - + // if same as last, just track repeats if (newval == last) repcount++; - + // otherwise, write it and start a new run else { @@ -385,7 +385,7 @@ huffman_error huffman_context_base::export_tree_huffman(bitstream_out &bitbuf) { if (repcount == 1) smallhuff.histo_one(*dest++ = last + 1); - else + else smallhuff.histo_one(*dest++ = 0), *lengths++ = repcount - 2; } @@ -413,7 +413,7 @@ huffman_error huffman_context_base::export_tree_huffman(bitstream_out &bitbuf) for (int index = first_non_zero; index <= last_non_zero; index++) bitbuf.write(smallhuff.m_huffnode[index].m_numbits, 3); bitbuf.write(7, 3); - + // determine the maximum length of an RLE count UINT32 temp = m_numcodes - 9; UINT8 rlefullbits = 0; @@ -427,7 +427,7 @@ huffman_error huffman_context_base::export_tree_huffman(bitstream_out &bitbuf) // encode the data UINT8 data = *src; smallhuff.encode_one(bitbuf, data); - + // if this is an RLE token, encode the length following if (data == 0) { @@ -438,7 +438,7 @@ huffman_error huffman_context_base::export_tree_huffman(bitstream_out &bitbuf) bitbuf.write(7, 3), bitbuf.write(count - 7, rlefullbits); } } - + // flush the final buffer return bitbuf.overflow() ? HUFFERR_OUTPUT_BUFFER_TOO_SMALL : HUFFERR_NONE; } @@ -540,7 +540,7 @@ int CLIB_DECL huffman_context_base::tree_node_compare(const void *item1, const v //------------------------------------------------- -// build_tree - build a huffman tree based on the +// build_tree - build a huffman tree based on the // data distribution //------------------------------------------------- @@ -616,8 +616,8 @@ int huffman_context_base::build_tree(UINT32 totaldata, UINT32 totalweight) //------------------------------------------------- -// assign_canonical_codes - assign canonical codes -// to all the nodes based on the number of bits +// assign_canonical_codes - assign canonical codes +// to all the nodes based on the number of bits // in each //------------------------------------------------- @@ -696,7 +696,7 @@ void huffman_context_base::build_lookup_table() huffman_8bit_encoder::huffman_8bit_encoder() { } - + //------------------------------------------------- // encode - encode a full buffer @@ -713,13 +713,13 @@ huffman_error huffman_8bit_encoder::encode(const UINT8 *source, UINT32 slength, huffman_error err = compute_tree_from_histo(); if (err != HUFFERR_NONE) return err; - + // export the tree bitstream_out bitbuf(dest, dlength); err = export_tree_huffman(bitbuf); if (err != HUFFERR_NONE) return err; - + // then encode the data for (UINT32 cur = 0; cur < slength; cur++) encode_one(bitbuf, source[cur]); @@ -727,7 +727,7 @@ huffman_error huffman_8bit_encoder::encode(const UINT8 *source, UINT32 slength, return bitbuf.overflow() ? HUFFERR_OUTPUT_BUFFER_TOO_SMALL : HUFFERR_NONE; } - + //************************************************************************** // 8-BIT DECODER @@ -740,7 +740,7 @@ huffman_error huffman_8bit_encoder::encode(const UINT8 *source, UINT32 slength, huffman_8bit_decoder::huffman_8bit_decoder() { } - + //------------------------------------------------- // decode - decode a full buffer @@ -753,7 +753,7 @@ huffman_error huffman_8bit_decoder::decode(const UINT8 *source, UINT32 slength, huffman_error err = import_tree_huffman(bitbuf); if (err != HUFFERR_NONE) return err; - + // then decode the data for (UINT32 cur = 0; cur < dlength; cur++) dest[cur] = decode_one(bitbuf); diff --git a/src/lib/util/huffman.h b/src/lib/util/huffman.h index 10dc301e7df..47525d82ed6 100644 --- a/src/lib/util/huffman.h +++ b/src/lib/util/huffman.h @@ -84,7 +84,7 @@ protected: UINT32 m_bits; // bits used to encode the node UINT8 m_numbits; // number of bits needed for this node }; - + // construction/destruction huffman_context_base(int numcodes, int maxbits, lookup_value *lookup, UINT32 *histo, node_t *nodes); @@ -133,12 +133,12 @@ public: void histo_reset() { memset(m_datahisto_array, 0, sizeof(m_datahisto_array)); } void histo_one(UINT32 data); void encode_one(bitstream_out &bitbuf, UINT32 data); - + // expose tree computation and export using huffman_context_base::compute_tree_from_histo; using huffman_context_base::export_tree_rle; using huffman_context_base::export_tree_huffman; - + private: // array versions of the info we need UINT32 m_datahisto_array[_NumCodes]; @@ -159,11 +159,11 @@ public: // single item operations UINT32 decode_one(bitstream_in &bitbuf); - + // expose tree import using huffman_context_base::import_tree_rle; using huffman_context_base::import_tree_huffman; - + private: // array versions of the info we need node_t m_huffnode_array[_NumCodes]; @@ -179,12 +179,12 @@ class huffman_8bit_encoder : public huffman_encoder<> public: // construction/destruction huffman_8bit_encoder(); - + // operations huffman_error encode(const UINT8 *source, UINT32 slength, UINT8 *dest, UINT32 destlength, UINT32 &complength); }; - + // ======================> huffman_8bit_decoder // generic 8-bit encoder/decoder @@ -193,7 +193,7 @@ class huffman_8bit_decoder : public huffman_decoder<> public: // construction/destruction huffman_8bit_decoder(); - + // operations huffman_error decode(const UINT8 *source, UINT32 slength, UINT8 *dest, UINT32 destlength); }; diff --git a/src/lib/util/un7z.c b/src/lib/util/un7z.c index 5bd8a605630..c0724687836 100644 --- a/src/lib/util/un7z.c +++ b/src/lib/util/un7z.c @@ -91,7 +91,7 @@ WRes File_Close(CSzFile *p) WRes File_Read(CSzFile *p, void *data, size_t *size) { -// file_error err; +// file_error err; UINT32 read_length; if (!p->_7z_osdfile) @@ -104,7 +104,7 @@ WRes File_Read(CSzFile *p, void *data, size_t *size) if (originalSize == 0) return 0; -// err = +// err = osd_read( p->_7z_osdfile, data, p->_7z_currfpos, originalSize, &read_length ); *size = read_length; p->_7z_currfpos += read_length; @@ -127,7 +127,7 @@ WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin) if (origin==2) p->_7z_currfpos = p->_7z_length - *pos; *pos = p->_7z_currfpos; - + return 0; } @@ -263,11 +263,11 @@ int _7z_search_crc_match(_7z_file *new_7z, UINT32 search_crc, const char* search if ((zn>=0x41) && (zn<=0x5a)) zn+=0x20; if (sn != zn) break; - } + } if (j==search_filename_length) namematch = true; } - + /* Check for a CRC match */ if (crc==search_crc) crcmatch = true; @@ -289,9 +289,9 @@ int _7z_search_crc_match(_7z_file *new_7z, UINT32 search_crc, const char* search found = true; } - if (found) + if (found) { - // printf("found %S %d %08x %08x %08x %s %d\n", temp, len, crc, search_crc, size, search_filename, search_filename_length); + // printf("found %S %d %08x %08x %08x %s %d\n", temp, len, crc, search_crc, size, search_filename, search_filename_length); new_7z->curr_file_idx = i; new_7z->uncompressed_length = size; new_7z->crc = crc; @@ -364,7 +364,7 @@ _7z_error _7z_file_open(const char *filename, _7z_file **_7z) FileInStream_CreateVTable(&new_7z->archiveStream); LookToRead_CreateVTable(&new_7z->lookStream, False); - + new_7z->lookStream.realStream = &new_7z->archiveStream.s; LookToRead_Init(&new_7z->lookStream); @@ -478,7 +478,7 @@ _7z_error _7z_file_decompress(_7z_file *new_7z, void *buffer, UINT32 length) &new_7z->blockIndex, &new_7z->outBuffer, &new_7z->outBufferSize, &offset, &outSizeProcessed, &new_7z->allocImp, &new_7z->allocTempImp); - + if (res != SZ_OK) return _7ZERR_FILE_ERROR; @@ -510,7 +510,7 @@ static void free__7z_file(_7z_file *_7z) if (_7z->outBuffer) IAlloc_Free(&_7z->allocImp, _7z->outBuffer); if (_7z->inited) SzArEx_Free(&_7z->db, &_7z->allocImp); - + free(_7z); } |
