提交 0b6c5321 authored 作者: Steve Underwood's avatar Steve Underwood

Moves towards colour FAX

上级 26d5a6eb
......@@ -48,7 +48,6 @@
#include <math.h>
#endif
#include "floating_fudge.h"
#include <jpeglib.h>
#include <tiffio.h>
#include <assert.h>
......
......@@ -31,6 +31,8 @@
#if !defined(_SPANDSP_EXPOSE_H_)
#define _SPANDSP_EXPOSE_H_
#include <jpeglib.h>
#include <spandsp/private/logging.h>
#include <spandsp/private/schedule.h>
#include <spandsp/private/bitstream.h>
......
......@@ -231,7 +231,11 @@ struct t30_state_s
/*! \brief The common group of supported image sizes. */
int mutual_image_sizes;
/*! \brief The image coding being used on the line. */
int line_encoding;
int line_compression;
/*! \brief The image type being used on the line. */
int line_image_type;
/*! \brief The width code for the image on the line. */
int line_width_code;
/*! \brief The current DCS message minimum scan time code. */
uint8_t min_scan_time_code;
/*! \brief The X direction resolution of the current image, in pixels per metre. */
......
......@@ -70,6 +70,14 @@
#define T30_DCS_BIT_RECEIVE_FAX_DOCUMENT 10
/* Bits 11, 12, 13, 14 - modem type */
#define T30_DIS_BIT_MODEM_TYPE_1 11
#define T30_DCS_BIT_MODEM_TYPE_1 11
#define T30_DIS_BIT_MODEM_TYPE_2 12
#define T30_DCS_BIT_MODEM_TYPE_2 12
#define T30_DIS_BIT_MODEM_TYPE_3 13
#define T30_DCS_BIT_MODEM_TYPE_3 13
#define T30_DIS_BIT_MODEM_TYPE_4 14
#define T30_DCS_BIT_MODEM_TYPE_4 14
#define T30_DIS_BIT_200_200_CAPABLE 15
#define T30_DCS_BIT_200_200 15
......
......@@ -26,6 +26,9 @@
#if !defined(_SPANDSP_PRIVATE_T42_H_)
#define _SPANDSP_PRIVATE_T42_H_
#include <setjmp.h>
#include <jpeglib.h>
struct lab_params_s
{
/* Lab gamut */
......@@ -50,11 +53,39 @@ struct t42_encode_state_s
t4_row_read_handler_t row_read_handler;
/*! \brief Opaque pointer passed to row_read_handler. */
void *row_read_user_data;
uint32_t image_width;
uint32_t image_length;
uint16_t samples_per_pixel;
int image_type;
int no_subsampling;
int itu_ycc;
int quality;
/* The X or Y direction resolution, in pixels per inch */
int spatial_resolution;
lab_params_t lab_params;
lab_params_t lab;
uint8_t illuminant_code[4];
int illuminant_colour_temperature;
/*! \brief The size of the compressed image, in bytes. */
int compressed_image_size;
int compressed_image_ptr;
int buf_size;
uint8_t *compressed_buf;
FILE *out;
#if defined(HAVE_OPEN_MEMSTREAM)
size_t outsize;
#endif
jmp_buf escape;
char error_message[JMSG_LENGTH_MAX];
struct jpeg_compress_struct compressor;
JSAMPROW scan_line_out;
JSAMPROW scan_line_in;
/*! \brief Error and flow logging control */
logging_state_t logging;
......@@ -73,8 +104,19 @@ struct t42_decode_state_s
void *comment_user_data;
/*! The maximum length of comment to be passed to the comment handler */
uint32_t max_comment_len;
uint32_t image_width;
uint32_t image_length;
uint16_t samples_per_pixel;
int image_type;
int itu_ycc;
/* The X or Y direction resolution, in pixels per inch */
int spatial_resolution;
lab_params_t lab;
lab_params_t lab_params;
uint8_t illuminant_code[4];
int illuminant_colour_temperature;
/*! The contents for a COMMENT marker segment, to be added to the
image at the next opportunity. This is set to NULL when nothing is
......@@ -89,6 +131,17 @@ struct t42_decode_state_s
int buf_size;
uint8_t *compressed_buf;
FILE *in;
jmp_buf escape;
char error_message[JMSG_LENGTH_MAX];
struct jpeg_decompress_struct decompressor;
/*! Flag that the data to be decoded has run out. */
int end_of_data;
JSAMPROW scan_line_out;
JSAMPROW scan_line_in;
/*! \brief Error and flow logging control */
logging_state_t logging;
};
......
......@@ -37,17 +37,21 @@ struct t43_encode_state_s
struct lab_params_s lab;
struct t85_encode_state_s t85;
int image_type;
int bit_planes[4];
int colour_map_entries;
uint8_t colour_map[3*256];
uint8_t illuminant_code[4];
int illuminant_colour_temperature;
/*! The width of the full image, in pixels */
uint32_t xd;
/*! The height of the full image, in pixels */
uint32_t yd;
int x_resolution;
int y_resolution;
/* The X or Y direction resolution, in pixels per inch */
int spatial_resolution;
/*! \brief Error and flow logging control */
logging_state_t logging;
......@@ -64,6 +68,7 @@ struct t43_decode_state_s
struct lab_params_s lab;
struct t85_decode_state_s t85;
int image_type;
int bit_planes[4];
uint8_t bit_plane_mask;
int current_bit_plane;
......@@ -72,8 +77,12 @@ struct t43_decode_state_s
int colour_map_entries;
uint8_t colour_map[3*256];
int x_resolution;
int y_resolution;
uint8_t illuminant_code[4];
int illuminant_colour_temperature;
/* The X or Y direction resolution, in pixels per inch */
int spatial_resolution;
int samples_per_pixel;
uint8_t *buf;
int ptr;
......
......@@ -39,7 +39,7 @@ typedef struct
/*! Image type - bilevel, gray, colour */
int image_type;
/*! \brief The compression type for output to the TIFF file. */
int output_encoding;
int compression;
/*! \brief The TIFF photometric setting for the current page. */
uint16_t photo_metric;
/*! \brief The TIFF fill order setting for the current page. */
......@@ -65,6 +65,12 @@ typedef struct
*/
typedef struct
{
/*! \brief The type of compression used on the wire. */
int compression;
/*! \brief The width of the current page, in pixels. */
uint32_t image_width;
/*! \brief The length of the current page, in pixels. */
uint32_t image_length;
/*! \brief Column-to-column (X) resolution in pixels per metre. */
int x_resolution;
/*! \brief Row-to-row (Y) resolution in pixels per metre. */
......@@ -104,14 +110,6 @@ struct t4_rx_state_s
/*! \brief The size of the compressed image on the line side, in bits. */
int line_image_size;
/*! \brief The type of compression used between the FAX machines. */
int line_encoding;
/*! \brief The width of the current page, in pixels. */
uint32_t image_width;
/*! \brief The length of the current page, in pixels. */
uint32_t image_length;
union
{
t4_t6_decode_state_t t4_t6;
......
......@@ -58,13 +58,15 @@ typedef struct
int row;
/*! \brief Width of the image in the file. */
int image_width;
uint32_t image_width;
/*! \brief Length of the image in the file. */
int image_length;
uint32_t image_length;
/*! \brief Column-to-column (X) resolution in pixels per metre of the image in the file. */
int image_x_resolution;
/*! \brief Row-to-row (Y) resolution in pixels per metre of the image in the file. */
int image_y_resolution;
/*! \brief Code for the combined X and Y resolution of the image in the file. */
int resolution_code;
/*! \brief Row counter used when the image is resized or dithered flat. */
int raw_row;
......@@ -78,14 +80,23 @@ typedef struct
*/
typedef struct
{
/*! \brief The type of compression used on the wire. */
int compression;
/*! \brief Image type - bi-level, gray, colour, etc. */
int image_type;
/*! \brief The width code for the image on the line side. */
int width_code;
/*! \brief The width of the current page on the wire, in pixels. */
uint32_t image_width;
/*! \brief The length of the current page on the wire, in pixels. */
uint32_t image_length;
/*! \brief Column-to-column (X) resolution in pixels per metre on the wire. */
int x_resolution;
/*! \brief Row-to-row (Y) resolution in pixels per metre on the wire. */
int y_resolution;
/*! \brief Code for the combined X and Y resolution of the image in the file. */
/*! \brief Code for the combined X and Y resolution on the wire. */
int resolution_code;
/*! \brief Image type - bi-level, gray, colour, etc. */
int image_type;
} t4_tx_metadata_t;
/*!
......@@ -99,19 +110,11 @@ struct t4_tx_state_s
/*! \brief Opaque pointer passed to row_read_handler. */
void *row_handler_user_data;
/*! \brief The type of compression used between the FAX machines. */
int line_encoding;
/*! \brief When superfine and fine resolution images need to be squahed vertically
to a lower resolution, this value sets the number of source rows which
must be squashed to form each row on the wire. */
int row_squashing_ratio;
/*! \brief The width of the current page, in pixels. */
uint32_t image_width;
/*! \brief The length of the current page, in pixels. */
uint32_t image_length;
/*! \brief The size of the compressed image on the line side, in bits. */
int line_image_size;
......
......@@ -525,7 +525,7 @@ static int rx_start_page(t30_state_t *s)
t4_rx_set_vendor(&s->t4.rx, s->vendor);
t4_rx_set_model(&s->t4.rx, s->model);
t4_rx_set_rx_encoding(&s->t4.rx, s->line_encoding);
t4_rx_set_rx_encoding(&s->t4.rx, s->line_compression);
t4_rx_set_x_resolution(&s->t4.rx, s->x_resolution);
t4_rx_set_y_resolution(&s->t4.rx, s->y_resolution);
......@@ -1455,7 +1455,7 @@ static int build_dcs(t30_state_t *s)
/* Select the compression to use. */
use_bilevel = TRUE;
switch (s->line_encoding)
switch (s->line_compression)
{
case T4_COMPRESSION_T4_1D:
/* There is nothing to set to select this encoding. */
......@@ -2053,7 +2053,7 @@ static int analyze_rx_dcs(t30_state_t *s, const uint8_t *msg, int len)
s->x_resolution = -1;
s->y_resolution = -1;
s->current_page_resolution = 0;
s->line_encoding = -1;
s->line_compression = -1;
x = -1;
if (test_ctrl_bit(dcs_frame, T30_DCS_BIT_T81_MODE)
||
......@@ -2157,22 +2157,22 @@ static int analyze_rx_dcs(t30_state_t *s, const uint8_t *msg, int len)
if (test_ctrl_bit(dcs_frame, T30_DCS_BIT_T81_MODE))
{
if ((s->supported_compressions & T4_SUPPORT_COMPRESSION_T42_T81))
s->line_encoding = T4_COMPRESSION_T42_T81;
s->line_compression = T4_COMPRESSION_T42_T81;
}
else if (test_ctrl_bit(dcs_frame, T30_DCS_BIT_T43_MODE))
{
if ((s->supported_compressions & T4_SUPPORT_COMPRESSION_T43))
s->line_encoding = T4_COMPRESSION_T43;
s->line_compression = T4_COMPRESSION_T43;
}
else if (test_ctrl_bit(dcs_frame, T30_DCS_BIT_T45_MODE))
{
if ((s->supported_compressions & T4_SUPPORT_COMPRESSION_T45))
s->line_encoding = T4_COMPRESSION_T45;
s->line_compression = T4_COMPRESSION_T45;
}
else if (test_ctrl_bit(dcs_frame, T30_DCS_BIT_SYCC_T81_MODE))
{
if ((s->supported_compressions & T4_SUPPORT_COMPRESSION_SYCC_T81))
s->line_encoding = T4_COMPRESSION_SYCC_T81;
s->line_compression = T4_COMPRESSION_SYCC_T81;
}
}
else
......@@ -2333,41 +2333,41 @@ static int analyze_rx_dcs(t30_state_t *s, const uint8_t *msg, int len)
test_ctrl_bit(dcs_frame, T30_DCS_BIT_T88_MODE_3))
{
if ((s->supported_compressions & T4_SUPPORT_COMPRESSION_T88))
s->line_encoding = T4_COMPRESSION_T88;
s->line_compression = T4_COMPRESSION_T88;
}
if (test_ctrl_bit(dcs_frame, T30_DCS_BIT_T85_L0_MODE))
{
if ((s->supported_compressions & T4_SUPPORT_COMPRESSION_T85_L0))
s->line_encoding = T4_COMPRESSION_T85_L0;
s->line_compression = T4_COMPRESSION_T85_L0;
}
else if (test_ctrl_bit(dcs_frame, T30_DCS_BIT_T85_MODE))
{
if ((s->supported_compressions & T4_SUPPORT_COMPRESSION_T85))
s->line_encoding = T4_COMPRESSION_T85;
s->line_compression = T4_COMPRESSION_T85;
}
else if (test_ctrl_bit(dcs_frame, T30_DCS_BIT_T6_MODE))
{
if ((s->supported_compressions & T4_SUPPORT_COMPRESSION_T6))
s->line_encoding = T4_COMPRESSION_T6;
s->line_compression = T4_COMPRESSION_T6;
}
else if (test_ctrl_bit(dcs_frame, T30_DCS_BIT_2D_MODE))
{
if ((s->supported_compressions & T4_SUPPORT_COMPRESSION_T4_2D))
s->line_encoding = T4_COMPRESSION_T4_2D;
s->line_compression = T4_COMPRESSION_T4_2D;
}
else
{
if ((s->supported_compressions & T4_SUPPORT_COMPRESSION_T4_1D))
s->line_encoding = T4_COMPRESSION_T4_1D;
s->line_compression = T4_COMPRESSION_T4_1D;
}
}
if (s->line_encoding == -1)
if (s->line_compression == -1)
{
t30_set_status(s, T30_ERR_INCOMPATIBLE);
return -1;
}
span_log(&s->logging, SPAN_LOG_FLOW, "Far end selected compression %s (%d)\n", t4_encoding_to_str(s->line_encoding), s->line_encoding);
span_log(&s->logging, SPAN_LOG_FLOW, "Far end selected compression %s (%d)\n", t4_encoding_to_str(s->line_compression), s->line_compression);
if (x < 0)
{
......@@ -2678,7 +2678,7 @@ static int start_sending_document(t30_state_t *s)
}
s->operation_in_progress = OPERATION_IN_PROGRESS_T4_TX;
t4_tx_get_pages_in_file(&s->t4.tx);
t4_tx_set_tx_encoding(&s->t4.tx, s->line_encoding);
t4_tx_set_tx_encoding(&s->t4.tx, s->line_compression);
t4_tx_set_local_ident(&s->t4.tx, s->tx_info.ident);
t4_tx_set_header_info(&s->t4.tx, s->header_info);
if (s->use_own_tz)
......@@ -2778,17 +2778,17 @@ static int process_rx_dis_dtc(t30_state_t *s, const uint8_t *msg, int len)
/* Choose a compression scheme from amongst those mutually available */
if ((s->mutual_compressions & T4_SUPPORT_COMPRESSION_T85_L0))
s->line_encoding = T4_COMPRESSION_T85_L0;
s->line_compression = T4_COMPRESSION_T85_L0;
else if ((s->mutual_compressions & T4_SUPPORT_COMPRESSION_T85))
s->line_encoding = T4_COMPRESSION_T85;
s->line_compression = T4_COMPRESSION_T85;
else if ((s->mutual_compressions & T4_SUPPORT_COMPRESSION_T6))
s->line_encoding = T4_COMPRESSION_T6;
s->line_compression = T4_COMPRESSION_T6;
else if ((s->mutual_compressions & T4_SUPPORT_COMPRESSION_T4_2D))
s->line_encoding = T4_COMPRESSION_T4_2D;
s->line_compression = T4_COMPRESSION_T4_2D;
else
s->line_encoding = T4_COMPRESSION_T4_1D;
s->line_compression = T4_COMPRESSION_T4_1D;
span_log(&s->logging, SPAN_LOG_FLOW, "Choose compression %s (%d)\n", t4_encoding_to_str(s->line_encoding), s->line_encoding);
span_log(&s->logging, SPAN_LOG_FLOW, "Choose compression %s (%d)\n", t4_encoding_to_str(s->line_compression), s->line_compression);
if (s->phase_b_handler)
{
......
......@@ -146,7 +146,7 @@ SPAN_DECLARE(int) t43_create_header(t43_decode_state_t *s, uint8_t data[], size_
pos += 6;
unpack_16(&data[pos], 1997);
pos += 2;
unpack_16(&data[pos], s->x_resolution);
unpack_16(&data[pos], s->spatial_resolution);
pos += 2;
/* JBIG coding method (0) is the only possible value here */
data[pos] = 0;
......@@ -523,7 +523,7 @@ static int t43_analyse_header(t43_decode_state_t *s, const uint8_t data[], size_
if (seg >= 6 + 10)
{
val[0] = pack_16(&data[pos + 6 + 0]);
s->x_resolution = pack_16(&data[pos + 6 + 2]);
s->spatial_resolution = pack_16(&data[pos + 6 + 2]);
val[2] = data[pos + 6 + 4];
val[3] = data[pos + 6 + 5];
s->bit_planes[0] = data[pos + 6 + 6];
......@@ -534,7 +534,7 @@ static int t43_analyse_header(t43_decode_state_t *s, const uint8_t data[], size_
SPAN_LOG_FLOW,
"Version %d, resolution %.2fdpi, coding method %d, type %s (%d), bit planes %d,%d,%d,%d\n",
val[0],
s->x_resolution/100.0f,
s->spatial_resolution/100.0f,
val[2],
t43_image_type_to_str(val[3]),
val[3],
......
差异被折叠。
......@@ -60,8 +60,8 @@
#include "config.h"
#endif
#include <stdlib.h>
#include <inttypes.h>
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
#include <fcntl.h>
......
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论