spandsp  3.0.0
t85_decode.c File Reference
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "spandsp/stdbool.h"
#include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/logging.h"
#include "spandsp/async.h"
#include "spandsp/timezone.h"
#include "spandsp/t4_rx.h"
#include "spandsp/t4_tx.h"
#include "spandsp/t81_t82_arith_coding.h"
#include "spandsp/t85.h"
#include "spandsp/private/logging.h"
#include "spandsp/private/t81_t82_arith_coding.h"
#include "spandsp/private/t85.h"

Functions

bool t85_analyse_header (uint32_t *width, uint32_t *length, const uint8_t data[], size_t len)
 
void t85_decode_rx_status (t85_decode_state_t *s, int status)
 Inform the T.85 decode engine of a status change in the signal source (end of tx, rx signal change, etc.). More...
 
int t85_decode_put (t85_decode_state_t *s, const uint8_t data[], size_t len)
 Decode a chunk of T.85 data. More...
 
int t85_decode_set_row_write_handler (t85_decode_state_t *s, t4_row_write_handler_t handler, void *user_data)
 Set the row handler routine. More...
 
int t85_decode_set_comment_handler (t85_decode_state_t *s, uint32_t max_comment_len, t4_row_write_handler_t handler, void *user_data)
 Set the comment handler routine. More...
 
int t85_decode_set_image_size_constraints (t85_decode_state_t *s, uint32_t max_xd, uint32_t max_yd)
 Set constraints on the received image size. More...
 
uint32_t t85_decode_get_image_width (t85_decode_state_t *s)
 Get the width of the image. More...
 
uint32_t t85_decode_get_image_length (t85_decode_state_t *s)
 Get the length of the image. More...
 
int t85_decode_get_compressed_image_size (t85_decode_state_t *s)
 Get the size of the compressed image, in bits. More...
 
int t85_decode_new_plane (t85_decode_state_t *s)
 
logging_state_tt85_decode_get_logging_state (t85_decode_state_t *s)
 Get the logging context associated with a T.85 decode context. More...
 
int t85_decode_restart (t85_decode_state_t *s)
 
t85_decode_state_tt85_decode_init (t85_decode_state_t *s, t4_row_write_handler_t handler, void *user_data)
 Prepare to decode an image in T.85 format. More...
 
int t85_decode_release (t85_decode_state_t *s)
 Release a T.85 decode context. More...
 
int t85_decode_free (t85_decode_state_t *s)
 Free a T.85 decode context. More...
 

Function Documentation

◆ t85_decode_free()

int t85_decode_free ( t85_decode_state_t s)

Free a T.85 decode context.

Parameters
sThe T.85 decode context.
Returns
0 for OK, else -1.

References t85_decode_release().

Referenced by t43_decode_free().

◆ t85_decode_get_compressed_image_size()

int t85_decode_get_compressed_image_size ( t85_decode_state_t s)

Get the size of the compressed image, in bits.

Parameters
sThe T.85 context.
Returns
The size of the compressed image, in bits.

References t85_decode_state_s::compressed_image_size.

◆ t85_decode_get_image_length()

uint32_t t85_decode_get_image_length ( t85_decode_state_t s)

Get the length of the image.

Parameters
sThe T.85 context.
Returns
The length of the image, in pixels.

References t85_decode_state_s::yd.

Referenced by t43_decode_get_image_length().

◆ t85_decode_get_image_width()

uint32_t t85_decode_get_image_width ( t85_decode_state_t s)

Get the width of the image.

Parameters
sThe T.85 context.
Returns
The width of the image, in pixels.

References t85_decode_state_s::xd.

Referenced by t43_decode_get_image_width().

◆ t85_decode_get_logging_state()

logging_state_t* t85_decode_get_logging_state ( t85_decode_state_t s)

Get the logging context associated with a T.85 decode context.

Get the logging context associated with a T.85 decode context.

Parameters
sThe T.85 decode context.
Returns
A pointer to the logging context

References t85_decode_state_s::logging.

◆ t85_decode_init()

t85_decode_state_t* t85_decode_init ( t85_decode_state_t s,
t4_row_write_handler_t  handler,
void *  user_data 
)

Prepare to decode an image in T.85 format.

Parameters
sThe T.85 context.
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.

◆ t85_decode_put()

int t85_decode_put ( t85_decode_state_t s,
const uint8_t  data[],
size_t  len 
)

Decode a chunk of T.85 data.

Parameters
sThe T.85 context.
dataThe data to be decoded.
lenThe length of the data to be decoded.
Returns
0 for OK.

References t85_decode_state_s::y.

◆ t85_decode_release()

int t85_decode_release ( t85_decode_state_t s)

Release a T.85 decode context.

Parameters
sThe T.85 decode context.
Returns
0 for OK, else -1.

References t85_decode_state_s::row_buf.

Referenced by t43_decode_release(), and t85_decode_free().

◆ t85_decode_rx_status()

void t85_decode_rx_status ( t85_decode_state_t s,
int  status 
)

Inform the T.85 decode engine of a status change in the signal source (end of tx, rx signal change, etc.).

After the final BIE byte has been delivered to t85_decode_put_xx(), it may still return T85_MORE_DATA when the T85_VLENGTH option was used, and no NEWLEN marker section has appeared yet. This is because such a BIE is not self-terminating (i.e. there could still be a NEWLEN followed by an SDNORM or SDRST at the very end of the final stripe, which needs to be processed before the final row is output. See ITU-T Recommendation T.85, Appendix I). Therefore, after the last byte has been delivered, call this routine to signal the end of the BIE. This is necessary to allow the routine to finish processing BIEs with option T85_VLENGTH that do not actually contain any NEWLEN marker section.

Parameters
sThe T.85 context.
statusThe type of status change which occured.

References t85_decode_state_s::logging, and span_log().

◆ t85_decode_set_comment_handler()

int t85_decode_set_comment_handler ( t85_decode_state_t s,
uint32_t  max_comment_len,
t4_row_write_handler_t  handler,
void *  user_data 
)

Set the comment handler routine.

Parameters
sThe T.85 context.
max_comment_lenThe maximum length of comment to be passed to the handler.
handlerA callback routine to handle decoded comment.
user_dataAn opaque pointer passed to handler.
Returns
0 for OK.

References t85_decode_state_s::comment_handler, t85_decode_state_s::comment_user_data, and t85_decode_state_s::max_comment_len.

Referenced by t43_decode_set_comment_handler().

◆ t85_decode_set_image_size_constraints()

int t85_decode_set_image_size_constraints ( t85_decode_state_t s,
uint32_t  max_xd,
uint32_t  max_yd 
)

Set constraints on the received image size.

A maliciously constructed T.85 image could consume too much memory, and constitute a denial of service attack on the system. This function allows constraints to be applied.

Parameters
sThe T.85 context.
max_xdThe maximum permitted width of the full image, in pixels
max_ydThe maximum permitted height of the full image, in pixels
Returns
0 for OK

References t85_decode_state_s::max_xd, and t85_decode_state_s::max_yd.

◆ t85_decode_set_row_write_handler()

int t85_decode_set_row_write_handler ( t85_decode_state_t s,
t4_row_write_handler_t  handler,
void *  user_data 
)

Set the row handler routine.

Parameters
sThe T.85 context.
handlerA callback routine to handle decoded image rows.
user_dataAn opaque pointer passed to handler.
Returns
0 for OK.

References t85_decode_state_s::row_write_handler, and t85_decode_state_s::row_write_user_data.

Referenced by t4_rx_set_row_write_handler().