git subrepo clone https://github.com/libretro/libretro-common.git deps/libretro-common
[pcsx_rearmed.git] / deps / libretro-common / include / libchdr / libchdr_zlib.h
1 /* license:BSD-3-Clause
2  * copyright-holders:Aaron Giles
3  ***************************************************************************
4
5     libchr_zlib.h
6
7     Zlib compression wrappers
8
9 ***************************************************************************/
10
11 #pragma once
12
13 #ifndef __LIBCHDR_ZLIB_H__
14 #define __LIBCHDR_ZLIB_H__
15
16 #include <stdint.h>
17
18 #include <zlib.h>
19 #include "coretypes.h"
20 #include "chd.h"
21
22 #define MAX_ZLIB_ALLOCS                         64
23
24 /* codec-private data for the ZLIB codec */
25
26 typedef struct _zlib_allocator zlib_allocator;
27 struct _zlib_allocator
28 {
29         UINT32 *                                allocptr[MAX_ZLIB_ALLOCS];
30         UINT32 *                                allocptr2[MAX_ZLIB_ALLOCS];
31 };
32
33 typedef struct _zlib_codec_data zlib_codec_data;
34 struct _zlib_codec_data
35 {
36         z_stream                                inflater;
37         zlib_allocator                  allocator;
38 };
39
40 /* codec-private data for the CDZL codec */
41 typedef struct _cdzl_codec_data cdzl_codec_data;
42 struct _cdzl_codec_data {
43         /* internal state */
44         zlib_codec_data         base_decompressor;
45 #ifdef WANT_SUBCODE
46         zlib_codec_data         subcode_decompressor;
47 #endif
48         uint8_t*                        buffer;
49 };
50
51 /* zlib compression codec */
52 chd_error zlib_codec_init(void *codec, uint32_t hunkbytes);
53
54 void zlib_codec_free(void *codec);
55
56 chd_error zlib_codec_decompress(void *codec, const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen);
57
58 voidpf zlib_fast_alloc(voidpf opaque, uInt items, uInt size);
59
60 void zlib_fast_free(voidpf opaque, voidpf address);
61
62 /* cdzl compression codec */
63 chd_error cdzl_codec_init(void* codec, uint32_t hunkbytes);
64
65 void cdzl_codec_free(void* codec);
66
67 chd_error cdzl_codec_decompress(void *codec, const uint8_t *src, uint32_t complen, uint8_t *dest, uint32_t destlen);
68
69 #endif /* __LIBCHDR_ZLIB_H__ */