diff options
Diffstat (limited to 'src/lib/util')
| -rw-r--r-- | src/lib/util/avhuff.c | 52 | ||||
| -rw-r--r-- | src/lib/util/avhuff.h | 20 | ||||
| -rw-r--r-- | src/lib/util/bitstream.h | 8 | ||||
| -rw-r--r-- | src/lib/util/cdrom.c | 2 | ||||
| -rw-r--r-- | src/lib/util/chd.c | 306 | ||||
| -rw-r--r-- | src/lib/util/chd.h | 148 | ||||
| -rw-r--r-- | src/lib/util/chdcodec.c | 58 | ||||
| -rw-r--r-- | src/lib/util/chdcodec.h | 18 | ||||
| -rw-r--r-- | src/lib/util/coretmpl.h | 4 | ||||
| -rw-r--r-- | src/lib/util/flac.c | 66 | ||||
| -rw-r--r-- | src/lib/util/flac.h | 16 | ||||
| -rw-r--r-- | src/lib/util/hashing.c | 82 | ||||
| -rw-r--r-- | src/lib/util/hashing.h | 102 | ||||
| -rw-r--r-- | src/lib/util/huffman.c | 46 | ||||
| -rw-r--r-- | src/lib/util/huffman.h | 16 | ||||
| -rw-r--r-- | src/lib/util/un7z.c | 20 |
16 files changed, 482 insertions, 482 deletions
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); } |
