spandsp 3.0.0
t4_rx.c File Reference
#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 "spandsp/stdbool.h"
#include "floating_fudge.h"
#include <tiffio.h>
#include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/logging.h"
#include "spandsp/bit_operations.h"
#include "spandsp/async.h"
#include "spandsp/timezone.h"
#include "spandsp/t4_rx.h"
#include "spandsp/t4_tx.h"
#include "spandsp/image_translate.h"
#include "spandsp/t81_t82_arith_coding.h"
#include "spandsp/t85.h"
#include "spandsp/t42.h"
#include "spandsp/t43.h"
#include "spandsp/t4_t6_decode.h"
#include "spandsp/t4_t6_encode.h"
#include "spandsp/version.h"
#include "spandsp/private/logging.h"
#include "spandsp/private/t81_t82_arith_coding.h"
#include "spandsp/private/t85.h"
#include "spandsp/private/t42.h"
#include "spandsp/private/t43.h"
#include "spandsp/private/t4_t6_decode.h"
#include "spandsp/private/t4_t6_encode.h"
#include "spandsp/private/image_translate.h"
#include "spandsp/private/t4_rx.h"
#include "spandsp/private/t4_tx.h"

Classes

struct  packer_t
 

Macros

#define CM_PER_INCH   2.54f
 

Functions

const char * t4_compression_to_str (int compression)
 Get the short text name of an encoding format.
 
const char * t4_image_type_to_str (int type)
 Get the short text name of an image format.
 
const char * t4_image_resolution_to_str (int resolution_code)
 Get the short text name of an image resolution.
 
int t4_rx_put_bit (t4_rx_state_t *s, int bit)
 Put a bit of the current document page.
 
int t4_rx_put (t4_rx_state_t *s, const uint8_t buf[], size_t len)
 Put a byte of the current document page.
 
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.
 
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.
 
void t4_rx_set_dcs (t4_rx_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_rx_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_rx_state_t *s, const char *ident)
 Set the identity of the remote machine, for inclusion in the file.
 
void t4_rx_set_vendor (t4_rx_state_t *s, const char *vendor)
 Set the vendor of the remote machine, for inclusion in the file.
 
void t4_rx_set_model (t4_rx_state_t *s, const char *model)
 Set the model of the remote machine, for inclusion in the file.
 
int t4_rx_set_rx_encoding (t4_rx_state_t *s, int compression)
 Set the encoding for the received data.
 
void t4_rx_set_image_width (t4_rx_state_t *s, int width)
 Set the expected width of the received image, in pixel columns.
 
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.
 
void t4_rx_get_transfer_statistics (t4_rx_state_t *s, t4_stats_t *t)
 Get the current transfer statistics.
 
int t4_rx_start_page (t4_rx_state_t *s)
 Prepare to receive the next page of the current document.
 
int t4_rx_end_page (t4_rx_state_t *s)
 Complete the reception of a page.
 
logging_state_tt4_rx_get_logging_state (t4_rx_state_t *s)
 Get the logging context associated with a T.4 receive context.
 
t4_rx_state_tt4_rx_init (t4_rx_state_t *s, const char *file, int supported_output_compressions)
 Prepare for reception of a document.
 
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.4 reception started with t4_rx_init.
 
