Exemple #1
0
SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int encoding)
{
    switch (encoding)
    {
    case T4_COMPRESSION_ITU_T4_1D:
    case T4_COMPRESSION_ITU_T4_2D:
    case T4_COMPRESSION_ITU_T6:
        switch (s->line_encoding)
        {
        case T4_COMPRESSION_ITU_T4_1D:
        case T4_COMPRESSION_ITU_T4_2D:
        case T4_COMPRESSION_ITU_T6:
            break;
        default:
            t4_t6_decode_init(&s->decoder.t4_t6, encoding, s->image_width, s->row_handler, s->row_handler_user_data);
            break;
        }
        s->line_encoding = encoding;
        return t4_t6_decode_set_encoding(&s->decoder.t4_t6, encoding);
    case T4_COMPRESSION_ITU_T42:
        switch (s->line_encoding)
        {
        case T4_COMPRESSION_ITU_T42:
            break;
        default:
            t42_decode_init(&s->decoder.t42, s->row_handler, s->row_handler_user_data);
            /* Constrain received images to the maximum width of any FAX. This will
               avoid one potential cause of trouble, where a bad received image has
               a gigantic dimension that sucks our memory dry. */
            t42_decode_set_image_size_constraints(&s->decoder.t42, T4_WIDTH_1200_A3, 0);
            break;
        }
        s->line_encoding = encoding;
        return 0;
#if defined(SPANDSP_SUPPORT_T43)
    case T4_COMPRESSION_ITU_T43:
        switch (s->line_encoding)
        {
        case T4_COMPRESSION_ITU_T43:
            break;
        default:
            t43_decode_init(&s->decoder.t43, s->row_handler, s->row_handler_user_data);
            /* Constrain received images to the maximum width of any FAX. This will
               avoid one potential cause of trouble, where a bad received image has
               a gigantic dimension that sucks our memory dry. */
            t43_decode_set_image_size_constraints(&s->decoder.t43, T4_WIDTH_1200_A3, 0);
            break;
        }
        s->line_encoding = encoding;
        return 0;
#endif
    case T4_COMPRESSION_ITU_T85:
    case T4_COMPRESSION_ITU_T85_L0:
        switch (s->line_encoding)
        {
        case T4_COMPRESSION_ITU_T85:
        case T4_COMPRESSION_ITU_T85_L0:
            break;
        default:
            t85_decode_init(&s->decoder.t85, s->row_handler, s->row_handler_user_data);
            /* Constrain received images to the maximum width of any FAX. This will
               avoid one potential cause of trouble, where a bad received image has
               a gigantic dimension that sucks our memory dry. */
            t85_decode_set_image_size_constraints(&s->decoder.t85, T4_WIDTH_1200_A3, 0);
            break;
        }
        s->line_encoding = encoding;
        return 0;
    }
    return -1;
}
Exemple #2
0
SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int compression)
{
    switch (compression)
    {
    case T4_COMPRESSION_T4_1D:
    case T4_COMPRESSION_T4_2D:
    case T4_COMPRESSION_T6:
        switch (s->metadata.compression)
        {
        case T4_COMPRESSION_T4_1D:
        case T4_COMPRESSION_T4_2D:
        case T4_COMPRESSION_T6:
            break;
        default:
            release_current_decoder(s);
            t4_t6_decode_init(&s->decoder.t4_t6, compression, s->metadata.image_width, s->row_handler, s->row_handler_user_data);
            s->current_decoder = T4_COMPRESSION_T4_1D | T4_COMPRESSION_T4_2D | T4_COMPRESSION_T6;
            break;
        }
        s->metadata.compression = compression;
        if (!select_tiff_compression(s, T4_IMAGE_TYPE_BILEVEL))
        {
            release_current_decoder(s);
            s->current_decoder = 0;
            pre_encoded_init(&s->decoder.no_decoder);
        }
        return t4_t6_decode_set_encoding(&s->decoder.t4_t6, compression);
    case T4_COMPRESSION_T85:
    case T4_COMPRESSION_T85_L0:
        switch (s->metadata.compression)
        {
        case T4_COMPRESSION_T85:
        case T4_COMPRESSION_T85_L0:
            break;
        default:
            release_current_decoder(s);
            t85_decode_init(&s->decoder.t85, s->row_handler, s->row_handler_user_data);
            s->current_decoder = T4_COMPRESSION_T85 | T4_COMPRESSION_T85_L0;
            /* Constrain received images to the maximum width of any FAX. This will
               avoid one potential cause of trouble, where a bad received image has
               a gigantic dimension that sucks our memory dry. */
            t85_decode_set_image_size_constraints(&s->decoder.t85, T4_WIDTH_1200_A3, 0);
            break;
        }
        s->metadata.compression = compression;
        if (!select_tiff_compression(s, T4_IMAGE_TYPE_BILEVEL))
        {
            release_current_decoder(s);
            s->current_decoder = 0;
            pre_encoded_init(&s->decoder.no_decoder);
        }
        return 0;
#if defined(SPANDSP_SUPPORT_T88)
    case T4_COMPRESSION_T88:
        switch (s->metadata.compression)
        {
        case T4_COMPRESSION_T88:
            break;
        default:
            release_current_decoder(s);
            t88_decode_init(&s->decoder.t88, s->row_handler, s->row_handler_user_data);
            s->current_decoder = T4_COMPRESSION_T88;
            break;
        }
        s->metadata.compression = compression;
        if (!select_tiff_compression(s, T4_IMAGE_TYPE_BILEVEL))
        {
            release_current_decoder(s);
            s->current_decoder = 0;
            pre_encoded_init(&s->decoder.no_decoder);
        }
        return 0;
#endif
    case T4_COMPRESSION_T42_T81:
    case T4_COMPRESSION_SYCC_T81:
        switch (s->metadata.compression)
        {
        case T4_COMPRESSION_T42_T81:
        case T4_COMPRESSION_SYCC_T81:
            break;
        default:
            release_current_decoder(s);
            t42_decode_init(&s->decoder.t42, s->row_handler, s->row_handler_user_data);
            s->current_decoder = T4_COMPRESSION_T42_T81;
            /* Constrain received images to the maximum width of any FAX. This will
               avoid one potential cause of trouble, where a bad received image has
               a gigantic dimension that sucks our memory dry. */
            t42_decode_set_image_size_constraints(&s->decoder.t42, T4_WIDTH_1200_A3, 0);
            break;
        }
        s->metadata.compression = compression;
        if (!select_tiff_compression(s, T4_IMAGE_TYPE_COLOUR_8BIT))
        {
            release_current_decoder(s);
            s->current_decoder = 0;
            pre_encoded_init(&s->decoder.no_decoder);
        }
        return 0;
    case T4_COMPRESSION_T43:
        switch (s->metadata.compression)
        {
        case T4_COMPRESSION_T43:
            break;
        default:
            release_current_decoder(s);
            t43_decode_init(&s->decoder.t43, s->row_handler, s->row_handler_user_data);
            s->current_decoder = T4_COMPRESSION_T43;
            /* Constrain received images to the maximum width of any FAX. This will
               avoid one potential cause of trouble, where a bad received image has
               a gigantic dimension that sucks our memory dry. */
            t43_decode_set_image_size_constraints(&s->decoder.t43, T4_WIDTH_1200_A3, 0);
            break;
        }
        s->metadata.compression = compression;
        if (!select_tiff_compression(s, T4_IMAGE_TYPE_COLOUR_8BIT))
        {
            release_current_decoder(s);
            s->current_decoder = 0;
            pre_encoded_init(&s->decoder.no_decoder);
        }
        return 0;
#if defined(SPANDSP_SUPPORT_T45)
    case T4_COMPRESSION_T45:
        switch (s->metadata.compression)
        {
        case T4_COMPRESSION_T45:
            break;
        default:
            release_current_decoder(s);
            t45_decode_init(&s->decoder.t45, s->row_handler, s->row_handler_user_data);
            s->current_decoder = T4_COMPRESSION_T45;
            break;
        }
        s->metadata.compression = compression;
        if (!select_tiff_compression(s, T4_IMAGE_TYPE_COLOUR_8BIT))
        {
            release_current_decoder(s);
            s->current_decoder = 0;
            pre_encoded_init(&s->decoder.no_decoder);
        }
        return 0;
#endif
    }

    return -1;
}