spandsp 3.0.0
t42.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 <float.h>
#include "spandsp/stdbool.h"
#include "floating_fudge.h"
#include <tiffio.h>
#include <assert.h>
#include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/fast_convert.h"
#include "spandsp/logging.h"
#include "spandsp/saturated.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/t42.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 "t42_t43_local.h"
#include "cielab_luts.h"

Classes

struct  cielab_t
 
struct  illuminant_t
 
struct  UVT
 

Macros

#define T42_USE_LUTS
 
#define LERP(a, b, c)
 

Typedefs

typedef struct UVT UVT
 

Functions

bool t42_analyse_header (uint32_t *width, uint32_t *length, const uint8_t data[], size_t len)
 
int xyz_to_corrected_color_temp (float *temp, float xyz[3])
 Convert an X0, Y0, Z0 coordinate to a colour tempature.
 
int colour_temp_to_xyz (float xyz[3], float temp)
 Convert a colour temperature to an X0, Y0, Z0 coordinate.
 
void set_lab_illuminant (lab_params_t *lab, float new_xn, float new_yn, float new_zn)
 
void set_lab_gamut (lab_params_t *lab, int L_min, int L_max, int a_min, int a_max, int b_min, int b_max, int ab_are_signed)
 
void set_lab_gamut2 (lab_params_t *lab, int L_P, int L_Q, int a_P, int a_Q, int b_P, int b_Q)
 
void get_lab_gamut2 (lab_params_t *lab, int *L_P, int *L_Q, int *a_P, int *a_Q, int *b_P, int *b_Q)
 
int set_illuminant_from_code (logging_state_t *logging, lab_params_t *lab, const uint8_t code[4])
 
void set_gamut_from_code (logging_state_t *logging, lab_params_t *s, const uint8_t code[12])
 
void srgb_to_lab (lab_params_t *s, uint8_t lab[], const uint8_t srgb[], int pixels)
 Convert a row of 8 bit pixels from Lab to sRGB.
 
void lab_to_srgb (lab_params_t *s, uint8_t srgb[], const uint8_t lab[], int pixels)
 Convert a row of 8 bit pixels from sRGB to Lab.
 
void t42_encode_set_options (t42_encode_state_t *s, uint32_t l0, int quality, int options)
 
int t42_encode_set_image_width (t42_encode_state_t *s, uint32_t image_width)
 
int t42_encode_set_image_length (t42_encode_state_t *s, uint32_t image_length)
 
int t42_encode_set_image_type (t42_encode_state_t *s, int image_type)
 
void t42_encode_abort (t42_encode_state_t *s)
 
void t42_encode_comment (t42_encode_state_t *s, const uint8_t comment[], size_t len)
 
int t42_encode_image_complete (t42_encode_state_t *s)
 Check if we are at the end of the current document page.
 
int t42_encode_get (t42_encode_state_t *s, uint8_t buf[], size_t max_len)
 
uint32_t t42_encode_get_image_width (t42_encode_state_t *s)
 
uint32_t t42_encode_get_image_length (t42_encode_state_t *s)
 
int t42_encode_get_compressed_image_size (t42_encode_state_t *s)
 Get the size of the compressed image in bits.
 
int t42_encode_set_row_read_handler (t42_encode_state_t *s, t4_row_read_handler_t handler, void *user_data)
 
logging_state_tt42_encode_get_logging_state (t42_encode_state_t *s)
 Get the logging context associated with a T.42 encode context.
 
int t42_encode_restart (t42_encode_state_t *s, uint32_t image_width, uint32_t image_length)
 Restart a T.42 encode context.
 
t42_encode_state_tt42_encode_init (t42_encode_state_t *s, uint32_t image_width, uint32_t image_length, t4_row_read_handler_t handler, void *user_data)
 Prepare to encode an image in T.42 format.
 
int t42_encode_release (t42_encode_state_t *s)
 Release a T.42 encode context.
 
int t42_encode_free (t42_encode_state_t *s)
 Free a T.42 encode context.
 
void t42_decode_rx_status (t42_decode_state_t *s, int status)
 
