More changes towards colour FAX support

This commit is contained in:
Steve Underwood 2013-04-22 08:31:30 +08:00
parent f93c3f70bf
commit 6e6272a7b5
6 changed files with 42 additions and 15 deletions

View File

@ -232,8 +232,6 @@ struct t30_state_s
int mutual_image_sizes; int mutual_image_sizes;
/*! \brief The image coding being used on the line. */ /*! \brief The image coding being used on the line. */
int line_encoding; int line_encoding;
/*! \brief The image coding being used for output files. */
int output_encoding;
/*! \brief The current DCS message minimum scan time code. */ /*! \brief The current DCS message minimum scan time code. */
uint8_t min_scan_time_code; uint8_t min_scan_time_code;
/*! \brief The X direction resolution of the current image, in pixels per metre. */ /*! \brief The X direction resolution of the current image, in pixels per metre. */

View File

@ -563,9 +563,9 @@ SPAN_DECLARE(logging_state_t *) t4_rx_get_logging_state(t4_rx_state_t *s);
/*! \brief Prepare for reception of a document. /*! \brief Prepare for reception of a document.
\param s The T.4 context. \param s The T.4 context.
\param file The name of the file to be received. \param file The name of the file to be received.
\param supported_compressions The compression schemes supported for output to a TIFF file. \param supported_output_compressions The compression schemes supported for output to a TIFF file.
\return A pointer to the context, or NULL if there was a problem. */ \return A pointer to the context, or NULL if there was a problem. */
SPAN_DECLARE(t4_rx_state_t *) t4_rx_init(t4_rx_state_t *s, const char *file, int supported_compressions); SPAN_DECLARE(t4_rx_state_t *) t4_rx_init(t4_rx_state_t *s, const char *file, int supported_output_compressions);
/*! \brief End reception of a document. Tidy up and close the file. /*! \brief 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. This should be used to end T.4 reception started with t4_rx_init.

View File

@ -2899,7 +2899,7 @@ static int process_rx_dcs(t30_state_t *s, const uint8_t *msg, int len)
} }
if (s->operation_in_progress != OPERATION_IN_PROGRESS_T4_RX) if (s->operation_in_progress != OPERATION_IN_PROGRESS_T4_RX)
{ {
if (t4_rx_init(&s->t4.rx, s->rx_file, s->output_encoding) == NULL) if (t4_rx_init(&s->t4.rx, s->rx_file, s->supported_output_compressions) == NULL)
{ {
span_log(&s->logging, SPAN_LOG_WARNING, "Cannot open target TIFF file '%s'\n", s->rx_file); span_log(&s->logging, SPAN_LOG_WARNING, "Cannot open target TIFF file '%s'\n", s->rx_file);
t30_set_status(s, T30_ERR_FILEERROR); t30_set_status(s, T30_ERR_FILEERROR);
@ -6806,7 +6806,7 @@ SPAN_DECLARE(t30_state_t *) t30_init(t30_state_t *s,
| T4_SUPPORT_LENGTH_UNLIMITED; | T4_SUPPORT_LENGTH_UNLIMITED;
/* Set the output encoding to something safe. Most things get 1D and 2D /* Set the output encoding to something safe. Most things get 1D and 2D
encoding right. Quite a lot get other things wrong. */ encoding right. Quite a lot get other things wrong. */
s->output_encoding = T4_COMPRESSION_T4_2D; s->supported_output_compressions = T4_COMPRESSION_T4_2D;
s->local_min_scan_time_code = T30_MIN_SCAN_0MS; s->local_min_scan_time_code = T30_MIN_SCAN_0MS;
span_log_init(&s->logging, SPAN_LOG_NONE, NULL); span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
span_log_set_protocol(&s->logging, "T.30"); span_log_set_protocol(&s->logging, "T.30");

View File

