spandsp  0.0.6
private/t4_tx.h
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 #define t4_tx_state_s t4_state_s
30 
31 /*!
32  T.4 FAX compression/decompression descriptor. This defines the working state
33  for a single instance of a T.4 FAX compression or decompression channel.
34 */
35 struct t4_state_s
36 {
37  /*! \brief The same structure is used for T.4 transmit and receive. This variable
38  records which mode is in progress. */
39  int rx;
40 
41  /*! \brief The type of compression used between the FAX machines. */
43 
44  /*! \brief The time at which handling of the current page began. */
46 
47  /*! \brief The text which will be used in FAX page header. No text results
48  in no header line. */
49  const char *header_info;
50  /*! \brief Optional per instance time zone for the FAX page header timestamp. */
51  struct tz_s *tz;
52 
53  /*! \brief The size of the compressed image on the line side, in bits. */
55 
56  /*! \brief The current number of bytes per row of uncompressed image data. */
58  /*! \brief The size of the image in the image buffer, in bytes. */
60  /*! \brief The current size of the image buffer. */
62  /*! \brief A point to the image buffer. */
63  uint8_t *image_buffer;
64 
65  /*! \brief The number of pages transferred to date. */
67  /*! \brief Column-to-column (X) resolution in pixels per metre. */
69  /*! \brief Row-to-row (Y) resolution in pixels per metre. */
71  /*! \brief Width of the current page, in pixels. */
73  /*! \brief Length of the current page, in pixels. */
75  /*! \brief Current pixel row number. */
76  int row;
77 
78  /*! \brief This variable is set if we are treating the current row as a 2D encoded
79  one. */
80  int row_is_2d;
81  /*! \brief The current length of the current row. */
82  int row_len;
83 
84  /*! \brief Black and white run-lengths for the current row. */
85  uint32_t *cur_runs;
86  /*! \brief Black and white run-lengths for the reference row. */
87  uint32_t *ref_runs;
88  /*! \brief Pointer to the buffer for the current pixel row. */
89  uint8_t *row_buf;
90 
91  /*! \brief Encoded data bits buffer. */
92  uint32_t tx_bitstream;
93  /*! \brief The number of bits currently in tx_bitstream. */
94  int tx_bits;
95 
96  /*! \brief The current number of bits in the current encoded row. */
97  int row_bits;
98  /*! \brief The minimum bits in any row of the current page. For monitoring only. */
100  /*! \brief The maximum bits in any row of the current page. For monitoring only. */
102 
103  /*! \brief Error and flow logging control */
105 
106  /*! \brief All TIFF file specific state information for the T.4 context. */
108  t4_t6_decode_state_t t4_t6_rx;
109  t4_t6_encode_state_t t4_t6_tx;
110 };
111 
112 #endif
113 /*- End of file ------------------------------------------------------------*/
t4_stats_t
Definition: t4_rx.h:213
t4_tx_set_min_bits_per_row
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
t4_tx_start_page
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
t4_tx.h
t4_rx_metadata_t::local_ident
const char * local_ident
The local ident string.
Definition: private/t4_rx.h:42
t4_tx_get_chunk
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
t4_tx_get_byte
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
t4_state_s::min_row_bits
int min_row_bits
The minimum bits in any row of the current page. For monitoring only.
Definition: private/t4_tx.h:99
t4_state_s::cur_runs
uint32_t * cur_runs
Black and white run-lengths for the current row.
Definition: private/t4_tx.h:85
t4_state_s::y_resolution
int y_resolution
Row-to-row (Y) resolution in pixels per metre.
Definition: private/t4_tx.h:70
t4_t6_encode_state_s::min_bits_per_row
int min_bits_per_row
The minimum number of encoded bits per row. This is a timing thing for hardware FAX machines.
Definition: private/t4_t6_encode.h:36
t4_state_s::tx_bits
int tx_bits
The number of bits currently in tx_bitstream.
Definition: private/t4_tx.h:94
EOLS_TO_END_T6_TX_PAGE
#define EOLS_TO_END_T6_TX_PAGE
Definition: t4_tx.c:108
t4_tx_get_chunk
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
t4_t6_decode_state_s::longest_bad_row_run
int longest_bad_row_run
The longest run of consecutive bad rows seen in the current page.
Definition: private/t4_t6_decode.h:92
t4_tx_restart_page
int t4_tx_restart_page(t4_tx_state_t *s)
Prepare the current page for a resend.
Definition: t4_tx.c:1347
T4_COMPRESSION_ITU_T85_L0
@ T4_COMPRESSION_ITU_T85_L0
Definition: t4_rx.h:62
t4_tx_set_local_ident
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
t4_t6_encode_state_s::max_rows_to_next_1d_row
int max_rows_to_next_1d_row
The current maximum contiguous rows that may be 2D encoded.
Definition: private/t4_t6_encode.h:38
t4_state_s::image_size
int image_size
The size of the image in the image buffer, in bytes.
Definition: private/t4_tx.h:59
t4_state_s::header_info
const char * header_info
The text which will be used in FAX page header. No text results in no header line.
Definition: private/t4_tx.h:49
t4_stats_t::bad_rows
int bad_rows
The number of bad pixel rows in the most recent page.
Definition: t4_rx.h:223
t4_rx_get_transfer_statistics
void t4_rx_get_transfer_statistics(t4_rx_state_t *s, t4_stats_t *t)
Get the current transfer statistics.
Definition: t4_rx.c:1133
async.h
t4_tx_restart_page
int t4_tx_restart_page(t4_tx_state_t *s)
Prepare the current page for a resend.
Definition: t4_tx.c:1347
t4_state_s::image_width
int image_width
Width of the current page, in pixels.
Definition: private/t4_tx.h:72
t4_state_s::tz
struct tz_s * tz
Optional per instance time zone for the FAX page header timestamp.
Definition: private/t4_tx.h:51
t4_state_s::row_len
int row_len
The current length of the current row.
Definition: private/t4_tx.h:82
t4_rx.h
t4_row_read_handler_t
int(* t4_row_read_handler_t)(void *user_data, uint8_t buf[], size_t len)
Definition: t4_tx.h:36
T4_COMPRESSION_ITU_T85
@ T4_COMPRESSION_ITU_T85
Definition: t4_rx.h:60
t4_tx_init
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
T4_COMPRESSION_ITU_T4_2D
@ T4_COMPRESSION_ITU_T4_2D
Definition: t4_rx.h:56
t4_state_s::row
int row
Current pixel row number.
Definition: private/t4_tx.h:76
t4_tiff_state_t::file
const char * file
The current file name.
Definition: private/t4_rx.h:57
t4_tx_set_tx_encoding
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
t4_state_s::row_buf
uint8_t * row_buf
Pointer to the buffer for the current pixel row.
Definition: private/t4_tx.h:89
t4_rx_start_page
int t4_rx_start_page(t4_rx_state_t *s)
Prepare to receive the next page of the current document.
Definition: t4_rx.c:1010
t4_rx_set_x_resolution
void t4_rx_set_x_resolution(t4_rx_state_t *s, int resolution)
Set the column-to-column (x) resolution to expect for a received image.
Definition: t4_rx.c:1097
t4_tx_set_header_tz
void t4_tx_set_header_tz(t4_tx_state_t *s, struct tz_s *tz)
Set the header timezone.
Definition: t4_tx.c:1435
t4_rx_set_row_write_handler
int t4_rx_set_row_write_handler(t4_rx_state_t *s, t4_row_write_handler_t handler, void *user_data)
Set the row write handler for a T.4 receive context.
Definition: t4_rx.c:1002
t4_tiff_state_t::tiff_file
TIFF * tiff_file
The libtiff context for the current TIFF file.
Definition: private/t4_rx.h:59
t4_tx_get_current_page_in_file
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
t4_tiff_state_t::photo_metric
uint16_t photo_metric
The TIFF photometric setting for the current page.
Definition: private/t4_rx.h:67
t4_tiff_state_t::stop_page
int stop_page
The last page to transfer. -1 to continue to the end of the file.
Definition: private/t4_rx.h:79
t4_state_s::line_encoding
int line_encoding
The type of compression used between the FAX machines.
Definition: private/t4_tx.h:42
t4_state_s::bytes_per_row
int bytes_per_row
The current number of bytes per row of uncompressed image data.
Definition: private/t4_tx.h:57
timezone.h
t4_run_table_entry_t::run_length
int16_t run_length
Definition: t4_tx.c:132
t4_stats_t::pages_transferred
int pages_transferred
The number of pages transferred so far.
Definition: t4_rx.h:215
t4_state_s::image_length
int image_length
Length of the current page, in pixels.
Definition: private/t4_tx.h:74
t4_tx_set_local_ident
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
t4_stats_t::length
int length
The number of vertical pixels in the most recent page.
Definition: t4_rx.h:221
t4_tiff_state_t::fill_order
uint16_t fill_order
The TIFF fill order setting for the current page.
Definition: private/t4_rx.h:69
t4_run_table_entry_t::code
uint16_t code
Definition: t4_tx.c:130
t4_tx_init
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
t4_rx_put_byte
int t4_rx_put_byte(t4_rx_state_t *s, uint8_t byte)
Put a byte of the current document page.
Definition: t4_rx.c:981
t4_tx_get_x_resolution
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
t4_state_s::row_bits
int row_bits
The current number of bits in the current encoded row.
Definition: private/t4_tx.h:97
t4_run_table_entry_t
Definition: t4_tx.c:126
t4_stats_t::width
int width
The number of horizontal pixels in the most recent page.
Definition: t4_rx.h:219
T4_COMPRESSION_ITU_T43
@ T4_COMPRESSION_ITU_T43
Definition: t4_rx.h:64
CM_PER_INCH
#define CM_PER_INCH
Definition: t4_tx.c:103
t4_t6_encode_state_s
Definition: private/t4_t6_encode.h:33
t4_state_s
Definition: private/t4_tx.h:36
t4_tx_get_pages_in_file
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
t4_t6_encode_state_s::bit_pos
int bit_pos
Pointer to the byte containing the next image bit to transmit.
Definition: private/t4_t6_encode.h:48
t4_t6_encode.h
t4_tx_get_x_resolution
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
t4_state_s::current_page
int current_page
The number of pages transferred to date.
Definition: private/t4_tx.h:66
t4_tiff_state_t::start_page
int start_page
The first page to transfer. -1 to start at the beginning of the file.
Definition: private/t4_rx.h:77
t4_tx_check_bit
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
t4_tx_get_byte
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
tz_s
Definition: private/timezone.h:82
t4_stats_t::pages_in_file
int pages_in_file
The number of pages in the file (<0 if unknown).
Definition: t4_rx.h:217
t4_state_s::max_row_bits
int max_row_bits
The maximum bits in any row of the current page. For monitoring only.
Definition: private/t4_tx.h:101
t4_t6_decode.h
t4_t6_encode_state_s::ref_steps
int ref_steps
The number of runs currently in the reference row.
Definition: private/t4_t6_encode.h:45
t4_t6_decode_state_s::bad_rows
int bad_rows
The total number of bad rows in the current page.
Definition: private/t4_t6_decode.h:94
t4_tx_release
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_rx_put_bit
int t4_rx_put_bit(t4_rx_state_t *s, int bit)
Put a bit of the current document page.
Definition: t4_rx.c:975
bit_operations.h
T4_COMPRESSION_ITU_T42
@ T4_COMPRESSION_ITU_T42
Definition: t4_rx.h:68
t4_tx_end_page
int t4_tx_end_page(t4_tx_state_t *s)
Complete the sending of a page.
Definition: t4_tx.c:1355
t4_tx_set_header_tz
void t4_tx_set_header_tz(t4_tx_state_t *s, tz_t *tz)
Set the header timezone.
Definition: t4_tx.c:1435
t4_rx_end_page
int t4_rx_end_page(t4_rx_state_t *s)
Complete the reception of a page.
Definition: t4_rx.c:581
t4_t6_decode_state_s
Definition: private/t4_t6_decode.h:33
EOLS_TO_END_T4_TX_PAGE
#define EOLS_TO_END_T4_TX_PAGE
Definition: t4_tx.c:106
t4_state_s::row_is_2d
int row_is_2d
This variable is set if we are treating the current row as a 2D encoded one.
Definition: private/t4_tx.h:80
t4_state_s::rx
int rx
The same structure is used for T.4 transmit and receive. This variable records which mode is in progr...
Definition: private/t4_tx.h:39
t4_tx_get_bit
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
span_log
int span_log(logging_state_t *s, int level, const char *format,...)
Generate a log entry.
Definition: logging.c:84
t4_tx_end_page
int t4_tx_end_page(t4_tx_state_t *s)
Complete the sending of a page.
Definition: t4_tx.c:1355
t4_state_s::ref_runs
uint32_t * ref_runs
Black and white run-lengths for the reference row.
Definition: private/t4_tx.h:87
t4_t6_encode_state_s::rows_to_next_1d_row
int rows_to_next_1d_row
Number of rows left that can be 2D encoded, before a 1D encoded row must be used.
Definition: private/t4_t6_encode.h:42
T4_COMPRESSION_ITU_T6
@ T4_COMPRESSION_ITU_T6
Definition: t4_rx.h:58
t4_tx_start_page
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
t4_tx_get_y_resolution
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
t4_tx_set_header_info
void t4_tx_set_header_info(t4_tx_state_t *s, const char *info)
Set the header info.
Definition: t4_tx.c:1429
t4_state_s::tx_bitstream
uint32_t tx_bitstream
Encoded data bits buffer.
Definition: private/t4_tx.h:92
t4_rx_init
t4_rx_state_t * t4_rx_init(t4_rx_state_t *s, const char *file, int output_encoding)
Prepare for reception of a document.
Definition: t4_rx.c:1177
t4_tx_get_bit
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
t4_tiff_state_t::pages_in_file
int pages_in_file
The number of pages in the current image file.
Definition: private/t4_rx.h:74
T4_COMPRESSION_ITU_SYCC_T42
@ T4_COMPRESSION_ITU_SYCC_T42
Definition: t4_rx.h:70
t4_state_s::x_resolution
int x_resolution
Column-to-column (X) resolution in pixels per metre.
Definition: private/t4_tx.h:68
t4_state_s::image_buffer_size
int image_buffer_size
The current size of the image buffer.
Definition: private/t4_tx.h:61
t4_stats_t::longest_bad_row_run
int longest_bad_row_run
The largest number of bad pixel rows in a block in the most recent page.
Definition: t4_rx.h:225
t4_tx_get_transfer_statistics
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
t4_state_s::logging
logging_state_t logging
Error and flow logging control.
Definition: private/t4_tx.h:104
t4_encoding_to_str
const char * t4_encoding_to_str(int encoding)
Get the short text name of an encoding format.
Definition: t4_rx.c:1148
t4_stats_t::encoding
int encoding
The type of compression used between the FAX machines.
Definition: t4_rx.h:231
t4_stats_t::x_resolution
int x_resolution
The horizontal resolution of the page in pixels per metre.
Definition: t4_rx.h:227
t4_tx_release
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_state_s::line_image_size
int line_image_size
The size of the compressed image on the line side, in bits.
Definition: private/t4_tx.h:54
logging.h
t4_tx_get_y_resolution
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
t4_tx_set_header_info
void t4_tx_set_header_info(t4_tx_state_t *s, const char *info)
Set the header info.
Definition: t4_tx.c:1429
t4_tiff_state_t
Definition: private/t4_rx.h:55
t4_state_s::tiff
t4_tiff_state_t tiff
All TIFF file specific state information for the T.4 context.
Definition: private/t4_tx.h:107
t4_state_s::image_buffer
uint8_t * image_buffer
A point to the image buffer.
Definition: private/t4_tx.h:63
t4_rx_set_y_resolution
void t4_rx_set_y_resolution(t4_rx_state_t *s, int resolution)
Set the row-to-row (y) resolution to expect for a received image.
Definition: t4_rx.c:1091
t4_tx_next_page_has_different_format
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
t4_tx_set_row_read_handler
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
t4_rx_set_image_width
void t4_rx_set_image_width(t4_rx_state_t *s, int width)
Set the expected width of the received image, in pixel columns.
Definition: t4_rx.c:1085
t4_tx_get_image_width
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
bit_reverse
void bit_reverse(uint8_t to[], const uint8_t from[], int len)
Bit reverse each byte in a buffer.
Definition: bit_operations.c:79
t4_rx_put_chunk
int t4_rx_put_chunk(t4_rx_state_t *s, const uint8_t buf[], int len)
Put a byte of the current document page.
Definition: t4_rx.c:987
t4_tx_set_row_read_handler
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
t4_rx_set_rx_encoding
void t4_rx_set_rx_encoding(t4_rx_state_t *s, int encoding)
Set the encoding for the received data.
Definition: t4_rx.c:1079
t4_tx_get_image_width
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
t4_t6_encode_state_s::row_read_user_data
void * row_read_user_data
Opaque pointer passed to row_read_handler.
Definition: private/t4_t6_encode.h:55
t4_tx_set_tx_encoding
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
t4_tx_set_min_bits_per_row
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
t4_stats_t::y_resolution
int y_resolution
The vertical resolution of the page in pixels per metre.
Definition: t4_rx.h:229
t4_run_table_entry_t::length
uint16_t length
Definition: t4_tx.c:128
T4_COMPRESSION_ITU_T4_1D
@ T4_COMPRESSION_ITU_T4_1D
Definition: t4_rx.h:54
t4_tx_free
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
logging_state_s
Definition: private/logging.h:34
t4_rx_release
int t4_rx_release(t4_rx_state_t *s)
End reception of a document. Tidy up and close the file. This should be used to end T....
Definition: t4_rx.c:1235
t4_t6_encode_state_s::row_read_handler
t4_row_read_handler_t row_read_handler
Callback function to read a row of pixels from the image source.
Definition: private/t4_t6_encode.h:53
t4_t6_encode_state_s::bit_ptr
int bit_ptr
Pointer to the bit within the byte containing the next image bit to transmit.
Definition: private/t4_t6_encode.h:50
SIG_STATUS_END_OF_DATA
@ SIG_STATUS_END_OF_DATA
The data stream has ended.
Definition: async.h:71
t4_stats_t::line_image_size
int line_image_size
The size of the image on the line, in bytes.
Definition: t4_rx.h:233
t4_state_s::page_start_time
time_t page_start_time
The time at which handling of the current page began.
Definition: private/t4_tx.h:45