spandsp  1.99.0
private/t85.h
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * private/t85.h - ITU T.85 JBIG for FAX image processing
5  *
6  * Written by Steve Underwood <steveu@coppice.org>
7  *
8  * Copyright (C) 2008, 2009 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 #if !defined(_SPANDSP_PRIVATE_T85_H_)
27 #define _SPANDSP_PRIVATE_T85_H_
28 
29 /* Maximum number of ATMOVEs per stripe that the decoder can handle */
30 #define T85_ATMOVES_MAX 1
31 
32 /* TP special pixels */
33 #define TPB2CX 0x195
34 #define TPB3CX 0x0E5
35 
36 /* T.82 table 2 - symbolic constants */
37 enum
38 {
39  T82_STUFF = 0x00,
40  T82_RESERVE = 0x01,
41  T82_SDNORM = 0x02,
42  T82_SDRST = 0x03,
43  T82_ABORT = 0x04,
44  T82_NEWLEN = 0x05,
45  T82_ATMOVE = 0x06,
46  T82_COMMENT = 0x07,
47  T82_ESC = 0xFF
48 };
49 
50 /* State of a working instance of the T.85 JBIG FAX encoder */
52 {
53  /*! \brief Callback function to read a row of pixels from the image source. */
55  /*! \brief Opaque pointer passed to row_read_handler. */
57 
58  /*! The number of bit planes. Always 1 for true T.85 */
59  uint8_t bit_planes;
60  uint8_t current_bit_plane;
61  /*! The width of the full image, in pixels */
62  uint32_t xd;
63  /*! The height of the full image, in pixels */
64  uint32_t yd;
65  /*! The number of rows per stripe */
66  uint32_t l0;
67  /*! Maximum ATMOVE window size (0 - 127) */
68  int mx;
69  /*! Encoding parameters */
70  int options;
71  /*! The contents for a COMMENT marker segment, to be added to the
72  image at the next opportunity. This is set to NULL when nothing is
73  pending. */
74  const uint8_t *comment;
75  /*! Length of data pointed to by comment */
76  size_t comment_len;
77 
78  /*! Next row number to be encoded */
79  uint32_t y;
80  /*! Next row within current stripe */
81  uint32_t i;
82  /*! Flag for handling NEWLEN processing. */
83  int newlen;
84  /*! X-offset of adaptive template pixel */
85  int32_t tx;
86  /*! Adaptive template algorithm variables */
87  uint32_t c_all;
88  /*! Adaptive template algorithm variables */
89  uint32_t c[128];
90  /*! New TX value, or <0 for analysis in progress */
91  int32_t new_tx;
92  /*! True if previous row was typical */
93  bool prev_ltp;
94  /*! Pointers to the 3 row buffers */
95  uint8_t *prev_row[3];
96  /*! Pointer to a block of allocated memory 3 rows long, which
97  we divide up for the 3 row buffers. */
98  uint8_t *row_buf;
99  uint8_t *bitstream;
100  int bitstream_len;
101  int bitstream_iptr;
102  int bitstream_optr;
103  int fill_with_white;
104 
105  /*! \brief The size of the compressed image, in bytes. */
107 
108  /*! Arithmetic encoder state */
110 
111  /*! \brief Error and flow logging control */
113 };
114 
115 /* State of a working instance of the T.85 JBIG FAX decoder */
117 {
118  /*! A callback routine to handle decoded pixel rows */
120  /*! An opaque pointer passed to row_write_handler() */
122  /*! A callback routine to handle decoded comments */
124  /*! An opaque pointer passed to comment_handler() */
126  /*! The maximum length of comment to be passed to the comment handler */
127  uint32_t max_comment_len;
128 
129  uint8_t min_bit_planes;
130  uint8_t max_bit_planes;
131  /*! The maximum permitted width of the full image, in pixels */
132  uint32_t max_xd;
133  /*! The maximum permitted height of the full image, in pixels */
134  uint32_t max_yd;
135 
136  /*! The number of bit planes expected, according to the header. Always 1 for true T.85 */
137  uint8_t bit_planes;
138  uint8_t current_bit_plane;
139 
140  /*! The width of the full image, in pixels */
141  uint32_t xd;
142  /*! The height of the full image, in pixels */
143  uint32_t yd;
144  /*! The number of rows per stripe */
145  uint32_t l0;
146  /*! Maximum ATMOVE window size */
147  int mx;
148  /*! Encoding parameters */
149  int options;
150 
151  /*! The current row and the previous 2 rows of image data */
152  int p[3];
153  /*! Pointers to the 3 row buffers */
154  uint8_t *prev_row[3];
155  /*! Pointer to a block of allocated memory 3 rows long, which
156  we divide up for the 3 row buffers. */
157  uint8_t *row_buf;
158  /*! The length of the row buffer */
160  /*! Bytes per pixel row */
162  /*! X-offset of AT pixel */
163  int32_t tx;
164  /*! Number of bytes read so far */
165  uint32_t bie_len;
166  /*! Buffer space for the BIH or marker segments fragments */
167  uint8_t buffer[20];
168  /*! Number of bytes in buffer. */
169  int buf_len;
170  /*! Required number of bytes in buffer to proceed with processing
171  its contents. */
173  /*! The content of a decoded COMMENT marker segment. */
174  uint8_t *comment;
175  /*! The expected length of a decoded COMMENT segment */
176  uint32_t comment_len;
177  /*! The length of COMMENT decoded to date */
179  /*! Current column */
180  uint32_t x;
181  /*! Current row */
182  uint32_t y;
183  /*! Current row within the current stripe */
184  uint32_t i;
185  /*! Number of AT moves in the current stripe */
186  int at_moves;
187  /*! Rows at which an AT move will happen */
188  uint32_t at_row[T85_ATMOVES_MAX];
189  /*! ATMOVE x-offsets in current stripe */
190  int at_tx[T85_ATMOVES_MAX];
191  /*! Working data for decode_pscd() */
192  uint32_t row_h[3];
193  /*! Flag for TPBON/TPDON: next pixel is a pseudo pixel */
194  int pseudo;
195  /*! Line is not typical flag. */
196  int lntp;
197  /*! Flag that row_write_handler() requested an interrupt. */
199  /*! Flag that the data to be decoded has run out. */
201  /*! Arithmetic decoder state */
203 
204  /*! \brief The size of the compressed image, in bytes. */
206 
207  /*! \brief Error and flow logging control */
209 };
210 
211 #endif
212 /*- End of file ------------------------------------------------------------*/
const uint8_t * comment
Definition: private/t85.h:74
uint32_t bie_len
Definition: private/t85.h:165
uint32_t comment_progress
Definition: private/t85.h:178
void * comment_user_data
Definition: private/t85.h:125
Definition: private/t81_t82_arith_coding.h:54
uint8_t bit_planes
Definition: private/t85.h:137
uint8_t bit_planes
Definition: private/t85.h:59
int buf_needed
Definition: private/t85.h:172
int row_buf_len
Definition: private/t85.h:159
t4_row_write_handler_t comment_handler
Definition: private/t85.h:123
void * row_write_user_data
Definition: private/t85.h:121
int mx
Definition: private/t85.h:147
uint32_t y
Definition: private/t85.h:79
t4_row_write_handler_t row_write_handler
Definition: private/t85.h:119
int lntp
Definition: private/t85.h:196
uint32_t comment_len
Definition: private/t85.h:176
uint32_t yd
Definition: private/t85.h:64
logging_state_t logging
Error and flow logging control.
Definition: private/t85.h:112
t81_t82_arith_decode_state_t s
Definition: private/t85.h:202
logging_state_t logging
Error and flow logging control.
Definition: private/t85.h:208
uint32_t y
Definition: private/t85.h:182
t81_t82_arith_encode_state_t s
Definition: private/t85.h:109
int newlen
Definition: private/t85.h:83
uint32_t max_yd
Definition: private/t85.h:134
int32_t tx
Definition: private/t85.h:163
int32_t new_tx
Definition: private/t85.h:91
uint32_t i
Definition: private/t85.h:81
uint32_t l0
Definition: private/t85.h:145
int32_t tx
Definition: private/t85.h:85
uint32_t c[128]
Definition: private/t85.h:89
int end_of_data
Definition: private/t85.h:200
uint8_t * row_buf
Definition: private/t85.h:157
uint32_t max_xd
Definition: private/t85.h:132
uint32_t xd
Definition: private/t85.h:141
int compressed_image_size
The size of the compressed image, in bytes.
Definition: private/t85.h:106
int compressed_image_size
The size of the compressed image, in bytes.
Definition: private/t85.h:205
size_t bytes_per_row
Definition: private/t85.h:161
void * row_read_user_data
Opaque pointer passed to row_read_handler.
Definition: private/t85.h:56
uint8_t * comment
Definition: private/t85.h:174
Definition: private/logging.h:33
int buf_len
Definition: private/t85.h:169
int at_moves
Definition: private/t85.h:186
Definition: private/t85.h:116
uint32_t i
Definition: private/t85.h:184
uint32_t yd
Definition: private/t85.h:143
Definition: private/t85.h:51
uint32_t max_comment_len
Definition: private/t85.h:127
uint32_t x
Definition: private/t85.h:180
uint8_t * prev_row[3]
Definition: private/t85.h:95
Definition: private/t81_t82_arith_coding.h:33
uint32_t c_all
Definition: private/t85.h:87
uint8_t * row_buf
Definition: private/t85.h:98
int options
Definition: private/t85.h:70
int interrupt
Definition: private/t85.h:198
bool prev_ltp
Definition: private/t85.h:93
int pseudo
Definition: private/t85.h:194
int mx
Definition: private/t85.h:68
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
uint32_t l0
Definition: private/t85.h:66
uint32_t xd
Definition: private/t85.h:62
int options
Definition: private/t85.h:149
t4_row_read_handler_t row_read_handler
Callback function to read a row of pixels from the image source.
Definition: private/t85.h:54
size_t comment_len
Definition: private/t85.h:76