1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * private/t4_tx.h - definitions for T.4 FAX transmit 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_TX_H_)
27 #define _SPANDSP_PRIVATE_T4_TX_H_
28 
29 typedef int (*t4_image_get_handler_t)(void *user_data, 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     /*! \brief The compression type used in the TIFF file */
42     uint16_t compression;
43     /*! \brief Image type - bi-level, gray, colour, etc. */
44     int image_type;
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 Width of the image in the file. */
51     uint32_t image_width;
52     /*! \brief Length of the image in the file. */
53     uint32_t image_length;
54     /*! \brief Column-to-column (X) resolution in pixels per metre of the image in the file. */
55     int x_resolution;
56     /*! \brief Row-to-row (Y) resolution in pixels per metre of the image in the file. */
57     int y_resolution;
58     /*! \brief Code for the combined X and Y resolution of the image in the file. */
59     int resolution_code;
60 
61     /*! \brief The number of pages in the current image file. */
62     int pages_in_file;
63 
64     /*! \brief A pointer to the image buffer. */
65     uint8_t *image_buffer;
66     /*! \brief The size of the image in the image buffer, in bytes. */
67     int image_size;
68     /*! \brief The current size of the image buffer. */
69     int image_buffer_size;
70     /*! \brief Row counter for playing out the rows of the image. */
71     int row;
72     /*! \brief Row counter used when the image is resized or dithered flat. */
73     int raw_row;
74 } t4_tx_tiff_state_t;
75 
76 /*!
77     T.4 FAX compression metadata descriptor. This contains information about the image
78     which may be relevant to the backend, but is not generally relevant to the image
79     encoding process. The exception here is the y-resolution, which is used in T.4 2-D
80     encoding for non-ECM applications, to optimise the balance of density and robustness.
81 */
82 typedef struct
83 {
84     /*! \brief The type of compression used on the wire. */
85     int compression;
86     /*! \brief Image type - bi-level, gray, colour, etc. */
87     int image_type;
88     /*! \brief The width code for the image on the line side. */
89     int width_code;
90 
91     /*! \brief The width of the current page on the wire, in pixels. */
92     uint32_t image_width;
93     /*! \brief The length of the current page on the wire, in pixels. */
94     uint32_t image_length;
95     /*! \brief Column-to-column (X) resolution in pixels per metre on the wire. */
96     int x_resolution;
97     /*! \brief Row-to-row (Y) resolution in pixels per metre on the wire. */
98     int y_resolution;
99     /*! \brief Code for the combined X and Y resolution on the wire. */
100     int resolution_code;
101 } t4_tx_metadata_t;
102 
103 typedef struct
104 {
105     uint8_t *buf;
106     int buf_len;
107     int buf_ptr;
108     int bit;
109 } no_encoder_state_t;
110 
111 /*!
112     T.4 FAX compression descriptor. This defines the working state
113     for a single instance of a T.4 FAX compression channel.
114 */
115 struct t4_tx_state_s
116 {
117     /*! \brief Callback function to read a row of pixels from the image source. */
118     t4_row_read_handler_t row_handler;
119     /*! \brief Opaque pointer passed to row_read_handler. */
120     void *row_handler_user_data;
121 
122     /*! \brief When superfine and fine resolution images need to be squahed vertically
123                to a lower resolution, this value sets the number of source rows which
124                must be squashed to form each row on the wire. */
125     int row_squashing_ratio;
126 
127     /*! \brief The size of the compressed image on the line side, in bits. */
128     int line_image_size;
129 
130     /*! \brief The first page to transfer. -1 to start at the beginning of the file. */
131     int start_page;
132     /*! \brief The last page to transfer. -1 to continue to the end of the file. */
133     int stop_page;
134 
135     /*! \brief True for FAX page headers to overlay (i.e. replace) the beginning of the
136                page image. False for FAX page headers to add to the overall length of
137                the page. */
138     bool header_overlays_image;
139     /*! \brief The text which will be used in FAX page header. No text results
140                in no header line. */
141     const char *header_info;
142     /*! \brief The local ident string. This is used with header_info to form a
143                page header line. */
144     const char *local_ident;
145     /*! \brief The page number of current page. The first page is zero. If FAX page
146                headers are used, the page number in the header will be one more than
147                this value (i.e. they start from 1). */
148     int current_page;
149 
150     /*! \brief The composed text of the FAX page header, if there is one. */
151     char *header_text;
152     /*! \brief Optional per instance time zone for the FAX page header timestamp. */
153     tz_t *tz;
154 
155     /*! \brief Row counter for playing out the rows of the header line. */
156     int header_row;
157 
158     union
159     {
160         no_encoder_state_t no_encoder;
161         t4_t6_encode_state_t t4_t6;
162         t85_encode_state_t t85;
163 #if defined(SPANDSP_SUPPORT_T88)
164         t88_encode_state_t t88;
165 #endif
166         t42_encode_state_t t42;
167         t43_encode_state_t t43;
168 #if defined(SPANDSP_SUPPORT_T45)
169         t45_encode_state_t t45;
170 #endif
171     } encoder;
172 
173     t4_image_get_handler_t image_get_handler;
174 
175     int apply_lab;
176     lab_params_t lab_params;
177     uint8_t *colour_map;
178     int colour_map_entries;
179 
180     image_translate_state_t translator;
181     uint8_t *pack_buf;
182     int pack_ptr;
183     int pack_row;
184     int pack_bit_mask;
185 
186     no_encoder_state_t no_encoder;
187 
188     /*! \brief Supporting information, like resolutions, which the backend may want. */
189     t4_tx_metadata_t metadata;
190 
191     /*! \brief All TIFF file specific state information for the T.4 context. */
192     t4_tx_tiff_state_t tiff;
193 
194     /*! \brief Error and flow logging control */
195     logging_state_t logging;
196 };
197 
198 #endif
199 /*- End of file ------------------------------------------------------------*/
200