int t42_decode_put (t42_decode_state_t *s, const uint8_t data[], size_t len)
 Decode a chunk of T.42 data.
 
int t42_decode_set_row_write_handler (t42_decode_state_t *s, t4_row_write_handler_t handler, void *user_data)
 Set the row handler routine.
 
int t42_decode_set_comment_handler (t42_decode_state_t *s, uint32_t max_comment_len, t4_row_write_handler_t handler, void *user_data)
 Set the comment handler routine.
 
int t42_decode_set_image_size_constraints (t42_decode_state_t *s, uint32_t max_xd, uint32_t max_yd)
 Set constraints on the received image size.
 
uint32_t t42_decode_get_image_width (t42_decode_state_t *s)
 Get the width of the image.
 
uint32_t t42_decode_get_image_length (t42_decode_state_t *s)
 Get the length of the image.
 
int t42_decode_get_compressed_image_size (t42_decode_state_t *s)
 Get the size of the compressed image in bits.
 
logging_state_tt42_decode_get_logging_state (t42_decode_state_t *s)
 Get the logging context associated with a T.42 decode context.
 
int t42_decode_restart (t42_decode_state_t *s)
 Restart a T.42 decode context.
 
t42_decode_state_tt42_decode_init (t42_decode_state_t *s, t4_row_write_handler_t handler, void *user_data)
 Prepare to decode an image in T.42 format.
 
int t42_decode_release (t42_decode_state_t *s)
 Release a T.42 decode context.
 
int t42_decode_free (t42_decode_state_t *s)
 Free a T.42 decode context.
 

Macro Definition Documentation

◆ LERP

#define LERP ( a,
b,
c )
Value:
(((b) - (a))*(c) + (a))

Function Documentation

◆ lab_to_srgb()

void lab_to_srgb ( lab_params_t * s,
uint8_t srgb[],
const uint8_t lab[],
int pixels )

Convert a row of 8 bit pixels from sRGB to Lab.

Parameters
sThe Lab parameters context.
srgbThe output pixels
labThe input pixels
pixelThe number of pixels in the row.

◆ srgb_to_lab()

void srgb_to_lab ( lab_params_t * s,
uint8_t lab[],
const uint8_t srgb[],
int pixels )

Convert a row of 8 bit pixels from Lab to sRGB.

Parameters
sThe Lab parameters context.
labThe output pixels
srgbThe input pixels
pixelThe number of pixels in the row.

◆ t42_decode_free()

int t42_decode_free ( t42_decode_state_t * s)

Free a T.42 decode context.

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

References t42_decode_release().

◆ t42_decode_get_compressed_image_size()

int t42_decode_get_compressed_image_size ( t42_decode_state_t * s)

Get the size of the compressed image in bits.

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

References t42_decode_state_s::compressed_image_size.

Referenced by t4_rx_get_transfer_statistics().

◆ t42_decode_get_image_length()

uint32_t t42_decode_get_image_length ( t42_decode_state_t * s)

Get the length of the image.

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

Referenced by t4_rx_end_page(), and t4_rx_get_transfer_statistics().

◆ t42_decode_get_image_width()

uint32_t t42_decode_get_image_width ( t42_decode_state_t * s)

Get the width of the image.

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

Referenced by t4_rx_get_transfer_statistics().

◆ t42_decode_get_logging_state()

logging_state_t * t42_decode_get_logging_state ( t42_decode_state_t * s)

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

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

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

References t42_decode_state_s::logging.

◆ t42_decode_init()

t42_decode_state_t * t42_decode_init ( t42_decode_state_t * s,
t4_row_write_handler_t handler,
void * user_data )

Prepare to decode an image in T.42 format.

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

References t42_decode_state_s::logging, t42_decode_state_s::row_write_handler, t42_decode_state_s::row_write_user_data, and t42_decode_restart().

Referenced by t4_rx_set_rx_encoding().

◆ t42_decode_put()

int t42_decode_put ( t42_decode_state_t * s,
const uint8_t data[],
size_t len )

Decode a chunk of T.42 data.

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

References t42_decode_state_s::compressed_image_size, t42_decode_state_s::end_of_data, t42_decode_state_s::logging, span_log(), and T4_DECODE_OK.

