1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * private/t4_rx.h - definitions for T.4 FAX receive processing
5  *
6  * Written by Steve Underwood <steveu@coppice.org>
7  *
8  * Copyright (C) 2003 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_T4_RX_H_)
27 #define _SPANDSP_PRIVATE_T4_RX_H_
28 
29 typedef int (*t4_image_put_handler_t)(void *user_data, const uint8_t buf[], size_t len);
30 
31 /*!
32     TIFF specific state information to go with T.4 compression or decompression handling.
33 */
34 typedef struct
35 {
36     /*! \brief The current file name. */
37     const char *file;
38     /*! \brief The libtiff context for the current TIFF file */
39     TIFF *tiff_file;
40 
41     /*! Image type - bilevel, gray, colour */
42     int image_type;
43     /*! \brief The compression type for output to the TIFF file. */
44     int compression;
45     /*! \brief The TIFF photometric setting for the current page. */
46     uint16_t photo_metric;
47     /*! \brief The TIFF fill order setting for the current page. */
48     uint16_t fill_order;
49 
50     /*! \brief The number of pages in the current image file. */
51     int pages_in_file;
52 
53     /*! \brief The time at which handling of the current page began. */
54     time_t page_start_time;
55 
56     /*! \brief A point to the image buffer. */
57     uint8_t *image_buffer;
58     /*! \brief The size of the image in the image buffer, in bytes. */
59     int image_size;
60     /*! \brief The current size of the image buffer. */
61     int image_buffer_size;
62 } t4_rx_tiff_state_t;
63 
64 /*!
65     T.4 FAX decompression metadata descriptor. This contains information about the image
66     which may be relevant to the backend, but is not relevant to the image decoding process.
67 */
68 typedef struct
69 {
70     /*! \brief The type of compression used on the wire. */
71     int compression;
72     /*! \brief The width of the current page, in pixels. */
73     uint32_t image_width;
74     /*! \brief The length of the current page, in pixels. */
75     uint32_t image_length;
76     /*! \brief Column-to-column (X) resolution in pixels per metre. */
77     int x_resolution;
78     /*! \brief Row-to-row (Y) resolution in pixels per metre. */
79     int y_resolution;
80 
81     /* "Background" information about the FAX, which can be stored in the image file. */
82     /*! \brief The vendor of the machine which produced the file. */
83     const char *vendor;
84     /*! \brief The model of machine which produced the file. */
85     const char *model;
86     /*! \brief The remote end's ident string. */
87     const char *far_ident;
88     /*! \brief The FAX sub-address. */
89     const char *sub_address;
90     /*! \brief The FAX DCS information, as an ASCII hex string. */
91     const char *dcs;
92 } t4_rx_metadata_t;
93 
94 typedef struct
95 {
96     uint8_t *buf;
97     int buf_len;
98     int buf_ptr;
99 } no_decoder_state_t;
100 
101 /*!
102     T.4 FAX decompression descriptor. This defines the working state
103     for a single instance of a T.4 FAX decompression channel.
104 */
105 struct t4_rx_state_s
106 {
107     /*! \brief Callback function to write a row of pixels to the image destination. */
108     t4_row_write_handler_t row_handler;
109     /*! \brief Opaque pointer passed to row_write_handler. */
110     void *row_handler_user_data;
111 
112     /*! \brief A bit mask of the currently supported image compression modes for writing
113                to the TIFF file. */
114     int supported_tiff_compressions;
115 
116     /*! \brief The number of pages transferred to date. */
117     int current_page;
118 
119     /*! \brief The size of the compressed image on the line side, in bits. */
120     int line_image_size;
121 
122     union
123     {
124         no_decoder_state_t no_decoder;
125         t4_t6_decode_state_t t4_t6;
126         t85_decode_state_t t85;
127 #if defined(SPANDSP_SUPPORT_T88)
128         t88_decode_state_t t88;
129 #endif
130         t42_decode_state_t t42;
131         t43_decode_state_t t43;
132 #if defined(SPANDSP_SUPPORT_T45)
133         t45_decode_state_t t45;
134 #endif
135     } decoder;
136 
137     t4_image_put_handler_t image_put_handler;
138 
139     int current_decoder;
140 
141     /* Supporting information, like resolutions, which the backend may want. */
142     t4_rx_metadata_t metadata;
143 
144     /*! \brief All TIFF file specific state information for the T.4 context. */
145     t4_rx_tiff_state_t tiff;
146 
147     /*! \brief Error and flow logging control */
148     logging_state_t logging;
149 };
150 
151 #endif
152 /*- End of file ------------------------------------------------------------*/
153