1 /*
2 
3 Copyright (c) 2011, 2012, Simon Howard
4 
5 Permission to use, copy, modify, and/or distribute this software
6 for any purpose with or without fee is hereby granted, provided
7 that the above copyright notice and this permission notice appear
8 in all copies.
9 
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
14 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
16 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17 CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 
19  */
20 
21 #ifndef LHASA_LHA_DECODER_H
22 #define LHASA_LHA_DECODER_H
23 
24 #include "public/lha_decoder.h"
25 
26 struct _LHADecoderType {
27 
28 	/**
29 	 * Callback function to initialize the decoder.
30 	 *
31 	 * @param extra_data     Pointer to the extra data area allocated for
32 	 *                       the decoder.
33 	 * @param callback       Callback function to invoke to read more
34 	 *                       compressed data.
35 	 * @param callback_data  Extra pointer to pass to the callback.
36 	 * @return               Non-zero for success.
37 	 */
38 
39 	int (*init)(void *extra_data,
40 	            LHADecoderCallback callback,
41 	            void *callback_data);
42 
43 	/**
44 	 * Callback function to free the decoder.
45 	 *
46 	 * @param extra_data     Pointer to the extra data area allocated for
47 	 *                       the decoder.
48 	 */
49 
50 	void (*free)(void *extra_data);
51 
52 	/**
53 	 * Callback function to read (ie. decompress) data from the
54 	 * decoder.
55 	 *
56 	 * @param extra_data     Pointer to the decoder's custom data.
57 	 * @param buf            Pointer to the buffer in which to store
58 	 *                       the decompressed data.  The buffer is
59 	 *                       at least 'max_read' bytes in size.
60 	 * @return               Number of bytes decompressed.
61 	 */
62 
63 	size_t (*read)(void *extra_data, uint8_t *buf);
64 
65 	/** Number of bytes of extra data to allocate for the decoder. */
66 
67 	size_t extra_size;
68 
69 	/** Maximum number of bytes that might be put into the buffer by
70 	    a single call to read() */
71 
72 	size_t max_read;
73 
74 	/** Block size. Used for calculating number of blocks for
75 	    progress bar. */
76 
77 	size_t block_size;
78 };
79 
80 struct _LHADecoder {
81 
82 	/** Type of decoder (algorithm) */
83 
84 	LHADecoderType *dtype;
85 
86 	/** Callback function to monitor decoder progress. */
87 
88 	LHADecoderProgressCallback progress_callback;
89 	void *progress_callback_data;
90 
91 	/** Last announced block position, for progress callback. */
92 
93 	unsigned int last_block, total_blocks;
94 
95 	/** Current position in the decode stream, and total length. */
96 
97 	size_t stream_pos, stream_length;
98 
99 	/** Output buffer, containing decoded data not yet returned. */
100 
101 	unsigned int outbuf_pos, outbuf_len;
102 	uint8_t *outbuf;
103 
104 	/** If true, the decoder read() function returned zero. */
105 
106 	unsigned int decoder_failed;
107 
108 	/** Current CRC of the output stream. */
109 
110 	uint16_t crc;
111 };
112 
113 #endif /* #ifndef LHASA_LHA_DECODER_H */
114 
115