diff --git a/formats/libchdr/libchdr_bitstream.c b/formats/libchdr/libchdr_bitstream.c index c82a67ddc5..036c60d400 100644 --- a/formats/libchdr/libchdr_bitstream.c +++ b/formats/libchdr/libchdr_bitstream.c @@ -122,4 +122,3 @@ uint32_t bitstream_flush(struct bitstream* bitstream) bitstream->bits = bitstream->buffer = 0; return bitstream->doffset; } - diff --git a/include/libchdr/libchdr_zlib.h b/include/libchdr/libchdr_zlib.h new file mode 100644 index 0000000000..4f3f141050 --- /dev/null +++ b/include/libchdr/libchdr_zlib.h @@ -0,0 +1,69 @@ +/* license:BSD-3-Clause + * copyright-holders:Aaron Giles + *************************************************************************** + + libchr_zlib.h + + Zlib compression wrappers + +***************************************************************************/ + +#pragma once + +#ifndef __LIBCHDR_ZLIB_H__ +#define __LIBCHDR_ZLIB_H__ + +#include + +#include +#include "coretypes.h" +#include "chd.h" + +#define MAX_ZLIB_ALLOCS 64 + +/* codec-private data for the ZLIB codec */ + +typedef struct _zlib_allocator zlib_allocator; +struct _zlib_allocator +{ + UINT32 * allocptr[MAX_ZLIB_ALLOCS]; +}; + +typedef struct _zlib_codec_data zlib_codec_data; +struct _zlib_codec_data +{ + z_stream inflater; + zlib_allocator allocator; +}; + + +/* codec-private data for the CDZL codec */ +typedef struct _cdzl_codec_data cdzl_codec_data; +struct _cdzl_codec_data { + /* internal state */ + zlib_codec_data base_decompressor; +#ifdef WANT_SUBCODE + zlib_codec_data subcode_decompressor; +#endif + uint8_t* buffer; +}; + +/* zlib compression codec */ +chd_error zlib_codec_init(void *codec, uint32_t hunkbytes); + +void zlib_codec_free(void *codec); + +chd_error zlib_codec_decompress(void *codec, const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen); + +voidpf zlib_fast_alloc(voidpf opaque, uInt items, uInt size); + +void zlib_fast_free(voidpf opaque, voidpf address); + +/* cdzl compression codec */ +chd_error cdzl_codec_init(void* codec, uint32_t hunkbytes); + +void cdzl_codec_free(void* codec); + +chd_error cdzl_codec_decompress(void *codec, const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen); + +#endif /* __LIBCHDR_ZLIB_H__ */ diff --git a/include/libchdr/lzma.h b/include/libchdr/lzma.h new file mode 100644 index 0000000000..e3cccbc196 --- /dev/null +++ b/include/libchdr/lzma.h @@ -0,0 +1,72 @@ +/* license:BSD-3-Clause + * copyright-holders:Aaron Giles + *************************************************************************** + + lzma.h + + LZMA compression wrappers + +***************************************************************************/ + +#pragma once + +#ifndef __LIBCHDR_LZMA_H__ +#define __LIBCHDR_LZMA_H__ + +#include + +#include +#include + +#include + +/* codec-private data for the LZMA codec */ +#define MAX_LZMA_ALLOCS 64 + +typedef struct _lzma_allocator lzma_allocator; +struct _lzma_allocator +{ + void *(*Alloc)(void *p, size_t size); + void (*Free)(void *p, void *address); /* address can be 0 */ + void (*FreeSz)(void *p, void *address, size_t size); /* address can be 0 */ + uint32_t* allocptr[MAX_LZMA_ALLOCS]; +}; + +typedef struct _lzma_codec_data lzma_codec_data; +struct _lzma_codec_data +{ + CLzmaDec decoder; + lzma_allocator allocator; +}; + +/* codec-private data for the CDLZ codec */ +typedef struct _cdlz_codec_data cdlz_codec_data; +struct _cdlz_codec_data { + /* internal state */ + lzma_codec_data base_decompressor; +#ifdef WANT_SUBCODE + zlib_codec_data subcode_decompressor; +#endif + uint8_t* buffer; +}; + +chd_error lzma_codec_init(void* codec, uint32_t hunkbytes); + +void lzma_codec_free(void* codec); + +/*------------------------------------------------- + * decompress - decompress data using the LZMA + * codec + *------------------------------------------------- + */ + +chd_error lzma_codec_decompress(void* codec, const uint8_t *src, + uint32_t complen, uint8_t *dest, uint32_t destlen); + +chd_error cdlz_codec_init(void* codec, uint32_t hunkbytes); + +void cdlz_codec_free(void* codec); + +chd_error cdlz_codec_decompress(void *codec, const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen); + +#endif /* __LIBCHDR_LZMA_H__ */