Exemplo n.º 1
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;
}
Exemplo n.º 2
0
SPAN_DECLARE(int) t4_rx_end_page(t4_rx_state_t *s)
{
    int length;

    length = 0;
    switch (s->metadata.compression)
    {
    case T4_COMPRESSION_T4_1D:
    case T4_COMPRESSION_T4_2D:
    case T4_COMPRESSION_T6:
        t4_t6_decode_put(&s->decoder.t4_t6, NULL, 0);
        length = t4_t6_decode_get_image_length(&s->decoder.t4_t6);
        break;
    case T4_COMPRESSION_T85:
    case T4_COMPRESSION_T85_L0:
        t85_decode_put(&s->decoder.t85, NULL, 0);
        length = t85_decode_get_image_length(&s->decoder.t85);
        break;
#if defined(SPANDSP_SUPPORT_T88)
    case T4_COMPRESSION_T88:
        t88_decode_put(&s->decoder.t88, NULL, 0);
        length = t88_decode_get_image_length(&s->decoder.t88);
        break;
#endif
    case T4_COMPRESSION_T42_T81:
        t42_decode_put(&s->decoder.t42, NULL, 0);
        length = t42_decode_get_image_length(&s->decoder.t42);
        if (s->decoder.t42.samples_per_pixel == 3)
            select_tiff_compression(s, T4_IMAGE_TYPE_COLOUR_8BIT);
        else
            select_tiff_compression(s, T4_IMAGE_TYPE_GRAY_8BIT);
        break;
#if defined(SPANDSP_SUPPORT_T43)
    case T4_COMPRESSION_T43:
        t43_decode_put(&s->decoder.t43, NULL, 0);
        length = t43_decode_get_image_length(&s->decoder.t43);
        break;
#endif
#if defined(SPANDSP_SUPPORT_T45)
    case T4_COMPRESSION_T45:
        t45_decode_put(&s->decoder.t45, NULL, 0);
        length = t45_decode_get_image_length(&s->decoder.t45);
        break;
#endif
    }

    if (length == 0)
        return -1;

    if (s->tiff.tiff_file)
    {
        if (write_tiff_image(s) == 0)
            s->current_page++;
        s->tiff.image_size = 0;
    }
    else
    {
        s->current_page++;
    }
    return 0;
}