@ -649,7 +649,6 @@ SPAN_DECLARE(int) t30_set_ecm_capability(t30_state_t *s, int enabled)
SPAN_DECLARE(int) t30_set_supported_output_compressions(t30_state_t *s, int supported_compressions) SPAN_DECLARE(int) t30_set_supported_output_compressions(t30_state_t *s, int supported_compressions)
{ {
s->supported_output_compressions = supported_compressions; s->supported_output_compressions = supported_compressions;
s->output_encoding = supported_compressions;
return 0; return 0;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/

View File

@ -578,13 +578,13 @@ static int write_tiff_image(t4_rx_state_t *s)
offset = 0; offset = 0;
if (!TIFFWriteCustomDirectory(t->tiff_file, &offset)) if (!TIFFWriteCustomDirectory(t->tiff_file, &offset))
printf("Failed to write custom directory.\n"); span_log(&s->logging, SPAN_LOG_WARNING, "Failed to write custom directory.\n");
/* Now go back and patch in the pointer to the new IFD */ /* Now go back and patch in the pointer to the new IFD */
if (!TIFFSetDirectory(t->tiff_file, s->current_page)) if (!TIFFSetDirectory(t->tiff_file, s->current_page))
printf("Failed to set directory.\n"); span_log(&s->logging, SPAN_LOG_WARNING, "Failed to set directory.\n");
if (!TIFFSetField(t->tiff_file, TIFFTAG_GLOBALPARAMETERSIFD, offset)) if (!TIFFSetField(t->tiff_file, TIFFTAG_GLOBALPARAMETERSIFD, offset))
printf("Failed to set field.\n"); span_log(&s->logging, SPAN_LOG_WARNING, "Failed to set field.\n");
if (!TIFFWriteDirectory(t->tiff_file)) if (!TIFFWriteDirectory(t->tiff_file))
span_log(&s->logging, SPAN_LOG_WARNING, "%s: Failed to write directory for page %d.\n", t->file, s->current_page); span_log(&s->logging, SPAN_LOG_WARNING, "%s: Failed to write directory for page %d.\n", t->file, s->current_page);
} }
@ -726,6 +726,31 @@ SPAN_DECLARE(void) t4_rx_set_model(t4_rx_state_t *s, const char *model)
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
static void select_tiff_compression(t4_rx_state_t *s, int output_image_type)
{
if (output_image_type == T4_IMAGE_TYPE_BILEVEL)
{
/* Only provide for one form of coding throughout the file, even though the
coding on the wire could change between pages. */
if ((s->supported_tiff_compressions & T4_SUPPORT_COMPRESSION_T85))
s->tiff.output_encoding = T4_COMPRESSION_T85;
else if ((s->supported_tiff_compressions & T4_SUPPORT_COMPRESSION_T6))
s->tiff.output_encoding = T4_COMPRESSION_T6;
else if ((s->supported_tiff_compressions & T4_SUPPORT_COMPRESSION_T4_2D))
s->tiff.output_encoding = T4_COMPRESSION_T4_2D;
else if ((s->supported_tiff_compressions & T4_SUPPORT_COMPRESSION_T4_1D))
s->tiff.output_encoding = T4_COMPRESSION_T4_1D;
}
else
{
if ((s->supported_tiff_compressions & T4_SUPPORT_COMPRESSION_T42_T81))
s->tiff.output_encoding = T4_COMPRESSION_T42_T81;
else if ((s->supported_tiff_compressions & T4_SUPPORT_COMPRESSION_T43))
s->tiff.output_encoding = T4_COMPRESSION_T43;
}
}
/*- End of function --------------------------------------------------------*/
SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int encoding) SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int encoding)
{ {
switch (encoding) switch (encoding)
@ -744,6 +769,7 @@ SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int encoding)
break; break;
} }
s->line_encoding = encoding; s->line_encoding = encoding;
select_tiff_compression(s, T4_IMAGE_TYPE_BILEVEL);
return t4_t6_decode_set_encoding(&s->decoder.t4_t6, encoding); return t4_t6_decode_set_encoding(&s->decoder.t4_t6, encoding);
case T4_COMPRESSION_T85: case T4_COMPRESSION_T85:
case T4_COMPRESSION_T85_L0: case T4_COMPRESSION_T85_L0:
@ -760,6 +786,7 @@ SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int encoding)
t85_decode_set_image_size_constraints(&s->decoder.t85, T4_WIDTH_1200_A3, 0); t85_decode_set_image_size_constraints(&s->decoder.t85, T4_WIDTH_1200_A3, 0);
break; break;
} }
select_tiff_compression(s, T4_IMAGE_TYPE_BILEVEL);
s->line_encoding = encoding; s->line_encoding = encoding;
return 0; return 0;
#if defined(SPANDSP_SUPPORT_T88) #if defined(SPANDSP_SUPPORT_T88)
@ -771,6 +798,7 @@ SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int encoding)
default: default:
break; break;
} }
select_tiff_compression(s, T4_IMAGE_TYPE_BILEVEL);
s->line_encoding = encoding; s->line_encoding = encoding;
return 0; return 0;
#endif #endif
@ -790,6 +818,7 @@ SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int encoding)
break; break;
} }
s->line_encoding = encoding; s->line_encoding = encoding;
select_tiff_compression(s, T4_IMAGE_TYPE_COLOUR_8BIT);
return 0; return 0;
#if defined(SPANDSP_SUPPORT_T43) #if defined(SPANDSP_SUPPORT_T43)
case T4_COMPRESSION_T43: case T4_COMPRESSION_T43:
@ -806,6 +835,7 @@ SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int encoding)
break; break;
} }
s->line_encoding = encoding; s->line_encoding = encoding;
select_tiff_compression(s, T4_IMAGE_TYPE_COLOUR_8BIT);
return 0; return 0;
#endif #endif
#if defined(SPANDSP_SUPPORT_T45) #if defined(SPANDSP_SUPPORT_T45)
@ -818,9 +848,11 @@ SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int encoding)
break; break;
} }
s->line_encoding = encoding; s->line_encoding = encoding;
select_tiff_compression(s, T4_IMAGE_TYPE_COLOUR_8BIT);
return 0; return 0;
#endif #endif
} }
return -1; return -1;
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
@ -1055,7 +1087,7 @@ SPAN_DECLARE(logging_state_t *) t4_rx_get_logging_state(t4_rx_state_t *s)
} }
/*- End of function --------------------------------------------------------*/ /*- End of function --------------------------------------------------------*/
SPAN_DECLARE(t4_rx_state_t *) t4_rx_init(t4_rx_state_t *s, const char *file, int output_encoding) SPAN_DECLARE(t4_rx_state_t *) t4_rx_init(t4_rx_state_t *s, const char *file, int supported_output_compressions)
{ {
int allocated; int allocated;
@ -1075,9 +1107,7 @@ SPAN_DECLARE(t4_rx_state_t *) t4_rx_init(t4_rx_state_t *s, const char *file, int
span_log(&s->logging, SPAN_LOG_FLOW, "Start rx document\n"); span_log(&s->logging, SPAN_LOG_FLOW, "Start rx document\n");
/* Only provide for one form of coding throughout the file, even though the s->supported_tiff_compressions = supported_output_compressions;
coding on the wire could change between pages. */
s->tiff.output_encoding = output_encoding;
/* Set some default values */ /* Set some default values */
s->metadata.x_resolution = T4_X_RESOLUTION_R8; s->metadata.x_resolution = T4_X_RESOLUTION_R8;

View File

@ -861,7 +861,7 @@ int main(int argc, char *argv[])
| T4_SUPPORT_RESOLUTION_600_1200 | T4_SUPPORT_RESOLUTION_600_1200
| T4_SUPPORT_RESOLUTION_1200_1200); | T4_SUPPORT_RESOLUTION_1200_1200);
t30_set_supported_colour_resolutions(t30_state[i], 0); t30_set_supported_colour_resolutions(t30_state[i], 0);
//t30_set_rx_encoding(t30_state[i], T4_COMPRESSION_T6); t30_set_supported_output_compressions(t30_state[i], T4_SUPPORT_COMPRESSION_T4_2D);
t30_set_ecm_capability(t30_state[i], use_ecm); t30_set_ecm_capability(t30_state[i], use_ecm);
t30_set_supported_compressions(t30_state[i], t30_set_supported_compressions(t30_state[i],
T4_SUPPORT_COMPRESSION_T4_1D T4_SUPPORT_COMPRESSION_T4_1D