int t4_rx_free (t4_rx_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.
 

Macro Definition Documentation

◆ CM_PER_INCH

#define CM_PER_INCH   2.54f

The number of centimetres in one inch

Function Documentation

◆ t4_compression_to_str()

const char * t4_compression_to_str ( int  compression)

Get the short text name of an encoding format.

Get the short text name of a compression format.

Parameters
compressionThe compression type.
Returns
A pointer to the string.

References T4_COMPRESSION_JPEG, T4_COMPRESSION_NONE, T4_COMPRESSION_SYCC_T81, T4_COMPRESSION_T42_T81, T4_COMPRESSION_T43, T4_COMPRESSION_T45, T4_COMPRESSION_T4_1D, T4_COMPRESSION_T4_2D, T4_COMPRESSION_T6, T4_COMPRESSION_T85, T4_COMPRESSION_T85_L0, T4_COMPRESSION_T88, and T4_COMPRESSION_UNCOMPRESSED.

Referenced by t4_rx_start_page(), and t4_tx_start_page().

◆ t4_image_resolution_to_str()

const char * t4_image_resolution_to_str ( int  resolution_code)

Get the short text name of an image resolution.

Get the short text name of an image resolution.

Parameters
resolution_codeThe image resolution code.
Returns
A pointer to the string.

References T4_RESOLUTION_100_100, T4_RESOLUTION_1200_1200, T4_RESOLUTION_200_100, T4_RESOLUTION_200_200, T4_RESOLUTION_200_400, T4_RESOLUTION_300_300, T4_RESOLUTION_300_600, T4_RESOLUTION_400_400, T4_RESOLUTION_400_800, T4_RESOLUTION_600_1200, T4_RESOLUTION_600_600, T4_RESOLUTION_R16_SUPERFINE, T4_RESOLUTION_R8_FINE, T4_RESOLUTION_R8_STANDARD, and T4_RESOLUTION_R8_SUPERFINE.

Referenced by t4_tx_set_tx_image_format().

◆ t4_image_type_to_str()

const char * t4_image_type_to_str ( int  type)

Get the short text name of an image format.

Get the short text name of an image format.

Parameters
typeThe image format.
Returns
A pointer to the string.

Referenced by t4_tx_set_tx_image_format().

◆ t4_rx_end_page()

◆ t4_rx_free()

int t4_rx_free ( t4_rx_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.

Parameters
sThe T.4 receive context.
Returns
0 for success, otherwise -1.

References t4_rx_release().

◆ t4_rx_get_logging_state()

logging_state_t * t4_rx_get_logging_state ( t4_rx_state_t s)

Get the logging context associated with a T.4 receive context.

Get the logging context associated with a T.4 receive context.

Parameters
sThe T.4 receive context.
Returns
A pointer to the logging context

References t4_rx_state_s::logging.

◆ 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.

Get the current image transfer statistics.

Parameters
sThe T.4 context.
tA pointer to a statistics structure.

References t4_t6_decode_state_s::bad_rows, t4_stats_t::bad_rows, t4_rx_metadata_t::compression, t4_stats_t::compression, t4_rx_state_s::current_page, t4_rx_metadata_t::image_length, t4_stats_t::image_length, t4_stats_t::image_type, t4_rx_metadata_t::image_width, t4_stats_t::image_width, t4_stats_t::image_x_resolution, t4_stats_t::image_y_resolution, t4_stats_t::length, t4_rx_state_s::line_image_size, t4_stats_t::line_image_size, t4_t6_decode_state_s::longest_bad_row_run, t4_stats_t::longest_bad_row_run, t4_rx_tiff_state_t::pages_in_file, t4_stats_t::pages_in_file, t4_stats_t::pages_transferred, t42_decode_get_compressed_image_size(), t42_decode_get_image_length(), t42_decode_get_image_width(), t43_decode_get_image_length(), t43_decode_get_image_width(), T4_COMPRESSION_T42_T81, T4_COMPRESSION_T43, T4_COMPRESSION_T45, T4_COMPRESSION_T4_1D, T4_COMPRESSION_T4_2D, T4_COMPRESSION_T6, T4_COMPRESSION_T85, T4_COMPRESSION_T85_L0, T4_COMPRESSION_T88, t4_t6_decode_get_compressed_image_size(), t4_t6_decode_get_image_length(), t4_t6_decode_get_image_width(), t85_decode_get_compressed_image_size(), t85_decode_get_image_length(), t85_decode_get_image_width(), t4_rx_state_s::tiff, t4_stats_t::type, t4_stats_t::width, t4_rx_metadata_t::x_resolution, t4_stats_t::x_resolution, t4_rx_metadata_t::y_resolution, and t4_stats_t::y_resolution.

Referenced by t30_get_transfer_statistics().

◆ t4_rx_init()

t4_rx_state_t * t4_rx_init ( t4_rx_state_t s,
const char *  file,
int  supported_output_compressions 
)

Prepare for reception of a document.

Parameters
sThe T.4 context.
fileThe name of the file to be received.
supported_output_compressionsThe compression schemes supported for output to a TIFF file.
Returns
A pointer to the context, or NULL if there was a problem.

References t4_rx_state_s::current_page, t4_rx_tiff_state_t::file, t4_rx_state_s::logging, t4_rx_tiff_state_t::pages_in_file, t4_rx_state_s::row_handler, t4_rx_state_s::row_handler_user_data, span_log(), t4_rx_state_s::supported_tiff_compressions, t4_rx_state_s::tiff, t4_rx_metadata_t::x_resolution, and t4_rx_metadata_t::y_resolution.

◆ t4_rx_put()

int t4_rx_put ( t4_rx_state_t s,
const uint8_t  buf[],
size_t  len 
)

Put a byte of the current document page.

Parameters
sThe T.4 context.
bufThe buffer containing the chunk.
lenThe length of the chunk.
Returns
Decode status.

References t4_rx_state_s::line_image_size, and T4_DECODE_OK.

Referenced by t30_non_ecm_put().

◆ t4_rx_put_bit()

int t4_rx_put_bit ( t4_rx_state_t s,
int  bit 
)

Put a bit of the current document page.

Parameters
sThe T.4 context.
bitThe data bit.
Returns
Decode status.

References t4_rx_state_s::line_image_size, and t4_t6_decode_put_bit().

Referenced by t30_non_ecm_put_bit().

◆ 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.4 reception started with t4_rx_init.

Parameters
sThe T.4 receive context.
Returns
0 for success, otherwise -1.

References t4_rx_tiff_state_t::file, and t4_rx_state_s::tiff.

Referenced by t4_rx_free().

◆ t4_rx_set_dcs()

void t4_rx_set_dcs ( t4_rx_state_t s,
const char *  dcs 
)

Set the DCS information of the fax, for inclusion in the file.

Parameters
sThe T.4 context.
dcsThe DCS information, formatted as an ASCII string.

References t4_rx_metadata_t::dcs.

◆ t4_rx_set_far_ident()

void t4_rx_set_far_ident ( t4_rx_state_t s,
const char *  ident 
)

Set the identity of the remote machine, for inclusion in the file.

Parameters
sThe T.4 context.
identThe identity string.

References t4_rx_metadata_t::far_ident.

◆ 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.

Parameters
sThe T.4 context.
widthThe number of pixels across the image.

References t4_rx_metadata_t::image_width.

◆ t4_rx_set_model()

void t4_rx_set_model ( t4_rx_state_t s,
const char *  model 
)

Set the model of the remote machine, for inclusion in the file.

Parameters
sThe T.4 context.
modelThe model string, or NULL.

References t4_rx_metadata_t::model.

◆ 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.

Parameters
sThe T.4 receive context.
handlerA pointer to the handler routine.
user_dataAn opaque pointer passed to the handler routine.
Returns
0 for success, otherwise -1.

References t4_rx_state_s::row_handler, t4_rx_state_s::row_handler_user_data, t42_decode_set_row_write_handler(), t43_decode_set_row_write_handler(), T4_COMPRESSION_T42_T81, T4_COMPRESSION_T43, T4_COMPRESSION_T45, T4_COMPRESSION_T4_1D, T4_COMPRESSION_T4_2D, T4_COMPRESSION_T6, T4_COMPRESSION_T85, T4_COMPRESSION_T85_L0, T4_COMPRESSION_T88, t4_t6_decode_set_row_write_handler(), and t85_decode_set_row_write_handler().

◆ t4_rx_set_rx_encoding()

◆ t4_rx_set_sub_address()

void t4_rx_set_sub_address ( t4_rx_state_t s,
const char *  sub_address 
)

Set the sub-address of the fax, for inclusion in the file.

Parameters
sThe T.4 context.
sub_addressThe sub-address string.

References t4_rx_metadata_t::sub_address.

◆ t4_rx_set_vendor()

void t4_rx_set_vendor ( t4_rx_state_t s,
const char *  vendor 
)

Set the vendor of the remote machine, for inclusion in the file.

Parameters
sThe T.4 context.
vendorThe vendor string, or NULL.

References t4_rx_metadata_t::vendor.

◆ 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.

Parameters
sThe T.4 context.
resolutionThe resolution, in pixels per metre.

References t4_rx_metadata_t::x_resolution.

◆ 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.

Parameters
sThe T.4 context.
resolutionThe resolution, in pixels per metre.

References t4_rx_metadata_t::y_resolution.

◆ t4_rx_start_page()