#include <stdlib.h>
#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include <memory.h>
#include <string.h>
#include "floating_fudge.h"
#include <tiffio.h>
#include "spandsp/telephony.h"
#include "spandsp/logging.h"
#include "spandsp/bit_operations.h"
#include "spandsp/async.h"
#include "spandsp/t4.h"
#include "faxfont.h"
#include "t4_states.h"
Classes | |
struct | t4_table_entry_t |
struct | t4_run_table_entry_t |
Defines | |
#define | CM_PER_INCH 2.54f |
#define | STATE_TRACE(...) |
#define | pixel_is_black(x, bit) (((x)[(bit) >> 3] << ((bit) & 7)) & 0x80) |
Enumerations | |
enum | { S_Null = 0, S_Pass = 1, S_Horiz = 2, S_Vert = 3, S_Ext = 4, S_TermW = 5, S_TermB = 6, S_MakeUpW = 7, S_MakeUpB = 8, S_MakeUp = 9, S_EOL = 10 } |
Functions | |
int | t4_rx_end_page (t4_state_t *s) |
Complete the reception of a page. | |
int | t4_rx_put_bit (t4_state_t *s, int bit) |
Put a bit of the current document page. | |
int | t4_rx_put_byte (t4_state_t *s, uint8_t byte) |
Put a byte of the current document page. | |
int | t4_rx_put_chunk (t4_state_t *s, const uint8_t buf[], int len) |
Put a byte of the current document page. | |
int | t4_rx_set_row_write_handler (t4_state_t *s, t4_row_write_handler_t handler, void *user_data) |
t4_state_t * | t4_rx_init (t4_state_t *s, const char *file, int output_encoding) |
Prepare for reception of a document. | |
int | t4_rx_start_page (t4_state_t *s) |
Prepare to receive the next page of the current document. | |
int | t4_rx_delete (t4_state_t *s) |
End reception of a document. Tidy up, close the file and free the context. This should be used to end T.4 reception started with t4_rx_init. | |
int | t4_rx_end (t4_state_t *s) |
End reception of a document. Tidy up and close the file. This should be used to end T.4 reception started with t4_rx_init. | |
void | t4_rx_set_rx_encoding (t4_state_t *s, int encoding) |
Set the encoding for the received data. | |
void | t4_rx_set_image_width (t4_state_t *s, int width) |
Set the expected width of the received image, in pixel columns. | |
void | t4_rx_set_y_resolution (t4_state_t *s, int resolution) |
Set the row-to-row (y) resolution to expect for a received image. | |
void | t4_rx_set_x_resolution (t4_state_t *s, int resolution) |
Set the column-to-column (x) resolution to expect for a received image. | |
void | t4_rx_set_dcs (t4_state_t *s, const char *dcs) |
Set the DCS information of the fax, for inclusion in the file. | |
void | t4_rx_set_sub_address (t4_state_t *s, const char *sub_address) |
Set the sub-address of the fax, for inclusion in the file. | |
void | t4_rx_set_far_ident (t4_state_t *s, const char *ident) |
Set the identity of the remote machine, for inclusion in the file. | |
void | t4_rx_set_vendor (t4_state_t *s, const char *vendor) |
Set the vendor of the remote machine, for inclusion in the file. | |
void | t4_rx_set_model (t4_state_t *s, const char *model) |
Set the model of the remote machine, for inclusion in the file. | |
int | t4_tx_set_row_read_handler (t4_state_t *s, t4_row_read_handler_t handler, void *user_data) |
t4_state_t * | t4_tx_init (t4_state_t *s, const char *file, int start_page, int stop_page) |
Prepare for transmission of a document. | |
int | t4_tx_start_page (t4_state_t *s) |
Prepare to send the next page of the current document. | |
int | t4_tx_more_pages (t4_state_t *s) |
Check for the existance of the next page. This information can be needed before it is determined that the current page is finished with. | |
int | t4_tx_restart_page (t4_state_t *s) |
Prepare the current page for a resend. | |
int | t4_tx_end_page (t4_state_t *s) |
Complete the sending of a page. | |
int | t4_tx_get_bit (t4_state_t *s) |
Get the next bit of the current document page. The document will be padded for the current minimum scan line time. If the file does not contain an RTC (return to control) code at the end of the page, one will be added where appropriate. | |
int | t4_tx_get_byte (t4_state_t *s) |
Get the next byte of the current document page. The document will be padded for the current minimum scan line time. If the file does not contain an RTC (return to control) code at the end of the page, one will be added where appropriate. | |
int | t4_tx_get_chunk (t4_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 scan line time. If the file does not contain an RTC (return to control) code at the end of the page, one will be added where appropriate. | |
int | t4_tx_check_bit (t4_state_t *s) |
Return the next bit of the current document page, without actually moving forward in the buffer. The document will be padded for the current minimum scan line time. If the file does not contain an RTC (return to control) code at the end of the page, one will be added. | |
int | t4_tx_delete (t4_state_t *s) |
End the transmission of a document. Tidy up, close the file and free the context. This should be used to end T.4 transmission started with t4_tx_init. | |
int | t4_tx_end (t4_state_t *s) |
End the transmission of a document. Tidy up and close the file. This should be used to end T.4 transmission started with t4_tx_init. | |
void | t4_tx_set_tx_encoding (t4_state_t *s, int encoding) |
Set the encoding for the encoded data. | |
void | t4_tx_set_min_row_bits (t4_state_t *s, int bits) |
Set the minimum number of encoded bits per row. This allows the makes the encoding process to be set to comply with the minimum row time specified by a remote receiving machine. | |
void | t4_tx_set_local_ident (t4_state_t *s, const char *ident) |
Set the identity of the local machine, for inclusion in page headers. | |
void | t4_tx_set_header_info (t4_state_t *s, const char *info) |
Set the header info. | |
int | t4_tx_get_y_resolution (t4_state_t *s) |
Get the row-to-row (y) resolution of the current page. | |
int | t4_tx_get_x_resolution (t4_state_t *s) |
Get the column-to-column (x) resolution of the current page. | |
int | t4_tx_get_image_width (t4_state_t *s) |
Get the width of the current page, in pixel columns. | |
int | t4_tx_get_pages_in_file (t4_state_t *s) |
Get the number of pages in the file. | |
void | t4_get_transfer_statistics (t4_state_t *s, t4_stats_t *t) |
Get the current transfer statistics. | |
const char * | t4_encoding_to_str (int encoding) |
Get the short text name of an encoding format. |
const char* t4_encoding_to_str | ( | int | encoding | ) |
Get the short text name of an encoding format.
Get the short text name of an encoding format.
encoding | The encoding type. |
void t4_get_transfer_statistics | ( | t4_state_t * | s, | |
t4_stats_t * | t | |||
) |
Get the current transfer statistics.
Get the current image transfer statistics.
s | The T.4 context. | |
t | A pointer to a statistics structure. |
References t4_state_t::bad_rows, t4_stats_t::bad_rows, t4_stats_t::encoding, t4_state_t::image_length, t4_state_t::image_width, t4_stats_t::length, t4_state_t::line_encoding, t4_state_t::line_image_size, t4_stats_t::line_image_size, t4_state_t::longest_bad_row_run, t4_stats_t::longest_bad_row_run, t4_state_t::pages_in_file, t4_stats_t::pages_in_file, t4_state_t::pages_transferred, t4_stats_t::pages_transferred, t4_state_t::start_page, t4_stats_t::width, t4_state_t::x_resolution, t4_stats_t::x_resolution, t4_state_t::y_resolution, and t4_stats_t::y_resolution.
Referenced by t30_get_transfer_statistics().
int t4_rx_delete | ( | t4_state_t * | s | ) |
End reception of a document. Tidy up, close the file and free the context. This should be used to end T.4 reception started with t4_rx_init.
s | The T.4 receive context. |
References t4_rx_end().
int t4_rx_end | ( | t4_state_t * | s | ) |
End reception of a document. Tidy up and close the file. This should be used to end T.4 reception started with t4_rx_init.
s | The T.4 context. |
References t4_state_t::rx, and t4_state_t::tiff_file.
Referenced by t30_release(), and t4_rx_delete().
int t4_rx_end_page | ( | t4_state_t * | s | ) |
Complete the reception of a page.
s | The T.4 receive context. |
References t4_state_t::bytes_per_row, t4_state_t::consecutive_eols, t4_state_t::curr_bad_row_run, t4_state_t::file, t4_state_t::image_buffer, t4_state_t::image_length, t4_state_t::image_size, t4_state_t::line_encoding, t4_state_t::logging, t4_state_t::longest_bad_row_run, t4_state_t::row_write_handler, t4_state_t::row_write_user_data, t4_state_t::rx_bits, t4_state_t::rx_bitstream, t4_state_t::rx_skip_bits, span_log(), t4_rx_put_bit(), and t4_state_t::tiff_file.
t4_state_t* t4_rx_init | ( | t4_state_t * | s, | |
const char * | file, | |||
int | output_encoding | |||
) |
Prepare for reception of a document.
s | The T.4 context. | |
file | The name of the file to be received. | |
output_encoding | The output encoding. |
References t4_state_t::bytes_per_row, t4_state_t::file, t4_state_t::image_buffer, t4_state_t::image_buffer_size, t4_state_t::image_width, t4_state_t::logging, t4_state_t::output_compression, t4_state_t::output_t4_options, t4_state_t::pages_in_file, t4_state_t::pages_transferred, t4_state_t::rx, span_log(), t4_state_t::start_page, t4_state_t::stop_page, t4_state_t::x_resolution, and t4_state_t::y_resolution.
int t4_rx_put_bit | ( | t4_state_t * | s, | |
int | bit | |||
) |
Put a bit of the current document page.
s | The T.4 context. | |
bit | The data bit. |
Referenced by t30_non_ecm_put_bit(), and t4_rx_end_page().
int t4_rx_put_byte | ( | t4_state_t * | s, | |
uint8_t | byte | |||
) |
Put a byte of the current document page.
s | The T.4 context. | |
byte | The data byte. |
Referenced by t30_non_ecm_put_byte().
int t4_rx_put_chunk | ( | t4_state_t * | s, | |
const uint8_t | buf[], | |||
int | len | |||
) |
Put a byte of the current document page.
s | The T.4 context. | |
buf | The buffer containing the chunk. | |
len | The length of the chunk. |
Referenced by t30_non_ecm_put_chunk().
void t4_rx_set_dcs | ( | t4_state_t * | s, | |
const char * | dcs | |||
) |
Set the DCS information of the fax, for inclusion in the file.
s | The T.4 context. | |
dcs | The DCS information, formatted as an ASCII string. |
References t4_state_t::dcs.
void t4_rx_set_far_ident | ( | t4_state_t * | s, | |
const char * | ident | |||
) |
Set the identity of the remote machine, for inclusion in the file.
s | The T.4 context. | |
ident | The identity string. |
References t4_state_t::far_ident.
void t4_rx_set_image_width | ( | t4_state_t * | s, | |
int | width | |||
) |
Set the expected width of the received image, in pixel columns.
s | The T.4 context. | |
width | The number of pixels across the image. |
References t4_state_t::image_width.
void t4_rx_set_model | ( | t4_state_t * | s, | |
const char * | model | |||
) |
Set the model of the remote machine, for inclusion in the file.
s | The T.4 context. | |
model | The model string, or NULL. |
References t4_state_t::model.
void t4_rx_set_rx_encoding | ( | t4_state_t * | s, | |
int | encoding | |||
) |
Set the encoding for the received data.
s | The T.4 context. | |
encoding | The encoding. |
References t4_state_t::line_encoding.
void t4_rx_set_sub_address | ( | t4_state_t * | s, | |
const char * | sub_address | |||
) |
Set the sub-address of the fax, for inclusion in the file.
s | The T.4 context. | |
sub_address | The sub-address string. |
References t4_state_t::sub_address.
void t4_rx_set_vendor | ( | t4_state_t * | s, | |
const char * | vendor | |||
) |
Set the vendor of the remote machine, for inclusion in the file.
s | The T.4 context. | |
vendor | The vendor string, or NULL. |
References t4_state_t::vendor.
void t4_rx_set_x_resolution | ( | t4_state_t * | s, | |
int | resolution | |||
) |
Set the column-to-column (x) resolution to expect for a received image.
s | The T.4 context. | |
resolution | The resolution, in pixels per metre. |
References t4_state_t::x_resolution.
void t4_rx_set_y_resolution | ( | t4_state_t * | s, | |
int | resolution | |||
) |
Set the row-to-row (y) resolution to expect for a received image.
s | The T.4 context. | |
resolution | The resolution, in pixels per metre. |
References t4_state_t::y_resolution.
int t4_rx_start_page | ( | t4_state_t * | s | ) |
Prepare to receive the next page of the current document.
s | The T.4 context. |
References t4_state_t::a0, t4_state_t::a_cursor, t4_state_t::b1, t4_state_t::b_cursor, t4_state_t::bad_rows, t4_state_t::black_white, t4_state_t::bytes_per_row, t4_state_t::consecutive_eols, t4_state_t::cur_runs, t4_state_t::curr_bad_row_run, t4_state_t::image_length, t4_state_t::image_size, t4_state_t::image_width, t4_state_t::its_black, t4_state_t::last_row_starts_at, t4_state_t::line_encoding, t4_state_t::line_image_size, t4_state_t::logging, t4_state_t::longest_bad_row_run, t4_state_t::max_row_bits, t4_state_t::min_row_bits, t4_state_t::page_start_time, t4_state_t::ref_runs, t4_state_t::ref_steps, t4_state_t::row_bits, t4_state_t::row_is_2d, t4_state_t::row_len, t4_state_t::run_length, t4_state_t::rx_bits, t4_state_t::rx_bitstream, t4_state_t::rx_skip_bits, span_log(), t4_state_t::tiff_file, t4_state_t::tx_bits, and t4_state_t::tx_bitstream.
int t4_tx_check_bit | ( | t4_state_t * | s | ) |
Return the next bit of the current document page, without actually moving forward in the buffer. The document will be padded for the current minimum scan line time. If the file does not contain an RTC (return to control) code at the end of the page, one will be added.
s | The T.4 context. |
References t4_state_t::bit_pos, t4_state_t::bit_ptr, t4_state_t::image_buffer, t4_state_t::image_size, and SIG_STATUS_END_OF_DATA.
int t4_tx_delete | ( | t4_state_t * | s | ) |
End the transmission of a document. Tidy up, close the file and free the context. This should be used to end T.4 transmission started with t4_tx_init.
s | The T.4 context. |
References t4_tx_end().
int t4_tx_end | ( | t4_state_t * | s | ) |
End the transmission of a document. Tidy up and close the file. This should be used to end T.4 transmission started with t4_tx_init.
s | The T.4 context. |
References t4_state_t::rx, and t4_state_t::tiff_file.
Referenced by t30_release(), and t4_tx_delete().
int t4_tx_end_page | ( | t4_state_t * | s | ) |
Complete the sending of a page.
s | The T.4 context. |
References t4_state_t::pages_transferred.
int t4_tx_get_bit | ( | t4_state_t * | s | ) |
Get the next bit of the current document page. The document will be padded for the current minimum scan line time. If the file does not contain an RTC (return to control) code at the end of the page, one will be added where appropriate.
s | The T.4 context. |
References t4_state_t::bit_pos, t4_state_t::bit_ptr, t4_state_t::image_buffer, t4_state_t::image_size, and SIG_STATUS_END_OF_DATA.
Referenced by t30_non_ecm_get_bit().
int t4_tx_get_byte | ( | t4_state_t * | s | ) |
Get the next byte of the current document page. The document will be padded for the current minimum scan line time. If the file does not contain an RTC (return to control) code at the end of the page, one will be added where appropriate.
s | The T.4 context. |
References t4_state_t::bit_ptr, t4_state_t::image_buffer, and t4_state_t::image_size.
Referenced by t30_non_ecm_get_byte().
int t4_tx_get_chunk | ( | t4_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 scan line time. If the file does not contain an RTC (return to control) code at the end of the page, one will be added where appropriate.
s | The T.4 context. | |
buf | The buffer into which the chunk is to written. | |
max_len | The maximum length of the chunk. |
References t4_state_t::bit_ptr, t4_state_t::image_buffer, and t4_state_t::image_size.
Referenced by t30_non_ecm_get_chunk().
int t4_tx_get_image_width | ( | t4_state_t * | s | ) |
Get the width of the current page, in pixel columns.
s | The T.4 context. |
References t4_state_t::image_width.
int t4_tx_get_pages_in_file | ( | t4_state_t * | s | ) |
Get the number of pages in the file.
s | The T.4 context. |
References t4_state_t::pages_in_file, t4_state_t::pages_transferred, and t4_state_t::tiff_file.
int t4_tx_get_x_resolution | ( | t4_state_t * | s | ) |
Get the column-to-column (x) resolution of the current page.
s | The T.4 context. |
References t4_state_t::x_resolution.
int t4_tx_get_y_resolution | ( | t4_state_t * | s | ) |
Get the row-to-row (y) resolution of the current page.
s | The T.4 context. |
References t4_state_t::y_resolution.
t4_state_t* t4_tx_init | ( | t4_state_t * | s, | |
const char * | file, | |||
int | start_page, | |||
int | stop_page | |||
) |
Prepare for transmission of a document.
s | The T.4 context. | |
file | The name of the file to be sent. | |
start_page | The first page to send. -1 for no restriction. | |
stop_page | The last page to send. -1 for no restriction. |
References t4_state_t::bytes_per_row, t4_state_t::cur_runs, t4_state_t::file, t4_state_t::image_buffer_size, t4_state_t::image_width, t4_state_t::logging, t4_state_t::max_rows_to_next_1d_row, t4_state_t::pages_in_file, t4_state_t::pages_transferred, t4_state_t::ref_runs, t4_state_t::ref_steps, t4_state_t::row_buf, t4_state_t::rows_to_next_1d_row, t4_state_t::rx, span_log(), t4_state_t::start_page, and t4_state_t::stop_page.
int t4_tx_more_pages | ( | t4_state_t * | s | ) |
Check for the existance of the next page. This information can be needed before it is determined that the current page is finished with.
s | The T.4 context. |
References t4_state_t::logging, t4_state_t::pages_in_file, t4_state_t::pages_transferred, span_log(), t4_state_t::stop_page, and t4_state_t::tiff_file.
int t4_tx_restart_page | ( | t4_state_t * | s | ) |
Prepare the current page for a resend.
s | The T.4 context. |
References t4_state_t::bit_pos, and t4_state_t::bit_ptr.
void t4_tx_set_header_info | ( | t4_state_t * | s, | |
const char * | info | |||
) |
Set the header info.
Set the info field, included in the header line included in each page of an encoded FAX. This is a string of up to 50 characters. Other information (date, local ident, etc.) are automatically included in the header. If the header info is set to NULL or a zero length string, no header lines will be added to the encoded FAX.
s | The T.4 context. | |
info | A string, of up to 50 bytes, which will form the info field. |
References t4_state_t::header_info.
Referenced by t30_set_tx_page_header_info().
void t4_tx_set_local_ident | ( | t4_state_t * | s, | |
const char * | ident | |||
) |
Set the identity of the local machine, for inclusion in page headers.
s | The T.4 context. | |
ident | The identity string. |
References t4_state_t::local_ident.
Referenced by t30_set_tx_ident().
void t4_tx_set_min_row_bits | ( | t4_state_t * | s, | |
int | bits | |||
) |
Set the minimum number of encoded bits per row. This allows the makes the encoding process to be set to comply with the minimum row time specified by a remote receiving machine.
s | The T.4 context. | |
bits | The minimum number of bits per row. |
References t4_state_t::min_bits_per_row.
void t4_tx_set_tx_encoding | ( | t4_state_t * | s, | |
int | encoding | |||
) |
Set the encoding for the encoded data.
s | The T.4 context. | |
encoding | The encoding. |
References t4_state_t::line_encoding, t4_state_t::max_rows_to_next_1d_row, t4_state_t::row_is_2d, and t4_state_t::rows_to_next_1d_row.
int t4_tx_start_page | ( | t4_state_t * | s | ) |
Prepare to send the next page of the current document.
s | The T.4 context. |
References t4_state_t::bit_pos, t4_state_t::bit_ptr, t4_state_t::bytes_per_row, t4_state_t::cur_runs, t4_state_t::file, t4_state_t::header_info, t4_state_t::image_length, t4_state_t::image_size, t4_state_t::image_width, t4_state_t::line_encoding, t4_state_t::line_image_size, t4_state_t::logging, t4_state_t::max_row_bits, t4_state_t::max_rows_to_next_1d_row, t4_state_t::min_row_bits, t4_state_t::pages_transferred, t4_state_t::ref_runs, t4_state_t::ref_steps, t4_state_t::row_bits, t4_state_t::row_buf, t4_state_t::row_is_2d, t4_state_t::row_read_handler, t4_state_t::row_read_user_data, t4_state_t::rows_to_next_1d_row, span_log(), t4_state_t::stop_page, t4_state_t::tiff_file, t4_state_t::tx_bits, t4_state_t::tx_bitstream, and t4_state_t::y_resolution.