diff options
Diffstat (limited to 'src/lib/util/chdcodec.h')
-rw-r--r-- | src/lib/util/chdcodec.h | 106 |
1 files changed, 45 insertions, 61 deletions
diff --git a/src/lib/util/chdcodec.h b/src/lib/util/chdcodec.h index e688b41a108..c477333544f 100644 --- a/src/lib/util/chdcodec.h +++ b/src/lib/util/chdcodec.h @@ -2,39 +2,28 @@ // copyright-holders:Aaron Giles /*************************************************************************** - chdcodec.h - Codecs used by the CHD format ***************************************************************************/ - -#ifndef MAME_UTIL_CHDCODEC_H -#define MAME_UTIL_CHDCODEC_H +#ifndef MAME_LIB_UTIL_CHDCODEC_H +#define MAME_LIB_UTIL_CHDCODEC_H #pragma once -#include "osdcore.h" -#include "coretmpl.h" - - -#define CHDCODEC_VERIFY_COMPRESSION 0 - +#include "utilfwd.h" -//************************************************************************** -// MACROS -//************************************************************************** +#include <cstdint> +#include <memory> +#include <vector> -#define CHD_MAKE_TAG(a,b,c,d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) +#define CHDCODEC_VERIFY_COMPRESSION 0 //************************************************************************** // TYPE DEFINITIONS //************************************************************************** -// forward references -class chd_file; - // base types typedef uint32_t chd_codec_type; @@ -63,7 +52,7 @@ public: private: // internal state chd_file & m_chd; - uint32_t m_hunkbytes; + uint32_t m_hunkbytes; bool m_lossy; }; @@ -78,6 +67,8 @@ protected: chd_compressor(chd_file &file, uint32_t hunkbytes, bool lossy); public: + using ptr = std::unique_ptr<chd_compressor>; + // implementation virtual uint32_t compress(const uint8_t *src, uint32_t srclen, uint8_t *dest) = 0; }; @@ -93,7 +84,10 @@ protected: chd_decompressor(chd_file &file, uint32_t hunkbytes, bool lossy); public: + using ptr = std::unique_ptr<chd_decompressor>; + // implementation + virtual void process(const uint8_t *src, uint32_t complen); virtual void decompress(const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen) = 0; }; @@ -105,35 +99,12 @@ class chd_codec_list { 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); + static chd_compressor::ptr new_compressor(chd_codec_type type, chd_file &file); + static chd_decompressor::ptr new_decompressor(chd_codec_type type, chd_file &file); // utilities - static bool codec_exists(chd_codec_type type) { return (find_in_list(type) != nullptr); } - static const char *codec_name(chd_codec_type type); - -private: - // an entry in the list - struct codec_entry - { - chd_codec_type m_type; - bool m_lossy; - const char * m_name; - chd_compressor * (*m_construct_compressor)(chd_file &, uint32_t, bool); - chd_decompressor * (*m_construct_decompressor)(chd_file &, uint32_t, bool); - }; - - // 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, uint32_t hunkbytes, bool lossy) { return new _CompressorClass(chd, hunkbytes, lossy); } - - template<class _DecompressorClass> - static chd_decompressor *construct_decompressor(chd_file &chd, uint32_t hunkbytes, bool lossy) { return new _DecompressorClass(chd, hunkbytes, lossy); } - - // the static list - static const codec_entry s_codec_list[]; + static bool codec_exists(chd_codec_type type) noexcept; + static const char *codec_name(chd_codec_type type) noexcept; }; @@ -152,37 +123,50 @@ public: private: // internal state - uint32_t m_hunkbytes; // number of bytes in a hunk - chd_compressor * m_compressor[4]; // array of active codecs - std::vector<uint8_t> m_compress_test; // test buffer for compression + uint32_t m_hunkbytes; // number of bytes in a hunk + chd_compressor::ptr m_compressor[4]; // array of active codecs + std::vector<uint8_t> m_compress_test; // test buffer for compression #if CHDCODEC_VERIFY_COMPRESSION - chd_decompressor * m_decompressor[4]; // array of active codecs - std::vector<uint8_t> m_decompressed; // verification buffer + chd_decompressor::ptr m_decompressor[4]; // array of active codecs + std::vector<uint8_t> m_decompressed; // verification buffer #endif }; //************************************************************************** +// MACROS +//************************************************************************** + +constexpr chd_codec_type CHD_MAKE_TAG(char a, char b, char c, char d) +{ + return (uint32_t(uint8_t(a)) << 24) | uint32_t(uint8_t((b)) << 16) | uint32_t(uint8_t((c)) << 8) | uint32_t(uint8_t(d)); +} + + + +//************************************************************************** // CONSTANTS //************************************************************************** // currently-defined codecs -const chd_codec_type CHD_CODEC_NONE = 0; +constexpr chd_codec_type CHD_CODEC_NONE = 0; // general codecs -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 = CHD_MAKE_TAG('f','l','a','c'); +constexpr chd_codec_type CHD_CODEC_ZLIB = CHD_MAKE_TAG('z','l','i','b'); +constexpr chd_codec_type CHD_CODEC_ZSTD = CHD_MAKE_TAG('z','s','t','d'); +constexpr chd_codec_type CHD_CODEC_LZMA = CHD_MAKE_TAG('l','z','m','a'); +constexpr chd_codec_type CHD_CODEC_HUFFMAN = CHD_MAKE_TAG('h','u','f','f'); +constexpr chd_codec_type CHD_CODEC_FLAC = CHD_MAKE_TAG('f','l','a','c'); // general codecs with CD frontend -const chd_codec_type CHD_CODEC_CD_ZLIB = CHD_MAKE_TAG('c','d','z','l'); -const chd_codec_type CHD_CODEC_CD_LZMA = CHD_MAKE_TAG('c','d','l','z'); -const chd_codec_type CHD_CODEC_CD_FLAC = CHD_MAKE_TAG('c','d','f','l'); +constexpr chd_codec_type CHD_CODEC_CD_ZLIB = CHD_MAKE_TAG('c','d','z','l'); +constexpr chd_codec_type CHD_CODEC_CD_ZSTD = CHD_MAKE_TAG('c','d','z','s'); +constexpr chd_codec_type CHD_CODEC_CD_LZMA = CHD_MAKE_TAG('c','d','l','z'); +constexpr chd_codec_type CHD_CODEC_CD_FLAC = CHD_MAKE_TAG('c','d','f','l'); // A/V codecs -const chd_codec_type CHD_CODEC_AVHUFF = CHD_MAKE_TAG('a','v','h','u'); +constexpr chd_codec_type CHD_CODEC_AVHUFF = CHD_MAKE_TAG('a','v','h','u'); // A/V codec configuration parameters enum @@ -190,4 +174,4 @@ enum AVHUFF_CODEC_DECOMPRESS_CONFIG = 1 }; -#endif // MAME_UTIL_CHDCODEC_H +#endif // MAME_LIB_UTIL_CHDCODEC_H |