diff options
Diffstat (limited to 'src/lib/util/chdcodec.cpp')
-rw-r--r-- | src/lib/util/chdcodec.cpp | 266 |
1 files changed, 133 insertions, 133 deletions
diff --git a/src/lib/util/chdcodec.cpp b/src/lib/util/chdcodec.cpp index e2758f08a9e..71763163a87 100644 --- a/src/lib/util/chdcodec.cpp +++ b/src/lib/util/chdcodec.cpp @@ -25,7 +25,7 @@ // GLOBAL VARIABLES //************************************************************************** -static const UINT8 s_cd_sync_header[12] = { 0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00 }; +static const uint8_t s_cd_sync_header[12] = { 0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00 }; @@ -52,7 +52,7 @@ private: static void fast_free(voidpf opaque, voidpf address); static const int MAX_ZLIB_ALLOCS = 64; - UINT32 * m_allocptr[MAX_ZLIB_ALLOCS]; + uint32_t * m_allocptr[MAX_ZLIB_ALLOCS]; }; @@ -63,11 +63,11 @@ class chd_zlib_compressor : public chd_compressor { public: // construction/destruction - chd_zlib_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy); + chd_zlib_compressor(chd_file &chd, uint32_t hunkbytes, bool lossy); ~chd_zlib_compressor(); // core functionality - virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) override; + virtual uint32_t compress(const uint8_t *src, uint32_t srclen, uint8_t *dest) override; private: // internal state @@ -83,11 +83,11 @@ class chd_zlib_decompressor : public chd_decompressor { public: // construction/destruction - chd_zlib_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy); + chd_zlib_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy); ~chd_zlib_decompressor(); // core functionality - virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) override; + virtual void decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) override; private: // internal state @@ -112,7 +112,7 @@ private: static void fast_free(void *p, void *address); static const int MAX_LZMA_ALLOCS = 64; - UINT32 * m_allocptr[MAX_LZMA_ALLOCS]; + uint32_t * m_allocptr[MAX_LZMA_ALLOCS]; }; @@ -123,14 +123,14 @@ class chd_lzma_compressor : public chd_compressor { public: // construction/destruction - chd_lzma_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy); + chd_lzma_compressor(chd_file &chd, uint32_t hunkbytes, bool lossy); ~chd_lzma_compressor(); // core functionality - virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) override; + virtual uint32_t compress(const uint8_t *src, uint32_t srclen, uint8_t *dest) override; // helpers - static void configure_properties(CLzmaEncProps &props, UINT32 hunkbytes); + static void configure_properties(CLzmaEncProps &props, uint32_t hunkbytes); private: // internal state @@ -146,11 +146,11 @@ class chd_lzma_decompressor : public chd_decompressor { public: // construction/destruction - chd_lzma_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy); + chd_lzma_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy); ~chd_lzma_decompressor(); // core functionality - virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) override; + virtual void decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) override; private: // internal state @@ -166,10 +166,10 @@ class chd_huffman_compressor : public chd_compressor { public: // construction/destruction - chd_huffman_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy); + chd_huffman_compressor(chd_file &chd, uint32_t hunkbytes, bool lossy); // core functionality - virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) override; + virtual uint32_t compress(const uint8_t *src, uint32_t srclen, uint8_t *dest) override; private: // internal state @@ -184,10 +184,10 @@ class chd_huffman_decompressor : public chd_decompressor { public: // construction/destruction - chd_huffman_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy); + chd_huffman_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy); // core functionality - virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) override; + virtual void decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) override; private: // internal state @@ -202,13 +202,13 @@ class chd_flac_compressor : public chd_compressor { public: // construction/destruction - chd_flac_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy); + chd_flac_compressor(chd_file &chd, uint32_t hunkbytes, bool lossy); // core functionality - virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) override; + virtual uint32_t compress(const uint8_t *src, uint32_t srclen, uint8_t *dest) override; // static helpers - static UINT32 blocksize(UINT32 bytes); + static uint32_t blocksize(uint32_t bytes); private: // internal state @@ -224,10 +224,10 @@ class chd_flac_decompressor : public chd_decompressor { public: // construction/destruction - chd_flac_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy); + chd_flac_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy); // core functionality - virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) override; + virtual void decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) override; private: // internal state @@ -243,14 +243,14 @@ class chd_cd_flac_compressor : public chd_compressor { public: // construction/destruction - chd_cd_flac_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy); + chd_cd_flac_compressor(chd_file &chd, uint32_t hunkbytes, bool lossy); ~chd_cd_flac_compressor(); // core functionality - virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) override; + virtual uint32_t compress(const uint8_t *src, uint32_t srclen, uint8_t *dest) override; // static helpers - static UINT32 blocksize(UINT32 bytes); + static uint32_t blocksize(uint32_t bytes); private: // internal state @@ -258,7 +258,7 @@ private: flac_encoder m_encoder; z_stream m_deflater; chd_zlib_allocator m_allocator; - std::vector<UINT8> m_buffer; + std::vector<uint8_t> m_buffer; }; @@ -269,11 +269,11 @@ class chd_cd_flac_decompressor : public chd_decompressor { public: // construction/destruction - chd_cd_flac_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy); + chd_cd_flac_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy); ~chd_cd_flac_decompressor(); // core functionality - virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) override; + virtual void decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) override; private: // internal state @@ -281,7 +281,7 @@ private: flac_decoder m_decoder; z_stream m_inflater; chd_zlib_allocator m_allocator; - std::vector<UINT8> m_buffer; + std::vector<uint8_t> m_buffer; }; @@ -292,7 +292,7 @@ class chd_cd_compressor : public chd_compressor { public: // construction/destruction - chd_cd_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy) + chd_cd_compressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_compressor(chd, hunkbytes, lossy), m_base_compressor(chd, (hunkbytes / CD_FRAME_SIZE) * CD_MAX_SECTOR_DATA, lossy), m_subcode_compressor(chd, (hunkbytes / CD_FRAME_SIZE) * CD_MAX_SUBCODE_DATA, lossy), @@ -304,25 +304,25 @@ public: } // core functionality - virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) override + virtual uint32_t compress(const uint8_t *src, uint32_t srclen, uint8_t *dest) override { // determine header bytes - UINT32 frames = srclen / CD_FRAME_SIZE; - UINT32 complen_bytes = (srclen < 65536) ? 2 : 3; - UINT32 ecc_bytes = (frames + 7) / 8; - UINT32 header_bytes = ecc_bytes + complen_bytes; + uint32_t frames = srclen / CD_FRAME_SIZE; + uint32_t complen_bytes = (srclen < 65536) ? 2 : 3; + uint32_t ecc_bytes = (frames + 7) / 8; + uint32_t header_bytes = ecc_bytes + complen_bytes; // clear out destination header memset(dest, 0, header_bytes); // copy audio data followed by subcode data - for (UINT32 framenum = 0; framenum < frames; framenum++) + for (uint32_t framenum = 0; framenum < frames; framenum++) { memcpy(&m_buffer[framenum * CD_MAX_SECTOR_DATA], &src[framenum * CD_FRAME_SIZE], CD_MAX_SECTOR_DATA); memcpy(&m_buffer[frames * CD_MAX_SECTOR_DATA + framenum * CD_MAX_SUBCODE_DATA], &src[framenum * CD_FRAME_SIZE + CD_MAX_SECTOR_DATA], CD_MAX_SUBCODE_DATA); // clear out ECC data if we can - UINT8 *sector = &m_buffer[framenum * CD_MAX_SECTOR_DATA]; + uint8_t *sector = &m_buffer[framenum * CD_MAX_SECTOR_DATA]; if (memcmp(sector, s_cd_sync_header, sizeof(s_cd_sync_header)) == 0 && ecc_verify(sector)) { dest[framenum / 8] |= 1 << (framenum % 8); @@ -332,7 +332,7 @@ public: } // encode the base portion - UINT32 complen = m_base_compressor.compress(&m_buffer[0], frames * CD_MAX_SECTOR_DATA, &dest[header_bytes]); + uint32_t complen = m_base_compressor.compress(&m_buffer[0], frames * CD_MAX_SECTOR_DATA, &dest[header_bytes]); if (complen >= srclen) throw CHDERR_COMPRESSION_ERROR; @@ -350,7 +350,7 @@ private: // internal state _BaseCompressor m_base_compressor; _SubcodeCompressor m_subcode_compressor; - std::vector<UINT8> m_buffer; + std::vector<uint8_t> m_buffer; }; @@ -361,7 +361,7 @@ class chd_cd_decompressor : public chd_decompressor { public: // construction/destruction - chd_cd_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy) + chd_cd_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_decompressor(chd, hunkbytes, lossy), m_base_decompressor(chd, (hunkbytes / CD_FRAME_SIZE) * CD_MAX_SECTOR_DATA, lossy), m_subcode_decompressor(chd, (hunkbytes / CD_FRAME_SIZE) * CD_MAX_SUBCODE_DATA, lossy), @@ -373,16 +373,16 @@ public: } // core functionality - virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) override + virtual void decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) override { // determine header bytes - UINT32 frames = destlen / CD_FRAME_SIZE; - UINT32 complen_bytes = (destlen < 65536) ? 2 : 3; - UINT32 ecc_bytes = (frames + 7) / 8; - UINT32 header_bytes = ecc_bytes + complen_bytes; + uint32_t frames = destlen / CD_FRAME_SIZE; + uint32_t complen_bytes = (destlen < 65536) ? 2 : 3; + uint32_t ecc_bytes = (frames + 7) / 8; + uint32_t header_bytes = ecc_bytes + complen_bytes; // extract compressed length of base - UINT32 complen_base = (src[ecc_bytes + 0] << 8) | src[ecc_bytes + 1]; + uint32_t complen_base = (src[ecc_bytes + 0] << 8) | src[ecc_bytes + 1]; if (complen_bytes > 2) complen_base = (complen_base << 8) | src[ecc_bytes + 2]; @@ -391,13 +391,13 @@ public: m_subcode_decompressor.decompress(&src[header_bytes + complen_base], complen - complen_base - header_bytes, &m_buffer[frames * CD_MAX_SECTOR_DATA], frames * CD_MAX_SUBCODE_DATA); // reassemble the data - for (UINT32 framenum = 0; framenum < frames; framenum++) + for (uint32_t framenum = 0; framenum < frames; framenum++) { memcpy(&dest[framenum * CD_FRAME_SIZE], &m_buffer[framenum * CD_MAX_SECTOR_DATA], CD_MAX_SECTOR_DATA); memcpy(&dest[framenum * CD_FRAME_SIZE + CD_MAX_SECTOR_DATA], &m_buffer[frames * CD_MAX_SECTOR_DATA + framenum * CD_MAX_SUBCODE_DATA], CD_MAX_SUBCODE_DATA); // reconstitute the ECC data and sync header - UINT8 *sector = &dest[framenum * CD_FRAME_SIZE]; + uint8_t *sector = &dest[framenum * CD_FRAME_SIZE]; if ((src[framenum / 8] & (1 << (framenum % 8))) != 0) { memcpy(sector, s_cd_sync_header, sizeof(s_cd_sync_header)); @@ -410,7 +410,7 @@ private: // internal state _BaseDecompressor m_base_decompressor; _SubcodeDecompressor m_subcode_decompressor; - std::vector<UINT8> m_buffer; + std::vector<uint8_t> m_buffer; }; @@ -421,10 +421,10 @@ class chd_avhuff_compressor : public chd_compressor { public: // construction/destruction - chd_avhuff_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy); + chd_avhuff_compressor(chd_file &chd, uint32_t hunkbytes, bool lossy); // core functionality - virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) override; + virtual uint32_t compress(const uint8_t *src, uint32_t srclen, uint8_t *dest) override; private: // internal helpers @@ -443,10 +443,10 @@ class chd_avhuff_decompressor : public chd_decompressor { public: // construction/destruction - chd_avhuff_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy); + chd_avhuff_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy); // core functionality - virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) override; + virtual void decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) override; virtual void configure(int param, void *config) override; private: @@ -488,7 +488,7 @@ const chd_codec_list::codec_entry chd_codec_list::s_codec_list[] = // chd_codec - constructor //------------------------------------------------- -chd_codec::chd_codec(chd_file &chd, UINT32 hunkbytes, bool lossy) +chd_codec::chd_codec(chd_file &chd, uint32_t hunkbytes, bool lossy) : m_chd(chd), m_hunkbytes(hunkbytes), m_lossy(lossy) @@ -525,7 +525,7 @@ void chd_codec::configure(int param, void *config) // chd_compressor - constructor //------------------------------------------------- -chd_compressor::chd_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy) +chd_compressor::chd_compressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_codec(chd, hunkbytes, lossy) { } @@ -540,7 +540,7 @@ chd_compressor::chd_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy) // chd_decompressor - constructor //------------------------------------------------- -chd_decompressor::chd_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy) +chd_decompressor::chd_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_codec(chd, hunkbytes, lossy) { } @@ -614,7 +614,7 @@ const chd_codec_list::codec_entry *chd_codec_list::find_in_list(chd_codec_type t // chd_compressor_group - constructor //------------------------------------------------- -chd_compressor_group::chd_compressor_group(chd_file &chd, UINT32 compressor_list[4]) +chd_compressor_group::chd_compressor_group(chd_file &chd, uint32_t compressor_list[4]) : m_hunkbytes(chd.hunk_bytes()), m_compress_test(m_hunkbytes) #if CHDCODEC_VERIFY_COMPRESSION @@ -658,11 +658,11 @@ chd_compressor_group::~chd_compressor_group() // compression for this hunk //------------------------------------------------- -INT8 chd_compressor_group::find_best_compressor(const UINT8 *src, UINT8 *compressed, UINT32 &complen) +int8_t chd_compressor_group::find_best_compressor(const uint8_t *src, uint8_t *compressed, uint32_t &complen) { // determine best compression technique complen = m_hunkbytes; - INT8 compression = -1; + int8_t compression = -1; for (int codecnum = 0; codecnum < ARRAY_LENGTH(m_compressor); codecnum++) if (m_compressor[codecnum] != nullptr) { @@ -670,7 +670,7 @@ INT8 chd_compressor_group::find_best_compressor(const UINT8 *src, UINT8 *compres try { // if this is the best one, copy the data into the permanent buffer - UINT32 compbytes = m_compressor[codecnum]->compress(src, m_hunkbytes, &m_compress_test[0]); + uint32_t compbytes = m_compressor[codecnum]->compress(src, m_hunkbytes, &m_compress_test[0]); #if CHDCODEC_VERIFY_COMPRESSION try { @@ -768,7 +768,7 @@ voidpf chd_zlib_allocator::fast_alloc(voidpf opaque, uInt items, uInt size) // reuse a hunk if we can for (int scan = 0; scan < MAX_ZLIB_ALLOCS; scan++) { - UINT32 *ptr = codec->m_allocptr[scan]; + uint32_t *ptr = codec->m_allocptr[scan]; if (ptr != nullptr && size == *ptr) { // set the low bit of the size so we don't match next time @@ -778,7 +778,7 @@ voidpf chd_zlib_allocator::fast_alloc(voidpf opaque, uInt items, uInt size) } // alloc a new one and put it into the list - UINT32 *ptr = reinterpret_cast<UINT32 *>(new UINT8[size + sizeof(UINT32)]); + uint32_t *ptr = reinterpret_cast<uint32_t *>(new uint8_t[size + sizeof(uint32_t)]); for (int scan = 0; scan < MAX_ZLIB_ALLOCS; scan++) if (codec->m_allocptr[scan] == nullptr) { @@ -802,7 +802,7 @@ void chd_zlib_allocator::fast_free(voidpf opaque, voidpf address) chd_zlib_allocator *codec = reinterpret_cast<chd_zlib_allocator *>(opaque); // find the hunk - UINT32 *ptr = reinterpret_cast<UINT32 *>(address) - 1; + uint32_t *ptr = reinterpret_cast<uint32_t *>(address) - 1; for (int scan = 0; scan < MAX_ZLIB_ALLOCS; scan++) if (ptr == codec->m_allocptr[scan]) { @@ -822,7 +822,7 @@ void chd_zlib_allocator::fast_free(voidpf opaque, voidpf address) // chd_zlib_compressor - constructor //------------------------------------------------- -chd_zlib_compressor::chd_zlib_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy) +chd_zlib_compressor::chd_zlib_compressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_compressor(chd, hunkbytes, lossy) { // initialize the deflater @@ -853,7 +853,7 @@ chd_zlib_compressor::~chd_zlib_compressor() // compress - compress data using the ZLIB codec //------------------------------------------------- -UINT32 chd_zlib_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) +uint32_t chd_zlib_compressor::compress(const uint8_t *src, uint32_t srclen, uint8_t *dest) { // reset the decompressor m_deflater.next_in = const_cast<Bytef *>(src); @@ -887,7 +887,7 @@ UINT32 chd_zlib_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *des // chd_zlib_decompressor - constructor //------------------------------------------------- -chd_zlib_decompressor::chd_zlib_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy) +chd_zlib_decompressor::chd_zlib_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_decompressor(chd, hunkbytes, lossy) { // init the inflater @@ -919,7 +919,7 @@ chd_zlib_decompressor::~chd_zlib_decompressor() // codec //------------------------------------------------- -void chd_zlib_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) +void chd_zlib_decompressor::decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) { // reset the decompressor m_inflater.next_in = const_cast<Bytef *>(src); @@ -988,7 +988,7 @@ void *chd_lzma_allocator::fast_alloc(void *p, size_t size) // reuse a hunk if we can for (int scan = 0; scan < MAX_LZMA_ALLOCS; scan++) { - UINT32 *ptr = codec->m_allocptr[scan]; + uint32_t *ptr = codec->m_allocptr[scan]; if (ptr != nullptr && size == *ptr) { // set the low bit of the size so we don't match next time @@ -998,7 +998,7 @@ void *chd_lzma_allocator::fast_alloc(void *p, size_t size) } // alloc a new one and put it into the list - UINT32 *ptr = reinterpret_cast<UINT32 *>(new UINT8[size + sizeof(UINT32)]); + uint32_t *ptr = reinterpret_cast<uint32_t *>(new uint8_t[size + sizeof(uint32_t)]); for (int scan = 0; scan < MAX_LZMA_ALLOCS; scan++) if (codec->m_allocptr[scan] == nullptr) { @@ -1025,7 +1025,7 @@ void chd_lzma_allocator::fast_free(void *p, void *address) chd_lzma_allocator *codec = reinterpret_cast<chd_lzma_allocator *>(p); // find the hunk - UINT32 *ptr = reinterpret_cast<UINT32 *>(address) - 1; + uint32_t *ptr = reinterpret_cast<uint32_t *>(address) - 1; for (int scan = 0; scan < MAX_LZMA_ALLOCS; scan++) if (ptr == codec->m_allocptr[scan]) { @@ -1045,7 +1045,7 @@ void chd_lzma_allocator::fast_free(void *p, void *address) // chd_lzma_compressor - constructor //------------------------------------------------- -chd_lzma_compressor::chd_lzma_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy) +chd_lzma_compressor::chd_lzma_compressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_compressor(chd, hunkbytes, lossy) { // initialize the properties @@ -1066,7 +1066,7 @@ chd_lzma_compressor::~chd_lzma_compressor() // compress - compress data using the LZMA codec //------------------------------------------------- -UINT32 chd_lzma_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) +uint32_t chd_lzma_compressor::compress(const uint8_t *src, uint32_t srclen, uint8_t *dest) { // allocate the encoder CLzmaEncHandle encoder = LzmaEnc_Create(&m_allocator); @@ -1104,7 +1104,7 @@ UINT32 chd_lzma_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *des // codec //------------------------------------------------- -void chd_lzma_compressor::configure_properties(CLzmaEncProps &props, UINT32 hunkbytes) +void chd_lzma_compressor::configure_properties(CLzmaEncProps &props, uint32_t hunkbytes) { LzmaEncProps_Init(&props); props.level = 9; @@ -1122,7 +1122,7 @@ void chd_lzma_compressor::configure_properties(CLzmaEncProps &props, UINT32 hunk // chd_lzma_decompressor - constructor //------------------------------------------------- -chd_lzma_decompressor::chd_lzma_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy) +chd_lzma_decompressor::chd_lzma_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_decompressor(chd, hunkbytes, lossy) { // construct the decoder @@ -1177,7 +1177,7 @@ chd_lzma_decompressor::~chd_lzma_decompressor() // codec //------------------------------------------------- -void chd_lzma_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) +void chd_lzma_decompressor::decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) { // initialize LzmaDec_Init(&m_decoder); @@ -1201,7 +1201,7 @@ void chd_lzma_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT8 * // chd_huffman_compressor - constructor //------------------------------------------------- -chd_huffman_compressor::chd_huffman_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy) +chd_huffman_compressor::chd_huffman_compressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_compressor(chd, hunkbytes, lossy) { } @@ -1212,9 +1212,9 @@ chd_huffman_compressor::chd_huffman_compressor(chd_file &chd, UINT32 hunkbytes, // codec //------------------------------------------------- -UINT32 chd_huffman_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) +uint32_t chd_huffman_compressor::compress(const uint8_t *src, uint32_t srclen, uint8_t *dest) { - UINT32 complen; + uint32_t complen; if (m_encoder.encode(src, srclen, dest, srclen, complen) != HUFFERR_NONE) throw CHDERR_COMPRESSION_ERROR; return complen; @@ -1230,7 +1230,7 @@ UINT32 chd_huffman_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 * // chd_huffman_decompressor - constructor //------------------------------------------------- -chd_huffman_decompressor::chd_huffman_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy) +chd_huffman_decompressor::chd_huffman_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_decompressor(chd, hunkbytes, lossy) { } @@ -1241,7 +1241,7 @@ chd_huffman_decompressor::chd_huffman_decompressor(chd_file &chd, UINT32 hunkbyt // codec //------------------------------------------------- -void chd_huffman_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) +void chd_huffman_decompressor::decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) { if (m_decoder.decode(src, complen, dest, destlen) != HUFFERR_NONE) throw CHDERR_COMPRESSION_ERROR; @@ -1257,12 +1257,12 @@ void chd_huffman_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT // chd_flac_compressor - constructor //------------------------------------------------- -chd_flac_compressor::chd_flac_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy) +chd_flac_compressor::chd_flac_compressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_compressor(chd, hunkbytes, lossy) { // determine whether we want native or swapped samples - UINT16 native_endian = 0; - *reinterpret_cast<UINT8 *>(&native_endian) = 1; + uint16_t native_endian = 0; + *reinterpret_cast<uint8_t *>(&native_endian) = 1; m_big_endian = (native_endian == 0x100); // configure the encoder @@ -1277,22 +1277,22 @@ chd_flac_compressor::chd_flac_compressor(chd_file &chd, UINT32 hunkbytes, bool l // compress - compress data using the FLAC codec //------------------------------------------------- -UINT32 chd_flac_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) +uint32_t chd_flac_compressor::compress(const uint8_t *src, uint32_t srclen, uint8_t *dest) { // reset and encode big-endian m_encoder.reset(dest + 1, hunkbytes() - 1); - if (!m_encoder.encode_interleaved(reinterpret_cast<const INT16 *>(src), srclen / 4, !m_big_endian)) + if (!m_encoder.encode_interleaved(reinterpret_cast<const int16_t *>(src), srclen / 4, !m_big_endian)) throw CHDERR_COMPRESSION_ERROR; - UINT32 complen_be = m_encoder.finish(); + uint32_t complen_be = m_encoder.finish(); // reset and encode little-endian m_encoder.reset(dest + 1, hunkbytes() - 1); - if (!m_encoder.encode_interleaved(reinterpret_cast<const INT16 *>(src), srclen / 4, m_big_endian)) + if (!m_encoder.encode_interleaved(reinterpret_cast<const int16_t *>(src), srclen / 4, m_big_endian)) throw CHDERR_COMPRESSION_ERROR; - UINT32 complen_le = m_encoder.finish(); + uint32_t complen_le = m_encoder.finish(); // pick the best one and add a byte - UINT32 complen = std::min(complen_le, complen_be); + uint32_t complen = std::min(complen_le, complen_be); if (complen + 1 >= hunkbytes()) throw CHDERR_COMPRESSION_ERROR; @@ -1302,7 +1302,7 @@ UINT32 chd_flac_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *des { dest[0] = 'B'; m_encoder.reset(dest + 1, hunkbytes() - 1); - if (!m_encoder.encode_interleaved(reinterpret_cast<const INT16 *>(src), srclen / 4, !m_big_endian)) + if (!m_encoder.encode_interleaved(reinterpret_cast<const int16_t *>(src), srclen / 4, !m_big_endian)) throw CHDERR_COMPRESSION_ERROR; m_encoder.finish(); } @@ -1314,11 +1314,11 @@ UINT32 chd_flac_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *des // blocksize - return the optimal block size //------------------------------------------------- -UINT32 chd_flac_compressor::blocksize(UINT32 bytes) +uint32_t chd_flac_compressor::blocksize(uint32_t bytes) { // determine FLAC block size, which must be 16-65535 // clamp to 2k since that's supposed to be the sweet spot - UINT32 hunkbytes = bytes / 4; + uint32_t hunkbytes = bytes / 4; while (hunkbytes > 2048) hunkbytes /= 2; return hunkbytes; @@ -1334,12 +1334,12 @@ UINT32 chd_flac_compressor::blocksize(UINT32 bytes) // chd_flac_decompressor - constructor //------------------------------------------------- -chd_flac_decompressor::chd_flac_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy) +chd_flac_decompressor::chd_flac_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_decompressor(chd, hunkbytes, lossy) { // determine whether we want native or swapped samples - UINT16 native_endian = 0; - *reinterpret_cast<UINT8 *>(&native_endian) = 1; + uint16_t native_endian = 0; + *reinterpret_cast<uint8_t *>(&native_endian) = 1; m_big_endian = (native_endian == 0x100); } @@ -1349,7 +1349,7 @@ chd_flac_decompressor::chd_flac_decompressor(chd_file &chd, UINT32 hunkbytes, bo // codec //------------------------------------------------- -void chd_flac_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) +void chd_flac_decompressor::decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) { // determine the endianness bool swap_endian; @@ -1363,7 +1363,7 @@ void chd_flac_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT8 * // reset and decode if (!m_decoder.reset(44100, 2, chd_flac_compressor::blocksize(destlen), src + 1, complen - 1)) throw CHDERR_DECOMPRESSION_ERROR; - if (!m_decoder.decode_interleaved(reinterpret_cast<INT16 *>(dest), destlen / 4, swap_endian)) + if (!m_decoder.decode_interleaved(reinterpret_cast<int16_t *>(dest), destlen / 4, swap_endian)) throw CHDERR_DECOMPRESSION_ERROR; // finish up @@ -1380,7 +1380,7 @@ void chd_flac_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT8 * // chd_cd_flac_compressor - constructor //------------------------------------------------- -chd_cd_flac_compressor::chd_cd_flac_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy) +chd_cd_flac_compressor::chd_cd_flac_compressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_compressor(chd, hunkbytes, lossy), m_buffer(hunkbytes) { @@ -1389,8 +1389,8 @@ chd_cd_flac_compressor::chd_cd_flac_compressor(chd_file &chd, UINT32 hunkbytes, throw CHDERR_CODEC_ERROR; // determine whether we want native or swapped samples - UINT16 native_endian = 0; - *reinterpret_cast<UINT8 *>(&native_endian) = 1; + uint16_t native_endian = 0; + *reinterpret_cast<uint8_t *>(&native_endian) = 1; m_swap_endian = (native_endian == 1); // configure the encoder @@ -1428,11 +1428,11 @@ chd_cd_flac_compressor::~chd_cd_flac_compressor() // and use zlib on the subcode data //------------------------------------------------- -UINT32 chd_cd_flac_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) +uint32_t chd_cd_flac_compressor::compress(const uint8_t *src, uint32_t srclen, uint8_t *dest) { // copy audio data followed by subcode data - UINT32 frames = hunkbytes() / CD_FRAME_SIZE; - for (UINT32 framenum = 0; framenum < frames; framenum++) + uint32_t frames = hunkbytes() / CD_FRAME_SIZE; + for (uint32_t framenum = 0; framenum < frames; framenum++) { memcpy(&m_buffer[framenum * CD_MAX_SECTOR_DATA], &src[framenum * CD_FRAME_SIZE], CD_MAX_SECTOR_DATA); memcpy(&m_buffer[frames * CD_MAX_SECTOR_DATA + framenum * CD_MAX_SUBCODE_DATA], &src[framenum * CD_FRAME_SIZE + CD_MAX_SECTOR_DATA], CD_MAX_SUBCODE_DATA); @@ -1440,12 +1440,12 @@ UINT32 chd_cd_flac_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 * // reset and encode the audio portion m_encoder.reset(dest, hunkbytes()); - UINT8 *buffer = &m_buffer[0]; - if (!m_encoder.encode_interleaved(reinterpret_cast<INT16 *>(buffer), frames * CD_MAX_SECTOR_DATA/4, m_swap_endian)) + uint8_t *buffer = &m_buffer[0]; + if (!m_encoder.encode_interleaved(reinterpret_cast<int16_t *>(buffer), frames * CD_MAX_SECTOR_DATA/4, m_swap_endian)) throw CHDERR_COMPRESSION_ERROR; // finish up - UINT32 complen = m_encoder.finish(); + uint32_t complen = m_encoder.finish(); // deflate the subcode data m_deflater.next_in = const_cast<Bytef *>(&m_buffer[frames * CD_MAX_SECTOR_DATA]); @@ -1469,7 +1469,7 @@ UINT32 chd_cd_flac_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 * } /** - * @fn UINT32 chd_cd_flac_compressor::blocksize(UINT32 bytes) + * @fn uint32_t chd_cd_flac_compressor::blocksize(uint32_t bytes) * * @brief ------------------------------------------------- * blocksize - return the optimal block size @@ -1477,13 +1477,13 @@ UINT32 chd_cd_flac_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 * * * @param bytes The bytes. * - * @return An UINT32. + * @return An uint32_t. */ -UINT32 chd_cd_flac_compressor::blocksize(UINT32 bytes) +uint32_t chd_cd_flac_compressor::blocksize(uint32_t bytes) { // for CDs it seems that CD_MAX_SECTOR_DATA is the right target - UINT32 blocksize = bytes / 4; + uint32_t blocksize = bytes / 4; while (blocksize > CD_MAX_SECTOR_DATA) blocksize /= 2; return blocksize; @@ -1496,7 +1496,7 @@ UINT32 chd_cd_flac_compressor::blocksize(UINT32 bytes) //************************************************************************** /** - * @fn chd_cd_flac_decompressor::chd_cd_flac_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy) + * @fn chd_cd_flac_decompressor::chd_cd_flac_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy) * * @brief ------------------------------------------------- * chd_cd_flac_decompressor - constructor @@ -1509,7 +1509,7 @@ UINT32 chd_cd_flac_compressor::blocksize(UINT32 bytes) * @param lossy true to lossy. */ -chd_cd_flac_decompressor::chd_cd_flac_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy) +chd_cd_flac_decompressor::chd_cd_flac_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_decompressor(chd, hunkbytes, lossy), m_buffer(hunkbytes) { @@ -1518,8 +1518,8 @@ chd_cd_flac_decompressor::chd_cd_flac_decompressor(chd_file &chd, UINT32 hunkbyt throw CHDERR_CODEC_ERROR; // determine whether we want native or swapped samples - UINT16 native_endian = 0; - *reinterpret_cast<UINT8 *>(&native_endian) = 1; + uint16_t native_endian = 0; + *reinterpret_cast<uint8_t *>(&native_endian) = 1; m_swap_endian = (native_endian == 1); // init the inflater @@ -1549,7 +1549,7 @@ chd_cd_flac_decompressor::~chd_cd_flac_decompressor() } /** - * @fn void chd_cd_flac_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) + * @fn void chd_cd_flac_decompressor::decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) * * @brief ------------------------------------------------- * decompress - decompress data using the FLAC codec @@ -1564,18 +1564,18 @@ chd_cd_flac_decompressor::~chd_cd_flac_decompressor() * @param destlen The destlen. */ -void chd_cd_flac_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) +void chd_cd_flac_decompressor::decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) { // reset and decode - UINT32 frames = destlen / CD_FRAME_SIZE; + uint32_t frames = destlen / CD_FRAME_SIZE; if (!m_decoder.reset(44100, 2, chd_cd_flac_compressor::blocksize(frames * CD_MAX_SECTOR_DATA), src, complen)) throw CHDERR_DECOMPRESSION_ERROR; - UINT8 *buffer = &m_buffer[0]; - if (!m_decoder.decode_interleaved(reinterpret_cast<INT16 *>(buffer), frames * CD_MAX_SECTOR_DATA/4, m_swap_endian)) + uint8_t *buffer = &m_buffer[0]; + if (!m_decoder.decode_interleaved(reinterpret_cast<int16_t *>(buffer), frames * CD_MAX_SECTOR_DATA/4, m_swap_endian)) throw CHDERR_DECOMPRESSION_ERROR; // inflate the subcode data - UINT32 offset = m_decoder.finish(); + uint32_t offset = m_decoder.finish(); m_inflater.next_in = const_cast<Bytef *>(src + offset); m_inflater.avail_in = complen - offset; m_inflater.total_in = 0; @@ -1594,7 +1594,7 @@ void chd_cd_flac_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT throw CHDERR_DECOMPRESSION_ERROR; // reassemble the data - for (UINT32 framenum = 0; framenum < frames; framenum++) + for (uint32_t framenum = 0; framenum < frames; framenum++) { memcpy(&dest[framenum * CD_FRAME_SIZE], &m_buffer[framenum * CD_MAX_SECTOR_DATA], CD_MAX_SECTOR_DATA); memcpy(&dest[framenum * CD_FRAME_SIZE + CD_MAX_SECTOR_DATA], &m_buffer[frames * CD_MAX_SECTOR_DATA + framenum * CD_MAX_SUBCODE_DATA], CD_MAX_SUBCODE_DATA); @@ -1608,7 +1608,7 @@ void chd_cd_flac_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT //************************************************************************** /** - * @fn chd_avhuff_compressor::chd_avhuff_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy) + * @fn chd_avhuff_compressor::chd_avhuff_compressor(chd_file &chd, uint32_t hunkbytes, bool lossy) * * @brief ------------------------------------------------- * chd_avhuff_compressor - constructor @@ -1619,7 +1619,7 @@ void chd_cd_flac_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT * @param lossy true to lossy. */ -chd_avhuff_compressor::chd_avhuff_compressor(chd_file &chd, UINT32 hunkbytes, bool lossy) +chd_avhuff_compressor::chd_avhuff_compressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_compressor(chd, hunkbytes, lossy), m_postinit(false) { @@ -1635,7 +1635,7 @@ chd_avhuff_compressor::chd_avhuff_compressor(chd_file &chd, UINT32 hunkbytes, bo } /** - * @fn UINT32 chd_avhuff_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) + * @fn uint32_t chd_avhuff_compressor::compress(const uint8_t *src, uint32_t srclen, uint8_t *dest) * * @brief ------------------------------------------------- * compress - compress data using the A/V codec @@ -1650,10 +1650,10 @@ chd_avhuff_compressor::chd_avhuff_compressor(chd_file &chd, UINT32 hunkbytes, bo * @param srclen The srclen. * @param [in,out] dest If non-null, destination for the. * - * @return An UINT32. + * @return An uint32_t. */ -UINT32 chd_avhuff_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *dest) +uint32_t chd_avhuff_compressor::compress(const uint8_t *src, uint32_t srclen, uint8_t *dest) { // if we haven't yet set up the avhuff code, do it now if (!m_postinit) @@ -1669,7 +1669,7 @@ UINT32 chd_avhuff_compressor::compress(const UINT8 *src, UINT32 srclen, UINT8 *d } // encode the audio and video - UINT32 complen; + uint32_t complen; avhuff_error averr = m_encoder.encode_data(src, dest, complen); if (averr != AVHERR_NONE || complen > srclen) throw CHDERR_COMPRESSION_ERROR; @@ -1703,9 +1703,9 @@ void chd_avhuff_compressor::postinit() throw CHDERR_INVALID_METADATA; // compute the bytes per frame - UINT32 fps_times_1million = fps * 1000000 + fpsfrac; - UINT32 max_samples_per_frame = (UINT64(rate) * 1000000 + fps_times_1million - 1) / fps_times_1million; - UINT32 bytes_per_frame = 12 + channels * max_samples_per_frame * 2 + width * height * 2; + uint32_t fps_times_1million = fps * 1000000 + fpsfrac; + uint32_t max_samples_per_frame = (uint64_t(rate) * 1000000 + fps_times_1million - 1) / fps_times_1million; + uint32_t bytes_per_frame = 12 + channels * max_samples_per_frame * 2 + width * height * 2; if (bytes_per_frame > hunkbytes()) throw CHDERR_INVALID_METADATA; @@ -1720,7 +1720,7 @@ void chd_avhuff_compressor::postinit() //************************************************************************** /** - * @fn chd_avhuff_decompressor::chd_avhuff_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy) + * @fn chd_avhuff_decompressor::chd_avhuff_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy) * * @brief ------------------------------------------------- * chd_avhuff_decompressor - constructor @@ -1731,13 +1731,13 @@ void chd_avhuff_compressor::postinit() * @param lossy true to lossy. */ -chd_avhuff_decompressor::chd_avhuff_decompressor(chd_file &chd, UINT32 hunkbytes, bool lossy) +chd_avhuff_decompressor::chd_avhuff_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy) : chd_decompressor(chd, hunkbytes, lossy) { } /** - * @fn void chd_avhuff_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) + * @fn void chd_avhuff_decompressor::decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) * * @brief ------------------------------------------------- * decompress - decompress data using the A/V codec @@ -1752,7 +1752,7 @@ chd_avhuff_decompressor::chd_avhuff_decompressor(chd_file &chd, UINT32 hunkbytes * @param destlen The destlen. */ -void chd_avhuff_decompressor::decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen) +void chd_avhuff_decompressor::decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) { // decode the audio and video avhuff_error averr = m_decoder.decode_data(src, complen, dest); |