spandsp  0.0.6
t4_tx.h
Go to the documentation of this file.
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * 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 /*! \file */
27 
28 #if !defined(_SPANDSP_T4_TX_H_)
29 #define _SPANDSP_T4_TX_H_
30 
31 //#define SPANDSP_SUPPORT_TIFF_FX
32 
33 /*! This function is a callback from the image decoders, to read the unencoded bi-level image,
34  row by row. It is called for each row, with len set to the number of bytes per row expected.
35  \return len for OK, or zero to indicate the end of the image data. */
36 typedef int (*t4_row_read_handler_t)(void *user_data, uint8_t buf[], size_t len);
37 
38 #if defined(SPANDSP_SUPPORT_TIFF_FX)
39 /* TIFF-FX related extensions to the tag set supported by libtiff */
40 
41 /*
42 Indexed(346) = 0, 1. SHORT
43  0: not a palette-color image.
44  1: palette-color image.
45  This field is used to indicate that each sample value is an index
46  into an array of color values specified in the image data stream.
47  Because the color map is embedded in the image data stream, the
48  ColorMap field is not used in Profile L. Lossless color fax
49  profile supports palette-color images with the ITULAB encoding.
50  The SamplesPerPixel value must be 1.
51 
52 GlobalParametersIFD (400) IFD
53  An IFD containing global parameters. It is recommended that a TIFF
54  writer place this field in the first IFD, where a TIFF reader would
55  find it quickly.
56 
57  Each field in the GlobalParametersIFD is a TIFF field that is legal
58  in any IFD. Required baseline fields should not be located in the
59  GlobalParametersIFD, but should be in each image IFD. If a conflict
60  exists between fields in the GlobalParametersIFD and in the image
61  IFDs, then the data in the image IFD shall prevail.
62 
63  Among the GlobalParametersIFD entries is a new ProfileType field
64  which generally describes information in this IFD and in the TIFF
65  file.
66 
67 ProfileType(401) LONG
68  The type of image data stored in this IFD.
69  0 = Unspecified
70  1 = Group 3 fax
71  No default
72 
73  The following new global fields are defined in this document as IFD
74  entries for use with fax applications.
75 
76 FaxProfile(402) = 0 - 6. BYTE
77  The profile that applies to this file; a profile is subset of the
78  full set of permitted fields and field values of TIFF for facsimile.
79  The currently defined values are:
80  0: does not conform to a profile defined for TIFF for facsimile
81  1: minimal black & white lossless, Profile S
82  2: extended black & white lossless, Profile F
83  3: lossless JBIG black & white, Profile J
84  4: lossy color and grayscale, Profile C
85  5: lossless color and grayscale, Profile L
86  6: Mixed Raster Content, Profile M
87 
88 CodingMethods(403) LONG
89  This field indicates which coding methods are used in the file. A
90  bit value of 1 indicates which of the following coding methods is
91  used:
92  Bit 0: unspecified compression,
93  Bit 1: 1-dimensional coding, ITU-T Rec. T.4 (MH - Modified Huffman),
94  Bit 2: 2-dimensional coding, ITU-T Rec. T.4 (MR - Modified Read),
95  Bit 3: 2-dimensional coding, ITU-T Rec. T.6 (MMR - Modified MR),
96  Bit 4: ITU-T Rec. T.82 coding, using ITU-T Rec. T.85 (JBIG),
97  Bit 5: ITU-T Rec. T.81 (Baseline JPEG),
98  Bit 6: ITU-T Rec. T.82 coding, using ITU-T Rec. T.43 (JBIG color),
99  Bits 7-31: reserved for future use
100  Note: There is a limit of 32 compression types to identify standard
101  compression methods.
102 
103 VersionYear(404) BYTE
104  Count: 4
105  The year of the standard specified by the FaxProfile field, given as
106  4 characters, e.g. '1997'; used in lossy and lossless color modes.
107 
108 ModeNumber (405) BYTE
109  The mode of the standard specified by the FaxProfile field. A
110  value of 0 indicates Mode 1.0; used in Mixed Raster Content mode.
111 
112 Decode(433) SRATIONAL
113  Count = 2 * SamplesPerPixel
114  Describes how to map image sample values into the range of values
115  appropriate for the current color space. In general, the values
116  are taken in pairs and specify the minimum and maximum output
117  value for each color component. For the base color fax profile,
118  Decode has a count of 6 values and maps the unsigned ITULAB-
119  encoded sample values (Lsample, asample, bsample) to signed L*a*b*
120  values, as follows:
121  L* = Decode[0] + Lsample x (Decode[1]-Decode[0])/(2^n -1)
122  a* = Decode[2] + asample x (Decode[3]-Decode[2])/(2^n -1)
123  b* = Decode[4] + bsample x (Decode[5]-Decode[4])/(2^n -1)
124  where Decode[0], Decode[2] and Decode[4] are the minimum values
125  for L*, a*, and b*; Decode[1], Decode[3] and Decode[5] are the
126  maximum values for L*, a*, and b*; and n is the BitsPerSample.
127  When n=8,=20 L*=Decode[0] when Lsample=0 and L*=Decode[1] when
128  Lsample=255.
129 
130 ImageBaseColor(434) SHORT
131  Count = SamplesPerPixel
132  In areas of an image layer where no image data is available (i.e.,
133  where no strips are defined, or where the StripByteCounts entry for
134  a given strip is 0), the color specified by ImageBaseColor will be
135  used.
136 
137 StripRowCounts(559) LONG
138  Count = number of strips.
139  The number of scanlines stored in a strip. Profile M allows each
140  fax strip to store a different number of scanlines. For strips
141  with more than one layer, the maximum strip size is either 256
142  scanlines or full page size. The 256 maximum SHOULD be used
143  unless the capability to receive longer strips has been
144  negotiated. This field replaces RowsPerStrip for IFDs with
145  variable-size strips. Only one of the two fields, StripRowCounts
146  and RowsPerStrip, may be used in an IFD.
147 
148 ImageLayer(34732) LONG
149  Count = 2.
150  Image layers are defined such that layer 1 is the Background
151  layer, layer 3 is the Foreground layer, and layer 2 is the Mask
152  layer, which selects pixels from the Background and Foreground
153  layers. The ImageLayer tag contains two values, which describe
154  the layer to which the image belongs and the order in which it is
155  imaged.
156 
157  ImageLayer[0] = 1, 2, 3.
158  1: Image is a Background image, i.e. the image that will appear
159  whenever the Mask contains a value of 0. Background images
160  typically contain low-resolution, continuous-tone imagery.
161  2: Image is the Mask layer. In MRC, if the Mask layer is present,
162  it must be the Primary IFD and be full page in extent.
163  3: Image is a Foreground image, i.e. the image that will appear
164  whenever the Mask contains a value of 1. The Foreground image
165  generally defines the color of text or lines but may also
166  contain high-resolution imagery.
167 
168  ImageLayer[1]:
169  1: first image to be imaged in this layer
170  2: second image to be imaged in this layer
171  3: ...
172 */
173 
174 #define TIFFTAG_INDEXED 346
175 #define TIFFTAG_GLOBALPARAMETERSIFD 400
176 #define TIFFTAG_PROFILETYPE 401
177 #define PROFILETYPE_UNSPECIFIED 0
178 #define PROFILETYPE_G3_FAX 1
179 #define TIFFTAG_FAXPROFILE 402
180 #define FAXPROFILE_S 1
181 #define FAXPROFILE_F 2
182 #define FAXPROFILE_J 3
183 #define FAXPROFILE_C 4
184 #define FAXPROFILE_L 5
185 #define FAXPROFILE_M 6
186 #define TIFFTAG_CODINGMETHODS 403
187 #define CODINGMETHODS_T4_1D (1 << 1)
188 #define CODINGMETHODS_T4_2D (1 << 2)
189 #define CODINGMETHODS_T6 (1 << 3)
190 #define CODINGMETHODS_T85 (1 << 4)
191 #define CODINGMETHODS_T42 (1 << 5)
192 #define CODINGMETHODS_T43 (1 << 6)
193 #define TIFFTAG_VERSIONYEAR 404
194 #define TIFFTAG_MODENUMBER 405
195 #define TIFFTAG_DECODE 433
196 #define TIFFTAG_IMAGEBASECOLOR 434
197 #define TIFFTAG_T82OPTIONS 435
198 #define TIFFTAG_STRIPROWCOUNTS 559
199 #define TIFFTAG_IMAGELAYER 34732
200 
201 #define COMPRESSION_T85 9
202 #define COMPRESSION_T43 10
203 #endif
204 
205 typedef struct t4_state_s t4_tx_state_t;
206 
207 #if defined(__cplusplus)
208 extern "C" {
209 #endif
210 
211 /*! \brief Prepare to send the next page of the current document.
212  \param s The T.4 context.
213  \return zero for success, -1 for failure. */
214 SPAN_DECLARE(int) t4_tx_start_page(t4_tx_state_t *s);
215 
216 /*! \brief Prepare the current page for a resend.
217  \param s The T.4 context.
218  \return zero for success, -1 for failure. */
219 SPAN_DECLARE(int) t4_tx_restart_page(t4_tx_state_t *s);
220 
221 /*! \brief Check for the existance of the next page, and whether its format is like the
222  current one. This information can be needed before it is determined that the current
223  page is finished with.
224  \param s The T.4 context.
225  \return 0 for next page found with the same format as the current page.
226  1 for next page found with different format from the current page.
227  -1 for no page found, or file failure. */
229 
230 /*! \brief Complete the sending of a page.
231  \param s The T.4 context.
232  \return zero for success, -1 for failure. */
233 SPAN_DECLARE(int) t4_tx_end_page(t4_tx_state_t *s);
234 
235 /*! \brief Return the next bit of the current document page, without actually
236  moving forward in the buffer. The document will be padded for the
237  current minimum scan line time.
238  \param s The T.4 context.
239  \return The next bit (i.e. 0 or 1). For the last bit of data, bit 1 is
240  set (i.e. the returned value is 2 or 3). */
241 SPAN_DECLARE(int) t4_tx_check_bit(t4_tx_state_t *s);
242 
243 /*! \brief Get the next bit of the current document page. The document will
244  be padded for the current minimum scan line time.
245  \param s The T.4 context.
246  \return The next bit (i.e. 0 or 1). For the last bit of data, bit 1 is
247  set (i.e. the returned value is 2 or 3). */
248 SPAN_DECLARE(int) t4_tx_get_bit(t4_tx_state_t *s);
249 
250 /*! \brief Get the next byte of the current document page. The document will
251  be padded for the current minimum scan line time.
252  \param s The T.4 context.
253  \return The next byte. For the last byte of data, bit 8 is
254  set. In this case, one or more bits of the byte may be padded with
255  zeros, to complete the byte. */
256 SPAN_DECLARE(int) t4_tx_get_byte(t4_tx_state_t *s);
257 
258 /*! \brief Get the next chunk of the current document page. The document will
259  be padded for the current minimum scan line time.
260  \param s The T.4 context.
261  \param buf The buffer into which the chunk is to written.
262  \param max_len The maximum length of the chunk.
263  \return The actual length of the chunk. If this is less than max_len it
264  indicates that the end of the document has been reached. */
265 SPAN_DECLARE(int) t4_tx_get_chunk(t4_tx_state_t *s, uint8_t buf[], int max_len);
266 
267 /*! \brief Set the encoding for the encoded data.
268  \param s The T.4 context.
269  \param encoding The encoding. */
270 SPAN_DECLARE(void) t4_tx_set_tx_encoding(t4_tx_state_t *s, int encoding);
271 
272 /*! \brief Set the minimum number of encoded bits per row. This allows the
273  makes the encoding process to be set to comply with the minimum row
274  time specified by a remote receiving machine.
275  \param s The T.4 context.
276  \param bits The minimum number of bits per row. */
277 SPAN_DECLARE(void) t4_tx_set_min_bits_per_row(t4_tx_state_t *s, int bits);
278 
279 /*! \brief Set the identity of the local machine, for inclusion in page headers.
280  \param s The T.4 context.
281  \param ident The identity string. */
282 SPAN_DECLARE(void) t4_tx_set_local_ident(t4_tx_state_t *s, const char *ident);
283 
284 /*! Set the info field, included in the header line included in each page of an encoded
285  FAX. This is a string of up to 50 characters. Other information (date, local ident, etc.)
286  are automatically included in the header. If the header info is set to NULL or a zero
287  length string, no header lines will be added to the encoded FAX.
288  \brief Set the header info.
289  \param s The T.4 context.
290  \param info A string, of up to 50 bytes, which will form the info field. */
291 SPAN_DECLARE(void) t4_tx_set_header_info(t4_tx_state_t *s, const char *info);
292 
293 /*! Set the time zone for the time stamp in page header lines. If this function is not used
294  the current time zone of the program's environment is used.
295  \brief Set the header timezone.
296  \param s The T.4 context.
297  \param tz A time zone descriptor. */
298 SPAN_DECLARE(void) t4_tx_set_header_tz(t4_tx_state_t *s, tz_t *tz);
299 
300 /*! \brief Set the row read handler for a T.4 transmit context.
301  \param s The T.4 transmit context.
302  \param handler A pointer to the handler routine.
303  \param user_data An opaque pointer passed to the handler routine.
304  \return 0 for success, otherwise -1. */
305 SPAN_DECLARE(int) t4_tx_set_row_read_handler(t4_tx_state_t *s, t4_row_read_handler_t handler, void *user_data);
306 
307 /*! \brief Get the row-to-row (y) resolution of the current page.
308  \param s The T.4 context.
309  \return The resolution, in pixels per metre. */
310 SPAN_DECLARE(int) t4_tx_get_y_resolution(t4_tx_state_t *s);
311 
312 /*! \brief Get the column-to-column (x) resolution of the current page.
313  \param s The T.4 context.
314  \return The resolution, in pixels per metre. */
315 SPAN_DECLARE(int) t4_tx_get_x_resolution(t4_tx_state_t *s);
316 
317 /*! \brief Get the width of the current page, in pixel columns.
318  \param s The T.4 context.
319  \return The number of columns. */
320 SPAN_DECLARE(int) t4_tx_get_image_width(t4_tx_state_t *s);
321 
322 /*! \brief Get the number of pages in the file.
323  \param s The T.4 context.
324  \return The number of pages, or -1 if there is an error. */
325 SPAN_DECLARE(int) t4_tx_get_pages_in_file(t4_tx_state_t *s);
326 
327 /*! \brief Get the currnet page number in the file.
328  \param s The T.4 context.
329  \return The page number, or -1 if there is an error. */
330 SPAN_DECLARE(int) t4_tx_get_current_page_in_file(t4_tx_state_t *s);
331 
332 /*! Get the current image transfer statistics.
333  \brief Get the current transfer statistics.
334  \param s The T.4 context.
335  \param t A pointer to a statistics structure. */
336 SPAN_DECLARE(void) t4_tx_get_transfer_statistics(t4_tx_state_t *s, t4_stats_t *t);
337 
338 /*! \brief Prepare for transmission of a document.
339  \param s The T.4 context.
340  \param file The name of the file to be sent.
341  \param start_page The first page to send. -1 for no restriction.
342  \param stop_page The last page to send. -1 for no restriction.
343  \return A pointer to the context, or NULL if there was a problem. */
344 SPAN_DECLARE(t4_tx_state_t *) t4_tx_init(t4_tx_state_t *s, const char *file, int start_page, int stop_page);
345 
346 /*! \brief End the transmission of a document. Tidy up and close the file.
347  This should be used to end T.4 transmission started with t4_tx_init.
348  \param s The T.4 context.
349  \return 0 for success, otherwise -1. */
350 SPAN_DECLARE(int) t4_tx_release(t4_tx_state_t *s);
351 
352 /*! \brief End the transmission of a document. Tidy up, close the file and
353  free the context. This should be used to end T.4 transmission
354  started with t4_tx_init.
355  \param s The T.4 context.
356  \return 0 for success, otherwise -1. */
357 SPAN_DECLARE(int) t4_tx_free(t4_tx_state_t *s);
358 
359 #if defined(__cplusplus)
360 }
361 #endif
362 
363 #endif
364 /*- End of file ------------------------------------------------------------*/
int t4_tx_get_image_width(t4_tx_state_t *s)
Get the width of the current page, in pixel columns.
Definition: t4_tx.c:1453
int t4_tx_free(t4_tx_state_t *s)
End the transmission of a document. Tidy up, close the file and free the context. This should be used...
Definition: t4_tx.c:1585
Definition: t4_rx.h:212
int t4_tx_start_page(t4_tx_state_t *s)
Prepare to send the next page of the current document.
Definition: t4_tx.c:1221
int t4_tx_release(t4_tx_state_t *s)
End the transmission of a document. Tidy up and close the file. This should be used to end T...
Definition: t4_tx.c:1574
t4_tx_state_t * t4_tx_init(t4_tx_state_t *s, const char *file, int start_page, int stop_page)
Prepare for transmission of a document.
Definition: t4_tx.c:1493
int t4_tx_restart_page(t4_tx_state_t *s)
Prepare the current page for a resend.
Definition: t4_tx.c:1347
void t4_tx_set_local_ident(t4_tx_state_t *s, const char *ident)
Set the identity of the local machine, for inclusion in page headers.
Definition: t4_tx.c:1423
int t4_tx_get_byte(t4_tx_state_t *s)
Get the next byte of the current document page. The document will be padded for the current minimum s...
Definition: t4_tx.c:1378
void t4_tx_set_tx_encoding(t4_tx_state_t *s, int encoding)
Set the encoding for the encoded data.
Definition: t4_tx.c:1409
struct tz_s * tz
Optional per instance time zone for the FAX page header timestamp.
Definition: private/t4_tx.h:51
void t4_tx_set_header_tz(t4_tx_state_t *s, tz_t *tz)
Set the header timezone.
Definition: t4_tx.c:1435
void t4_tx_set_header_info(t4_tx_state_t *s, const char *info)
Set the header info.
Definition: t4_tx.c:1429
int t4_tx_end_page(t4_tx_state_t *s)
Complete the sending of a page.
Definition: t4_tx.c:1355
Definition: private/timezone.h:81
void t4_tx_set_min_bits_per_row(t4_tx_state_t *s, int bits)
Set the minimum number of encoded bits per row. This allows the makes the encoding process to be set ...
Definition: t4_tx.c:1417
int t4_tx_get_pages_in_file(t4_tx_state_t *s)
Get the number of pages in the file.
Definition: t4_tx.c:1459
int t4_tx_check_bit(t4_tx_state_t *s)
Return the next bit of the current document page, without actually moving forward in the buffer...
Definition: t4_tx.c:1398
int t4_tx_get_chunk(t4_tx_state_t *s, uint8_t buf[], int max_len)
Get the next chunk of the current document page. The document will be padded for the current minimum ...
Definition: t4_tx.c:1386
int t4_tx_next_page_has_different_format(t4_tx_state_t *s)
Check for the existance of the next page, and whether its format is like the current one...
Definition: t4_tx.c:1328
int t4_tx_get_current_page_in_file(t4_tx_state_t *s)
Get the currnet page number in the file.
Definition: t4_tx.c:1472
void t4_tx_get_transfer_statistics(t4_tx_state_t *s, t4_stats_t *t)
Get the current transfer statistics.
Definition: t4_tx.c:1478
int t4_tx_get_bit(t4_tx_state_t *s)
Get the next bit of the current document page. The document will be padded for the current minimum sc...
Definition: t4_tx.c:1362
int t4_tx_get_x_resolution(t4_tx_state_t *s)
Get the column-to-column (x) resolution of the current page.
Definition: t4_tx.c:1447
int t4_tx_set_row_read_handler(t4_tx_state_t *s, t4_row_read_handler_t handler, void *user_data)
Set the row read handler for a T.4 transmit context.
Definition: t4_tx.c:1213
Definition: private/t4_tx.h:35
int(* t4_row_read_handler_t)(void *user_data, uint8_t buf[], size_t len)
Definition: t4_tx.h:36
int t4_tx_get_y_resolution(t4_tx_state_t *s)
Get the row-to-row (y) resolution of the current page.
Definition: t4_tx.c:1441