Referenced by t4_rx_start_page().

◆ t42_decode_release()

int t42_decode_release ( t42_decode_state_t * s)

Release a T.42 decode context.

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

References t42_decode_state_s::comment.

Referenced by t42_decode_free().

◆ t42_decode_restart()

int t42_decode_restart ( t42_decode_state_t * s)

Restart a T.42 decode context.

Parameters
sThe T.42 context.

References t42_decode_state_s::compressed_image_size, and t42_decode_state_s::end_of_data.

Referenced by t42_decode_init(), and t4_rx_start_page().

◆ t42_decode_set_comment_handler()

int t42_decode_set_comment_handler ( t42_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.42 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 t42_decode_state_s::comment_handler, t42_decode_state_s::comment_user_data, and t42_decode_state_s::max_comment_len.

◆ t42_decode_set_image_size_constraints()

int t42_decode_set_image_size_constraints ( t42_decode_state_t * s,
uint32_t max_xd,
uint32_t max_yd )

Set constraints on the received image size.

A maliciously constructed T.42 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.42 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

Referenced by t4_rx_set_rx_encoding().

◆ t42_decode_set_row_write_handler()

int t42_decode_set_row_write_handler ( t42_decode_state_t * s,
t4_row_write_handler_t handler,
void * user_data )

Set the row handler routine.

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

References t42_decode_state_s::row_write_handler, and t42_decode_state_s::row_write_user_data.

Referenced by t4_rx_set_row_write_handler().

◆ t42_encode_free()

int t42_encode_free ( t42_encode_state_t * s)

Free a T.42 encode context.

Parameters
sThe T.42 encode context.
Returns
0 for OK, else -1.

References t42_encode_release().

◆ t42_encode_get_compressed_image_size()

int t42_encode_get_compressed_image_size ( t42_encode_state_t * s)

Get the size of the compressed image in bits.

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

References t42_encode_state_s::compressed_image_size.

Referenced by t4_tx_get_transfer_statistics().

◆ t42_encode_get_logging_state()

logging_state_t * t42_encode_get_logging_state ( t42_encode_state_t * s)

Get the logging context associated with a T.42 encode context.

Get the logging context associated with a T.42 encode context.

Parameters
sThe T.42 encode context.
Returns
A pointer to the logging context

References t42_encode_state_s::logging.

◆ t42_encode_image_complete()

int t42_encode_image_complete ( t42_encode_state_t * s)

Check if we are at the end of the current document page.

Parameters
sThe T.42 context.
Returns
0 for more data to come. SIG_STATUS_END_OF_DATA for no more data.

Referenced by t4_tx_image_complete().

◆ t42_encode_init()

t42_encode_state_t * t42_encode_init ( t42_encode_state_t * s,
uint32_t image_width,
uint32_t image_length,
t4_row_read_handler_t handler,
void * user_data )

Prepare to encode an image in T.42 format.

Parameters
sThe T.42 context.
image_widthImage width, in pixels.
image_lengthImage length, in pixels.
handlerA callback routine to handle encoded image rows.
user_dataAn opaque pointer passed to handler.
Returns
A pointer to the context, or NULL if there was a problem.

References t42_encode_state_s::logging, t42_encode_state_s::row_read_handler, t42_encode_state_s::row_read_user_data, and t42_encode_restart().

Referenced by t4_tx_set_tx_image_format().

◆ t42_encode_release()

int t42_encode_release ( t42_encode_state_t * s)

Release a T.42 encode context.

Parameters
sThe T.42 encode context.
Returns
0 for OK, else -1.

Referenced by t42_encode_free().

◆ t42_encode_restart()

int t42_encode_restart ( t42_encode_state_t * s,
uint32_t image_width,
uint32_t image_length )

Restart a T.42 encode context.

Parameters
sThe T.42 context.
imageimage_width The image width, in pixels.
imageimage_width The image length, in pixels.
Returns
0 for success, otherwise -1.

References t42_encode_state_s::compressed_image_size, t42_encode_state_s::logging, and span_log().

Referenced by t42_encode_init(), and t4_tx_start_page().