1 /*
2 Copyright (C) 2015-2021, Dirk Krause
3 SPDX-License-Identifier: BSD-3-Clause
4 */
5 
6 /*
7 	WARNING: This file was generated by the dkct program (see
8 	http://dktools.sourceforge.net/ for details).
9 	Changes you make here will be lost if dkct is run again!
10 	You should modify the original source and run dkct on it.
11 	Original source: dk4rld.ctr
12 */
13 
14 #ifndef DK4RLD_H_INCLUDED
15 /** Avoid multiple inclusions. */
16 #define DK4RLD_H_INCLUDED 1
17 
18 
19 /**	@file	dk4rld.h	Run-length decoder.
20 
21 Use dk4rld_init() to initialize the decoder before feeding data to it.
22 
23 Feed the encoded data into the decoder byte by byte, use the
24 dk4rld_add() function.
25 If the function returns DK4_EDSTM_ACCEPT, the input was successfully stored
26 into the internal data structures, not need for further action.
27 If the function returns DK4_EDSTM_FINISHED, an output secquence was
28 completed, either a run or a literal byte sequence. Use dk4rld_output()
29 to retrieve output data.
30 If the dk4rld_add function returns DK4_EDSTM_STOP, an end of data
31 (EOD) marker was found; do not feed further bytes into the decoder.
32 
33 After feeding all input bytes into the decoder, use dk4rld_finish() to check
34 syntax. If the function returns DK4_EDSTM_ERROR, the input data stream
35 was not properly run-length encoded.
36 */
37 
38 
39 #ifndef	DK4CONF_H_INCLUDED
40 #if DK4_BUILDING_DKTOOLS4
41 #include "dk4conf.h"
42 #else
43 #include <dktools-4/dk4conf.h>
44 #endif
45 #endif
46 
47 #ifndef	DK4ERROR_H_INCLUDED
48 #if DK4_BUILDING_DKTOOLS4
49 #include <libdk4base/dk4error.h>
50 #else
51 #include <dktools-4/dk4error.h>
52 #endif
53 #endif
54 
55 /**	Run length decoder.
56 */
57 typedef struct {
58   unsigned char		ob[128];	/**< Output buffer. */
59   size_t		oused;		/**< Number of used bytes in ob. */
60   size_t		ll;		/**< Number of expected bytes. */
61   int			st;		/**< Current state. */
62 } dk4_rl_dec_t;
63 
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
69 /**	Initialize decoder.
70 	@param	dec	Decoder to initialize.
71 	@param	erp	Error report, may be NULL.
72 
73 	Error codes:
74 	- DK4_E_INVALID_ARGUMENTS	if enc is NULL.
75 */
76 void
77 dk4rld_init(dk4_rl_dec_t *dec, dk4_er_t *erp);
78 
79 /**	Add one encoded byte to decoder.
80 	@param	dec	Decoder.
81 	@param	inbyte	Byte to process.
82 	@param	erp	Error report, may be NULL.
83 	@return	Action to take, one from:
84 	- DK4_EDSTM_ACCEPT<br>
85 	  if the byte was successfully added
86 	  to the internal data structures, no further action necessary.
87 	- DK4_EDSTM_FINISHED<br>
88 	  if output is available, use dk4rld_output() to retrieve output.
89 	- DK4_EDSTM_STOP<br>
90 	  if an EOD marker was detected. Do not feed further bytes
91 	  to the decoder.
92 	- DK4_EDSTM_ERROR<br>
93 	  if an error occured.
94 
95 	Error codes:
96 	- DK4_E_INVALID_ARGUMENTS	if enc is NULL.
97 */
98 int
99 dk4rld_add(dk4_rl_dec_t *dec, unsigned char inbyte, dk4_er_t *erp);
100 
101 /**	Finish decoding.
102 	@param	dec	Decoder.
103 	@param	erp	Error report, may be NULL.
104 	@return	Action to take, one from:
105 	- DK4_EDSTM_ACCEPT<br>
106 	  if no remaining data is stored in the decoder, no further
107 	  action necessary.
108 	- DK4_EDSTM_FINISHED<br>
109 	  if output is available, use dk4rld_output() to retrieve output.
110 	- DK4_EDSTM_ERROR<br>
111 	  if an error occured.
112 
113 	Error codes:
114 	- DK4_E_INVALID_ARGUMENTS<br>
115 	  if enc is NULL.
116 	- DK4_E_SYNTAX<br>
117 	  if data indicated by the run-length byte or literally-length
118 	  byte is missing.
119 */
120 int
121 dk4rld_finish(dk4_rl_dec_t *dec, dk4_er_t *erp);
122 
123 /**	Retrieve decoder output.
124 	@param	dptr	Address of pointer to set to decoder output,
125 			should be initialized to NULL.
126 	@param	szptr	Address of variable to receive buffer size,
127 			should be initialized to 0.
128 	@param	dec	Decoder.
129 	@param	erp	Error report, may be NULL.
130 	@return	1 if data is available, 0 otherwise.
131 
132 	Error codes:
133 	- DK4_E_INVALID_ARGUMENTS	if enc is NULL.
134 */
135 int
136 dk4rld_output(
137   const unsigned char	**dptr,
138   size_t		 *szptr,
139   dk4_rl_dec_t	const	 *dec,
140   dk4_er_t		 *erp
141 );
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 
148 #endif
149