spandsp 3.0.0
t4_t6_encode.c File Reference
#include <inttypes.h>
#include <stdlib.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/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  t4_run_table_entry_t
 

Macros

#define EOLS_TO_END_T4_TX_PAGE   6
 
#define EOLS_TO_END_T6_TX_PAGE   2
 
#define STATE_TRACE(...)
 
#define pixel_is_black(x, bit)   (((x)[(bit) >> 3] << ((bit) & 7)) & 0x80)
 

Functions

int t4_t6_encode_image_complete (t4_t6_encode_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. More...
 
int t4_t6_encode_get_bit (t4_t6_encode_state_t *s)
 Get the next bit of the current image. The image will be padded for the current minimum scan line time. More...
 
int t4_t6_encode_get (t4_t6_encode_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. More...
 
int t4_t6_encode_set_row_read_handler (t4_t6_encode_state_t *s, t4_row_read_handler_t handler, void *user_data)
 Set the row read handler for a T.4/T.6 encode context. More...
 
int t4_t6_encode_set_encoding (t4_t6_encode_state_t *s, int encoding)
 Set the encoding for the encoded data. More...
 
void t4_t6_encode_set_min_bits_per_row (t4_t6_encode_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. More...
 
int t4_t6_encode_set_image_width (t4_t6_encode_state_t *s, int image_width)
 Set the width of the image. More...
 
int t4_t6_encode_set_image_length (t4_t6_encode_state_t *s, int image_length)
 Set the length of the image. More...
 
uint32_t t4_t6_encode_get_image_width (t4_t6_encode_state_t *s)
 Get the width of the image. More...
 
uint32_t t4_t6_encode_get_image_length (t4_t6_encode_state_t *s)
 Get the length of the image. More...
 
int t4_t6_encode_get_compressed_image_size (t4_t6_encode_state_t *s)
 Get the size of the compressed image, in bits. More...
 
void t4_t6_encode_set_max_2d_rows_per_1d_row (t4_t6_encode_state_t *s, int max)
 Set the maximum number of 2D encoded rows between 1D encoded rows. This is only valid for T.4 2D encoding. More...
 
logging_state_tt4_t6_encode_get_logging_state (t4_t6_encode_state_t *s)
 Get the logging context associated with a T.4 or T.6 encode context. More...
 
int t4_t6_encode_restart (t4_t6_encode_state_t *s, int image_width, int image_length)
 Restart a T.4 or T.6 encode context. More...
 
t4_t6_encode_state_tt4_t6_encode_init (t4_t6_encode_state_t *s, int encoding, int image_width, int image_length, t4_row_read_handler_t handler, void *user_data)
 Prepare to encode an image in T.4 or T.6 format. More...
 
int t4_t6_encode_release (t4_t6_encode_state_t *s)
 
int t4_t6_encode_free (t4_t6_encode_state_t *s)
 

Macro Definition Documentation

◆ EOLS_TO_END_T4_TX_PAGE

#define EOLS_TO_END_T4_TX_PAGE   6

The number of EOLs to be sent at the end of a T.4 page

◆ EOLS_TO_END_T6_TX_PAGE

#define EOLS_TO_END_T6_TX_PAGE   2

The number of EOLs to be sent at the end of a T.6 page

Function Documentation

◆ t4_t6_encode_get()

int t4_t6_encode_get ( t4_t6_encode_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.

Parameters
sThe T.4/T.6 context.
bufThe buffer into which the chunk is to written.
max_lenThe maximum length of the chunk.
Returns
The actual length of the chunk. If this is less than max_len it indicates that the end of the document has been reached.

◆ t4_t6_encode_get_bit()

int t4_t6_encode_get_bit ( t4_t6_encode_state_t s)

Get the next bit of the current image. The image will be padded for the current minimum scan line time.

Parameters
sThe T.4/T.6 context.
Returns
The next bit (i.e. 0 or 1). SIG_STATUS_END_OF_DATA for no more data.

References t4_t6_encode_state_s::bitstream_iptr, and t4_t6_encode_state_s::bitstream_optr.

Referenced by t4_tx_get_bit().

◆ t4_t6_encode_get_compressed_image_size()

int t4_t6_encode_get_compressed_image_size ( t4_t6_encode_state_t s)

Get the size of the compressed image, in bits.

Parameters
sThe T.4/T.6 context.
Returns
The size of the compressed image, in bits.

References t4_t6_encode_state_s::compressed_image_size.

Referenced by t4_tx_get_transfer_statistics().

◆ t4_t6_encode_get_image_length()

uint32_t t4_t6_encode_get_image_length ( t4_t6_encode_state_t s)

Get the length of the image.

Parameters
sThe T.4/T.6 context.
Returns
The length of the image, in pixels.

References t4_t6_encode_state_s::image_length.

Referenced by t4_tx_get_transfer_statistics().

◆ t4_t6_encode_get_image_width()

uint32_t t4_t6_encode_get_image_width ( t4_t6_encode_state_t s)

Get the width of the image.

Parameters
sThe T.4/T.6 context.
Returns
The width of the image, in pixels.

References t4_t6_encode_state_s::image_width.

Referenced by t4_tx_get_transfer_statistics().

◆ t4_t6_encode_get_logging_state()

logging_state_t * t4_t6_encode_get_logging_state ( t4_t6_encode_state_t s)

Get the logging context associated with a T.4 or T.6 encode context.

Get the logging context associated with a T.4 or T.6 encode context.

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

References t4_t6_encode_state_s::logging.

◆ t4_t6_encode_image_complete()

int t4_t6_encode_image_complete ( t4_t6_encode_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.

Parameters
sThe T.4/T.6 context.
Returns
0 for more data to come. SIG_STATUS_END_OF_DATA for no more data.

References t4_t6_encode_state_s::bitstream_iptr, and t4_t6_encode_state_s::bitstream_optr.

Referenced by t4_tx_image_complete().

◆ t4_t6_encode_init()

t4_t6_encode_state_t * t4_t6_encode_init ( t4_t6_encode_state_t s,
int  encoding,
int  image_width,
int  image_length,
t4_row_read_handler_t  handler,
void *  user_data 
)

Prepare to encode an image in T.4 or T.6 format.

Parameters
sThe T.4/T.6 context.
encodingThe encoding mode.
image_widthThe image width, in pixels.
image_lengthThe image length, in pixels. This can be set to -1, if the length is not known.
handlerA callback routine to handle decoded image rows.
user_dataAn opaque pointer passed to handler.
Returns
A pointer to the context, or NULL if there was a problem.

◆ t4_t6_encode_restart()

◆ t4_t6_encode_set_encoding()

int t4_t6_encode_set_encoding ( t4_t6_encode_state_t s,
int  encoding 
)

Set the encoding for the encoded data.

Parameters
sThe T.4/T.6 context.
encodingThe encoding.
Returns
0 for success, otherwise -1.

References t4_t6_encode_state_s::encoding, t4_t6_encode_state_s::max_rows_to_next_1d_row, t4_t6_encode_state_s::min_bits_per_row, t4_t6_encode_state_s::row_is_2d, t4_t6_encode_state_s::rows_to_next_1d_row, T4_COMPRESSION_T4_1D, T4_COMPRESSION_T4_2D, and T4_COMPRESSION_T6.

◆ t4_t6_encode_set_image_length()

int t4_t6_encode_set_image_length ( t4_t6_encode_state_t s,
int  image_length 
)

Set the length of the image.

Parameters
sThe T.4/T.6 context.
image_lengthThe image length, in pixels.
Returns
0 for success, otherwise -1.

◆ t4_t6_encode_set_image_width()

int t4_t6_encode_set_image_width ( t4_t6_encode_state_t s,
int  image_width 
)

Set the width of the image.

Parameters
sThe T.4/T.6 context.
image_widthThe image width, in pixels.
Returns
0 for success, otherwise -1.

References t4_t6_encode_state_s::bytes_per_row, and t4_t6_encode_state_s::image_width.

Referenced by t4_t6_encode_restart().

◆ t4_t6_encode_set_max_2d_rows_per_1d_row()

void t4_t6_encode_set_max_2d_rows_per_1d_row ( t4_t6_encode_state_t s,
int  max 
)

Set the maximum number of 2D encoded rows between 1D encoded rows. This is only valid for T.4 2D encoding.

Parameters
sThe T.4/T.6 context.
maxThe "K" parameter defined in the T.4 specification. This means the value is one greater than the maximum number of 2D rows between each 1D row.

Referenced by t4_tx_set_max_2d_rows_per_1d_row().

◆ t4_t6_encode_set_min_bits_per_row()

void t4_t6_encode_set_min_bits_per_row ( t4_t6_encode_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.

Parameters
sThe T.4/T.6 context.
bitsThe minimum number of bits per row.

◆ t4_t6_encode_set_row_read_handler()

int t4_t6_encode_set_row_read_handler ( t4_t6_encode_state_t s,
t4_row_read_handler_t  handler,
void *  user_data 
)

Set the row read handler for a T.4/T.6 encode context.

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

References t4_t6_encode_state_s::row_read_handler, and t4_t6_encode_state_s::row_read_user_data.