spandsp  3.0.0
t43.h
Go to the documentation of this file.
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * t43.h - ITU T.43 JBIG for grey and colour FAX image processing
5  *
6  * Written by Steve Underwood <steveu@coppice.org>
7  *
8  * Copyright (C) 2011 Steve Underwood
9  *
10  * All rights reserved.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 2.1,
14  * as published by the Free Software Foundation.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25 
26 /*! \file */
27 
28 #if !defined(_SPANDSP_T43_H_)
29 #define _SPANDSP_T43_H_
30 
31 /*! \page t43_page T.43 (JBIG for gray and colour FAX) image compression and decompression
32 
33 \section t43_page_sec_1 What does it do?
34 
35 \section t43_page_sec_1 How does it work?
36 */
37 
38 /*! State of a working instance of the T.43 encoder */
40 
41 /*! State of a working instance of the T.43 decoder */
43 
44 enum
45 {
46  T43_IMAGE_TYPE_RGB_BILEVEL = 0,
47  T43_IMAGE_TYPE_CMY_BILEVEL = 1,
48  T43_IMAGE_TYPE_CMYK_BILEVEL = 2,
49  T43_IMAGE_TYPE_8BIT_COLOUR_PALETTE = 16,
50  T43_IMAGE_TYPE_12BIT_COLOUR_PALETTE = 17,
51  T43_IMAGE_TYPE_GRAY = 32,
52  T43_IMAGE_TYPE_COLOUR = 48
53 };
54 
55 #if defined(__cplusplus)
56 extern "C"
57 {
58 #endif
59 
60 SPAN_DECLARE(const char *) t43_image_type_to_str(int type);
61 
62 SPAN_DECLARE(void) t43_encode_set_options(t43_encode_state_t *s,
63  uint32_t l0,
64  int mx,
65  int options);
66 
67 SPAN_DECLARE(int) t43_encode_set_image_width(t43_encode_state_t *s, uint32_t image_width);
68 
69 SPAN_DECLARE(int) t43_encode_set_image_length(t43_encode_state_t *s, uint32_t length);
70 
71 SPAN_DECLARE(int) t43_encode_set_image_type(t43_encode_state_t *s, int image_type);
72 
73 SPAN_DECLARE(void) t43_encode_abort(t43_encode_state_t *s);
74 
75 SPAN_DECLARE(void) t43_encode_comment(t43_encode_state_t *s, const uint8_t comment[], size_t len);
76 
77 /*! \brief Check if we are at the end of the current document page.
78  \param s The T.43 context.
79  \return 0 for more data to come. SIG_STATUS_END_OF_DATA for no more data. */
80 SPAN_DECLARE(int) t43_encode_image_complete(t43_encode_state_t *s);
81 
82 SPAN_DECLARE(int) t43_encode_get(t43_encode_state_t *s, uint8_t buf[], size_t max_len);
83 
84 SPAN_DECLARE(uint32_t) t43_encode_get_image_width(t43_encode_state_t *s);
85 
86 SPAN_DECLARE(uint32_t) t43_encode_get_image_length(t43_encode_state_t *s);
87 
88 SPAN_DECLARE(int) t43_encode_get_compressed_image_size(t43_encode_state_t *s);
89 
90 SPAN_DECLARE(int) t43_encode_set_row_read_handler(t43_encode_state_t *s,
91  t4_row_read_handler_t handler,
92  void *user_data);
93 
94 /*! Get the logging context associated with a T.43 encode context.
95  \brief Get the logging context associated with a T.43 encode context.
96  \param s The T.43 encode context.
97  \return A pointer to the logging context */
99 
100 /*! \brief Restart a T.43 encode context.
101  \param s The T.43 context.
102  \param image image_width The image width, in pixels.
103  \param image image_width The image length, in pixels.
104  \return 0 for success, otherwise -1. */
105 SPAN_DECLARE(int) t43_encode_restart(t43_encode_state_t *s, uint32_t image_width, uint32_t image_length);
106 
107 /*! \brief Prepare to encode an image in T.43 format.
108  \param s The T.43 context.
109  \param image_width Image width, in pixels.
110  \param image_length Image length, in pixels.
111  \param handler A callback routine to handle encoded image rows.
112  \param user_data An opaque pointer passed to handler.
113  \return A pointer to the context, or NULL if there was a problem. */
115  uint32_t image_width,
116  uint32_t image_length,
117  t4_row_read_handler_t handler,
118  void *user_data);
119 
120 /*! \brief Release a T.43 encode context.
121  \param s The T.43 encode context.
122  \return 0 for OK, else -1. */
123 SPAN_DECLARE(int) t43_encode_release(t43_encode_state_t *s);
124 
125 /*! \brief Free a T.43 encode context.
126  \param s The T.43 encode context.
127  \return 0 for OK, else -1. */
128 SPAN_DECLARE(int) t43_encode_free(t43_encode_state_t *s);
129 
130 SPAN_DECLARE(void) t43_decode_rx_status(t43_decode_state_t *s, int status);
131 
132 /*! \brief Decode a chunk of T.43 data.
133  \param s The T.43 context.
134  \param data The data to be decoded.
135  \param len The length of the data to be decoded.
136  \return 0 for OK. */
137 SPAN_DECLARE(int) t43_decode_put(t43_decode_state_t *s, const uint8_t data[], size_t len);
138 
139 /*! \brief Set the row handler routine.
140  \param s The T.43 context.
141  \param handler A callback routine to handle decoded image rows.
142  \param user_data An opaque pointer passed to handler.
143  \return 0 for OK. */
145  t4_row_write_handler_t handler,
146  void *user_data);
147 
148 /*! \brief Set the comment handler routine.
149  \param s The T.43 context.
150  \param max_comment_len The maximum length of comment to be passed to the handler.
151  \param handler A callback routine to handle decoded comment.
152  \param user_data An opaque pointer passed to handler.
153  \return 0 for OK. */
155  uint32_t max_comment_len,
156  t4_row_write_handler_t handler,
157  void *user_data);
158 
159 SPAN_DECLARE(int) t43_decode_set_image_size_constraints(t43_decode_state_t *s,
160  uint32_t max_xd,
161  uint32_t max_yd);
162 
163 /*! \brief Get the width of the image.
164  \param s The T.43 context.
165  \return The width of the image, in pixels. */
166 SPAN_DECLARE(uint32_t) t43_decode_get_image_width(t43_decode_state_t *s);
167 
168 /*! \brief Get the length of the image.
169  \param s The T.43 context.
170  \return The length of the image, in pixels. */
171 SPAN_DECLARE(uint32_t) t43_decode_get_image_length(t43_decode_state_t *s);
172 
173 SPAN_DECLARE(int) t43_decode_get_compressed_image_size(t43_decode_state_t *s);
174 
175 /*! Get the logging context associated with a T.43 decode context.
176  \brief Get the logging context associated with a T.43 decode context.
177  \param s The T.43 decode context.
178  \return A pointer to the logging context */
180 
181 SPAN_DECLARE(int) t43_decode_restart(t43_decode_state_t *s);
182 
183 /*! \brief Prepare to decode an image in T.43 format.
184  \param s The T.43 context.
185  \param handler A callback routine to handle decoded image rows.
186  \param user_data An opaque pointer passed to handler.
187  \return A pointer to the context, or NULL if there was a problem. */
189  t4_row_write_handler_t handler,
190  void *user_data);
191 
192 /*! \brief Release a T.43 decode context.
193  \param s The T.43 decode context.
194  \return 0 for OK, else -1. */
195 SPAN_DECLARE(int) t43_decode_release(t43_decode_state_t *s);
196 
197 /*! \brief Free a T.43 decode context.
198  \param s The T.43 decode context.
199  \return 0 for OK, else -1. */
200 SPAN_DECLARE(int) t43_decode_free(t43_decode_state_t *s);
201 
202 #if defined(__cplusplus)
203 }
204 #endif
205 
206 #endif
207 /*- End of file ------------------------------------------------------------*/
int t43_decode_set_comment_handler(t43_decode_state_t *s, uint32_t max_comment_len, t4_row_write_handler_t handler, void *user_data)
Set the comment handler routine.
Definition: t43.c:832
logging_state_t * t43_encode_get_logging_state(t43_encode_state_t *s)
Get the logging context associated with a T.43 encode context.
Definition: t43.c:301
int t43_decode_put(t43_decode_state_t *s, const uint8_t data[], size_t len)
Decode a chunk of T.43 data.
Definition: t43.c:740
int t43_decode_release(t43_decode_state_t *s)
Release a T.43 decode context.
Definition: t43.c:927
int t43_encode_restart(t43_encode_state_t *s, uint32_t image_width, uint32_t image_length)
Restart a T.43 encode context.
Definition: t43.c:307
int t43_decode_set_row_write_handler(t43_decode_state_t *s, t4_row_write_handler_t handler, void *user_data)
Set the row handler routine.
Definition: t43.c:820
int t43_decode_free(t43_decode_state_t *s)
Free a T.43 decode context.
Definition: t43.c:934
uint32_t t43_decode_get_image_width(t43_decode_state_t *s)
Get the width of the image.
Definition: t43.c:849
logging_state_t * t43_decode_get_logging_state(t43_decode_state_t *s)
Get the logging context associated with a T.43 decode context.
Definition: t43.c:867
Definition: private/t43.h:61
int t43_encode_free(t43_encode_state_t *s)
Free a T.43 encode context.
Definition: t43.c:352
int t43_encode_image_complete(t43_encode_state_t *s)
Check if we are at the end of the current document page.
Definition: t43.c:261
t43_decode_state_t * t43_decode_init(t43_decode_state_t *s, t4_row_write_handler_t handler, void *user_data)
Prepare to decode an image in T.43 format.
Definition: t43.c:891
Definition: private/t43.h:30
int t43_encode_release(t43_encode_state_t *s)
Release a T.43 encode context.
Definition: t43.c:345
Definition: private/logging.h:33
uint32_t t43_decode_get_image_length(t43_decode_state_t *s)
Get the length of the image.
Definition: t43.c:855
t43_encode_state_t * t43_encode_init(t43_encode_state_t *s, uint32_t image_width, uint32_t image_length, t4_row_read_handler_t handler, void *user_data)
Prepare to encode an image in T.43 format.
Definition: t43.c:313
int(* t4_row_write_handler_t)(void *user_data, const uint8_t buf[], size_t len)
Definition: t4_rx.h:46
int(* t4_row_read_handler_t)(void *user_data, uint8_t buf[], size_t len)
Definition: t4_tx.h:34