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