Ejemplo n.º 1
0
SPAN_DECLARE(int) t4_rx_end_page(t4_rx_state_t *s)
{
    int length;

    length = 0;

    if (s->image_put_handler)
        s->image_put_handler((void *) &s->decoder, NULL, 0);

    switch (s->current_decoder)
    {
    case 0:
        length = s->decoder.no_decoder.buf_ptr;
        break;
    case T4_COMPRESSION_T4_1D | T4_COMPRESSION_T4_2D | T4_COMPRESSION_T6:
        length = t4_t6_decode_get_image_length(&s->decoder.t4_t6);
        break;
    case T4_COMPRESSION_T85 | T4_COMPRESSION_T85_L0:
        length = t85_decode_get_image_length(&s->decoder.t85);
        break;
#if defined(SPANDSP_SUPPORT_T88)
    case T4_COMPRESSION_T88:
        length = t88_decode_get_image_length(&s->decoder.t88);
        break;
#endif
    case T4_COMPRESSION_T42_T81:
        length = t42_decode_get_image_length(&s->decoder.t42);
        if (s->decoder.t42.samples_per_pixel == 3)
            s->tiff.image_type = T4_IMAGE_TYPE_COLOUR_8BIT;
        else
            s->tiff.image_type = T4_IMAGE_TYPE_GRAY_8BIT;
        break;
    case T4_COMPRESSION_T43:
        length = t43_decode_get_image_length(&s->decoder.t43);
        break;
#if defined(SPANDSP_SUPPORT_T45)
    case T4_COMPRESSION_T45:
        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;
}
Ejemplo n.º 2
0
SPAN_DECLARE(void) t4_rx_get_transfer_statistics(t4_rx_state_t *s, t4_stats_t *t)
{
    memset(t, 0, sizeof(*t));
    t->pages_transferred = s->current_page;
    t->pages_in_file = s->tiff.pages_in_file;
    t->image_x_resolution = s->metadata.x_resolution;
    t->image_y_resolution = s->metadata.y_resolution;
    t->x_resolution = s->metadata.x_resolution;
    t->y_resolution = s->metadata.y_resolution;
    t->encoding = s->line_encoding;
    switch (s->line_encoding)
    {
    case T4_COMPRESSION_ITU_T4_1D:
    case T4_COMPRESSION_ITU_T4_2D:
    case T4_COMPRESSION_ITU_T6:
        t->type = T4_IMAGE_TYPE_BILEVEL;
        t->width = t4_t6_decode_get_image_width(&s->decoder.t4_t6);
        t->length = t4_t6_decode_get_image_length(&s->decoder.t4_t6);
        t->image_type = t->type;
        t->image_width = t->width;
        t->image_length = t->length;
        t->line_image_size = t4_t6_decode_get_compressed_image_size(&s->decoder.t4_t6)/8;
        t->bad_rows = s->decoder.t4_t6.bad_rows;
        t->longest_bad_row_run = s->decoder.t4_t6.longest_bad_row_run;
        break;
    case T4_COMPRESSION_ITU_T42:
        t->type = 0;
        t->width = t42_decode_get_image_width(&s->decoder.t42);
        t->length = t42_decode_get_image_length(&s->decoder.t42);
        t->image_type = t->type;
        t->image_width = t->width;
        t->image_length = t->length;
        t->line_image_size = t42_decode_get_compressed_image_size(&s->decoder.t42)/8;
        break;
#if defined(SPANDSP_SUPPORT_T43)
    case T4_COMPRESSION_ITU_T43:
        t->type = 0;
        t->width = t43_decode_get_image_width(&s->decoder.t43);
        t->length = t43_decode_get_image_length(&s->decoder.t43);
        t->image_type = t->type;
        t->image_width = t->width;
        t->image_length = t->length;
        t->line_image_size = t43_decode_get_compressed_image_size(&s->decoder.t43)/8;
        break;
#endif
    case T4_COMPRESSION_ITU_T85:
    case T4_COMPRESSION_ITU_T85_L0:
        t->type = T4_IMAGE_TYPE_BILEVEL;
        t->width = t85_decode_get_image_width(&s->decoder.t85);
        t->length = t85_decode_get_image_length(&s->decoder.t85);
        t->image_type = t->type;
        t->image_width = t->width;
        t->image_length = t->length;
        t->line_image_size = t85_decode_get_compressed_image_size(&s->decoder.t85)/8;
        break;
    }
}
Ejemplo n.º 3
0
SPAN_DECLARE(int) t4_rx_end_page(t4_rx_state_t *s)
{
    int length;

    length = 0;
    switch (s->line_encoding)
    {
    case T4_COMPRESSION_ITU_T4_1D:
    case T4_COMPRESSION_ITU_T4_2D:
    case T4_COMPRESSION_ITU_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_ITU_T42:
        t42_decode_put(&s->decoder.t42, NULL, 0);
        length = t42_decode_get_image_length(&s->decoder.t42);
        break;
#if defined(SPANDSP_SUPPORT_T43)
    case T4_COMPRESSION_ITU_T43:
        t43_decode_put(&s->decoder.t43, NULL, 0);
        length = t43_decode_get_image_length(&s->decoder.t43);
        break;
#endif
    case T4_COMPRESSION_ITU_T85:
    case T4_COMPRESSION_ITU_T85_L0:
        t85_decode_put(&s->decoder.t85, NULL, 0);
        length = t85_decode_get_image_length(&s->decoder.t85);
        break;
    }

    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;
}
Ejemplo n.º 4
0
static int set_tiff_directory_info(t4_rx_state_t *s)
{
    time_t now;
    struct tm *tm;
    char buf[256 + 1];
    uint16_t resunit;
    float x_resolution;
    float y_resolution;
    t4_rx_tiff_state_t *t;
    int32_t output_compression;
    int32_t output_t4_options;

    t = &s->tiff;
    /* Prepare the directory entry fully before writing the image, or libtiff complains */
    switch (t->output_encoding)
    {
    case T4_COMPRESSION_ITU_T6:
        output_compression = COMPRESSION_CCITT_T6;
        output_t4_options = 0;
        break;
    case T4_COMPRESSION_ITU_T4_2D:
        output_compression = COMPRESSION_CCITT_T4;
        output_t4_options = GROUP3OPT_FILLBITS | GROUP3OPT_2DENCODING;
        break;
    default:
        output_compression = COMPRESSION_CCITT_T4;
        output_t4_options = GROUP3OPT_FILLBITS;
        break;
    }

    TIFFSetField(t->tiff_file, TIFFTAG_COMPRESSION, output_compression);
    switch (output_compression)
    {
    case COMPRESSION_CCITT_T4:
        TIFFSetField(t->tiff_file, TIFFTAG_T4OPTIONS, output_t4_options);
        TIFFSetField(t->tiff_file, TIFFTAG_FAXMODE, FAXMODE_CLASSF);
        break;
    case COMPRESSION_CCITT_T6:
        TIFFSetField(t->tiff_file, TIFFTAG_T6OPTIONS, 0);
        TIFFSetField(t->tiff_file, TIFFTAG_FAXMODE, FAXMODE_CLASSF);
        break;
    }
#if defined(SPANDSP_SUPPORT_TIFF_FX)
    TIFFSetField(t->tiff_file, TIFFTAG_PROFILETYPE, PROFILETYPE_G3_FAX);
    TIFFSetField(t->tiff_file, TIFFTAG_FAXPROFILE, FAXPROFILE_S);
    TIFFSetField(t->tiff_file, TIFFTAG_CODINGMETHODS, CODINGMETHODS_T4_1D | CODINGMETHODS_T4_2D | CODINGMETHODS_T6);
    TIFFSetField(t->tiff_file, TIFFTAG_VERSIONYEAR, "1998");
    /* TIFFSetField(t->tiff_file, TIFFTAG_MODENUMBER, 0); */
#endif
    TIFFSetField(t->tiff_file, TIFFTAG_BITSPERSAMPLE, 1);
    TIFFSetField(t->tiff_file, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
    TIFFSetField(t->tiff_file, TIFFTAG_SAMPLESPERPIXEL, 1);
    if (output_compression == COMPRESSION_CCITT_T4
        ||
        output_compression == COMPRESSION_CCITT_T6)
    {
        TIFFSetField(t->tiff_file, TIFFTAG_ROWSPERSTRIP, -1L);
    }
    else
    {
        TIFFSetField(t->tiff_file,
                     TIFFTAG_ROWSPERSTRIP,
                     TIFFDefaultStripSize(t->tiff_file, 0));
    }
    TIFFSetField(t->tiff_file, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
    TIFFSetField(t->tiff_file, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
    TIFFSetField(t->tiff_file, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB);

    x_resolution = s->metadata.x_resolution/100.0f;
    y_resolution = s->metadata.y_resolution/100.0f;
    /* Metric seems the sane thing to use in the 21st century, but a lot of lousy software
       gets FAX resolutions wrong, and more get it wrong using metric than using inches. */
#if 0
    TIFFSetField(t->tiff_file, TIFFTAG_XRESOLUTION, x_resolution);
    TIFFSetField(t->tiff_file, TIFFTAG_YRESOLUTION, y_resolution);
    resunit = RESUNIT_CENTIMETER;
    TIFFSetField(t->tiff_file, TIFFTAG_RESOLUTIONUNIT, resunit);
#else
    TIFFSetField(t->tiff_file, TIFFTAG_XRESOLUTION, floorf(x_resolution*CM_PER_INCH + 0.5f));
    TIFFSetField(t->tiff_file, TIFFTAG_YRESOLUTION, floorf(y_resolution*CM_PER_INCH + 0.5f));
    resunit = RESUNIT_INCH;
    TIFFSetField(t->tiff_file, TIFFTAG_RESOLUTIONUNIT, resunit);
#endif
    TIFFSetField(t->tiff_file, TIFFTAG_SOFTWARE, "Spandsp " SPANDSP_RELEASE_DATETIME_STRING);
    if (gethostname(buf, sizeof(buf)) == 0)
        TIFFSetField(t->tiff_file, TIFFTAG_HOSTCOMPUTER, buf);

#if defined(TIFFTAG_FAXDCS)
    if (s->metadata.dcs)
        TIFFSetField(t->tiff_file, TIFFTAG_FAXDCS, s->metadata.dcs);
#endif
    if (s->metadata.sub_address)
        TIFFSetField(t->tiff_file, TIFFTAG_FAXSUBADDRESS, s->metadata.sub_address);
    if (s->metadata.far_ident)
        TIFFSetField(t->tiff_file, TIFFTAG_IMAGEDESCRIPTION, s->metadata.far_ident);
    if (s->metadata.vendor)
        TIFFSetField(t->tiff_file, TIFFTAG_MAKE, s->metadata.vendor);
    if (s->metadata.model)
        TIFFSetField(t->tiff_file, TIFFTAG_MODEL, s->metadata.model);

    time(&now);
    tm = localtime(&now);
    sprintf(buf,
            "%4d/%02d/%02d %02d:%02d:%02d",
            tm->tm_year + 1900,
            tm->tm_mon + 1,
            tm->tm_mday,
            tm->tm_hour,
            tm->tm_min,
            tm->tm_sec);
    TIFFSetField(t->tiff_file, TIFFTAG_DATETIME, buf);
    TIFFSetField(t->tiff_file, TIFFTAG_FAXRECVTIME, now - s->tiff.page_start_time);

    TIFFSetField(t->tiff_file, TIFFTAG_IMAGEWIDTH, s->image_width);
    /* Set the total pages to 1. For any one page document we will get this
       right. For multi-page documents we will need to come back and fill in
       the right answer when we know it. */
    TIFFSetField(t->tiff_file, TIFFTAG_PAGENUMBER, s->current_page, 1);
    /* TIFF page numbers start from zero, so the number of pages in the file
       is always one greater than the highest page number in the file. */
    s->tiff.pages_in_file = s->current_page + 1;
    switch (s->line_encoding)
    {
    case T4_COMPRESSION_ITU_T4_1D:
    case T4_COMPRESSION_ITU_T4_2D:
        /* We only get bad row info from pages received in non-ECM mode. */
        if (output_compression == COMPRESSION_CCITT_T4)
        {
            if (s->decoder.t4_t6.bad_rows)
            {
                TIFFSetField(t->tiff_file, TIFFTAG_BADFAXLINES, s->decoder.t4_t6.bad_rows);
                TIFFSetField(t->tiff_file, TIFFTAG_CONSECUTIVEBADFAXLINES, s->decoder.t4_t6.longest_bad_row_run);
                TIFFSetField(t->tiff_file, TIFFTAG_CLEANFAXDATA, CLEANFAXDATA_REGENERATED);
            }
            else
            {
                TIFFSetField(t->tiff_file, TIFFTAG_CLEANFAXDATA, CLEANFAXDATA_CLEAN);
            }
        }
        /* Fall through */
    case T4_COMPRESSION_ITU_T6:
        TIFFSetField(t->tiff_file, TIFFTAG_IMAGELENGTH, t4_t6_decode_get_image_length(&s->decoder.t4_t6));
        break;
    case T4_COMPRESSION_ITU_T42:
        TIFFSetField(t->tiff_file, TIFFTAG_IMAGELENGTH, t42_decode_get_image_length(&s->decoder.t42));
        break;
#if defined(SPANDSP_SUPPORT_T43)
    case T4_COMPRESSION_ITU_T43:
        TIFFSetField(t->tiff_file, TIFFTAG_IMAGELENGTH, t43_decode_get_image_length(&s->decoder.t43));
        break;
#endif
    case T4_COMPRESSION_ITU_T85:
    case T4_COMPRESSION_ITU_T85_L0:
        TIFFSetField(t->tiff_file, TIFFTAG_IMAGELENGTH, t85_decode_get_image_length(&s->decoder.t85));
        break;
    }
    return 0;
}
Ejemplo n.º 5
0
static int set_tiff_directory_info(t4_rx_state_t *s)
{
    time_t now;
    struct tm *tm;
    char buf[256 + 1];
    uint16_t resunit;
    float x_resolution;
    float y_resolution;
    t4_rx_tiff_state_t *t;
    int32_t output_compression;
    int32_t output_t4_options;
    int bits_per_sample;
    int samples_per_pixel;
    int photometric;
    uint32_t width;
    uint32_t length;

    t = &s->tiff;
    /* Prepare the directory entry fully before writing the image, or libtiff complains */
    bits_per_sample = 1;
    samples_per_pixel = 1;
    photometric = PHOTOMETRIC_MINISWHITE;
    output_t4_options = 0;
    switch (t->compression)
    {
    case T4_COMPRESSION_T4_1D:
    default:
        output_compression = COMPRESSION_CCITT_T4;
        output_t4_options = GROUP3OPT_FILLBITS;
        break;
    case T4_COMPRESSION_T4_2D:
        output_compression = COMPRESSION_CCITT_T4;
        output_t4_options = GROUP3OPT_FILLBITS | GROUP3OPT_2DENCODING;
        break;
    case T4_COMPRESSION_T6:
        output_compression = COMPRESSION_CCITT_T6;
        break;
    case T4_COMPRESSION_T85:
    case T4_COMPRESSION_T85_L0:
        output_compression = COMPRESSION_T85;
        break;
#if defined(SPANDSP_SUPPORT_T88)
    case T4_COMPRESSION_T88:
        output_compression = COMPRESSION_T88;
        break;
#endif
    case T4_COMPRESSION_JPEG:
        output_compression = COMPRESSION_JPEG;
        bits_per_sample = 8;
        if (t->image_type == T4_IMAGE_TYPE_COLOUR_8BIT)
        {
            samples_per_pixel = 3;
            photometric = PHOTOMETRIC_YCBCR;
        }
        else
        {
            samples_per_pixel = 1;
            photometric = PHOTOMETRIC_MINISBLACK;
        }
        break;
    case T4_COMPRESSION_T42_T81:
        output_compression = COMPRESSION_JPEG;
        bits_per_sample = 8;
        if (t->image_type == T4_IMAGE_TYPE_COLOUR_8BIT)
        {
            samples_per_pixel = 3;
            photometric = PHOTOMETRIC_ITULAB;
        }
        else
        {
            samples_per_pixel = 1;
            photometric = PHOTOMETRIC_MINISBLACK;
        }
        break;
    case T4_COMPRESSION_SYCC_T81:
        output_compression = COMPRESSION_JPEG;
        bits_per_sample = 8;
        if (t->image_type == T4_IMAGE_TYPE_COLOUR_8BIT)
        {
            samples_per_pixel = 3;
            photometric = PHOTOMETRIC_YCBCR;
        }
        else
        {
            samples_per_pixel = 1;
            photometric = PHOTOMETRIC_MINISBLACK;
        }
        break;
    case T4_COMPRESSION_T43:
        output_compression = COMPRESSION_T43;
        bits_per_sample = 8;
        samples_per_pixel = 3;
        photometric = PHOTOMETRIC_ITULAB;
        break;
#if defined(SPANDSP_SUPPORT_T45)
    case T4_COMPRESSION_T45:
        output_compression = COMPRESSION_T45;
        bits_per_sample = 8;
        samples_per_pixel = 3;
        photometric = PHOTOMETRIC_ITULAB;
        break;
#endif
    }

    TIFFSetField(t->tiff_file, TIFFTAG_COMPRESSION, output_compression);
    switch (output_compression)
    {
    case COMPRESSION_CCITT_T4:
        TIFFSetField(t->tiff_file, TIFFTAG_T4OPTIONS, output_t4_options);
        TIFFSetField(t->tiff_file, TIFFTAG_FAXMODE, FAXMODE_CLASSF);
        break;
    case COMPRESSION_CCITT_T6:
        TIFFSetField(t->tiff_file, TIFFTAG_T6OPTIONS, 0);
        TIFFSetField(t->tiff_file, TIFFTAG_FAXMODE, FAXMODE_CLASSF);
        break;
    case COMPRESSION_T85:
        TIFFSetField(t->tiff_file, TIFFTAG_FAXMODE, FAXMODE_CLASSF);
        break;
    case COMPRESSION_JPEG:
        TIFFSetField(t->tiff_file, TIFFTAG_FAXMODE, FAXMODE_CLASSF);
        break;
    case COMPRESSION_T43:
        TIFFSetField(t->tiff_file, TIFFTAG_FAXMODE, FAXMODE_CLASSF);
        break;
    }
    TIFFSetField(t->tiff_file, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
    TIFFSetField(t->tiff_file, TIFFTAG_BITSPERSAMPLE, bits_per_sample);
    TIFFSetField(t->tiff_file, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel);
    TIFFSetField(t->tiff_file, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
    TIFFSetField(t->tiff_file, TIFFTAG_PHOTOMETRIC, photometric);
    TIFFSetField(t->tiff_file, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB);
    switch (t->compression)
    {
    case T4_COMPRESSION_JPEG:
        TIFFSetField(t->tiff_file, TIFFTAG_YCBCRSUBSAMPLING, 2, 2);
        //TIFFSetField(t->tiff_file, TIFFTAG_YCBCRSUBSAMPLING, 1, 1);
        TIFFSetField(t->tiff_file, TIFFTAG_JPEGQUALITY, 75);
        TIFFSetField(t->tiff_file, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
        break;
    case T4_COMPRESSION_T42_T81:
        TIFFSetField(t->tiff_file, TIFFTAG_YCBCRSUBSAMPLING, 2, 2);
        //TIFFSetField(t->tiff_file, TIFFTAG_YCBCRSUBSAMPLING, 1, 1);
        TIFFSetField(t->tiff_file, TIFFTAG_JPEGQUALITY, 75);
        TIFFSetField(t->tiff_file, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
        break;
    }
    /* TIFFTAG_STRIPBYTECOUNTS and TIFFTAG_STRIPOFFSETS are added automatically */

    x_resolution = s->metadata.x_resolution/100.0f;
    y_resolution = s->metadata.y_resolution/100.0f;
    /* Metric seems the sane thing to use in the 21st century, but a lot of lousy software
       gets FAX resolutions wrong, and more get it wrong using metric than using inches. */
#if 0
    TIFFSetField(t->tiff_file, TIFFTAG_XRESOLUTION, x_resolution);
    TIFFSetField(t->tiff_file, TIFFTAG_YRESOLUTION, y_resolution);
    resunit = RESUNIT_CENTIMETER;
    TIFFSetField(t->tiff_file, TIFFTAG_RESOLUTIONUNIT, resunit);
#else
    TIFFSetField(t->tiff_file, TIFFTAG_XRESOLUTION, floorf(x_resolution*CM_PER_INCH + 0.5f));
    TIFFSetField(t->tiff_file, TIFFTAG_YRESOLUTION, floorf(y_resolution*CM_PER_INCH + 0.5f));
    resunit = RESUNIT_INCH;
    TIFFSetField(t->tiff_file, TIFFTAG_RESOLUTIONUNIT, resunit);
#endif
    TIFFSetField(t->tiff_file, TIFFTAG_SOFTWARE, "Spandsp " SPANDSP_RELEASE_DATETIME_STRING);
    if (gethostname(buf, sizeof(buf)) == 0)
        TIFFSetField(t->tiff_file, TIFFTAG_HOSTCOMPUTER, buf);

#if defined(TIFFTAG_FAXDCS)
    if (s->metadata.dcs)
        TIFFSetField(t->tiff_file, TIFFTAG_FAXDCS, s->metadata.dcs);
#endif
    if (s->metadata.sub_address)
        TIFFSetField(t->tiff_file, TIFFTAG_FAXSUBADDRESS, s->metadata.sub_address);
    if (s->metadata.far_ident)
        TIFFSetField(t->tiff_file, TIFFTAG_IMAGEDESCRIPTION, s->metadata.far_ident);
    if (s->metadata.vendor)
        TIFFSetField(t->tiff_file, TIFFTAG_MAKE, s->metadata.vendor);
    if (s->metadata.model)
        TIFFSetField(t->tiff_file, TIFFTAG_MODEL, s->metadata.model);

    time(&now);
    tm = localtime(&now);
    sprintf(buf,
            "%4d/%02d/%02d %02d:%02d:%02d",
            tm->tm_year + 1900,
            tm->tm_mon + 1,
            tm->tm_mday,
            tm->tm_hour,
            tm->tm_min,
            tm->tm_sec);
    TIFFSetField(t->tiff_file, TIFFTAG_DATETIME, buf);
    TIFFSetField(t->tiff_file, TIFFTAG_FAXRECVTIME, now - s->tiff.page_start_time);

    TIFFSetField(t->tiff_file, TIFFTAG_IMAGEWIDTH, s->metadata.image_width);
    /* Set the total pages to 1. For any one page document we will get this
       right. For multi-page documents we will need to come back and fill in
       the right answer when we know it. */
    TIFFSetField(t->tiff_file, TIFFTAG_PAGENUMBER, s->current_page, 1);
    /* TIFF page numbers start from zero, so the number of pages in the file
       is always one greater than the highest page number in the file. */
    s->tiff.pages_in_file = s->current_page + 1;
    s->metadata.image_length = 0;
    switch (s->current_decoder)
    {
    case 0:
        switch (t->compression)
        {
        case T4_COMPRESSION_T42_T81:
        case T4_COMPRESSION_SYCC_T81:
            t42_analyse_header(&width, &length, s->decoder.no_decoder.buf, s->decoder.no_decoder.buf_ptr);
            s->metadata.image_width = width;
            s->metadata.image_length = length;
            break;
        case T4_COMPRESSION_T85:
        case T4_COMPRESSION_T85_L0:
            t85_analyse_header(&width, &length, s->decoder.no_decoder.buf, s->decoder.no_decoder.buf_ptr);
            s->metadata.image_width = width;
            s->metadata.image_length = length;
            break;
        }
        break;
    case T4_COMPRESSION_T4_1D | T4_COMPRESSION_T4_2D | T4_COMPRESSION_T6:
        if ((s->metadata.compression & (T4_COMPRESSION_T4_1D | T4_COMPRESSION_T4_2D)))
        {
            /* We only get bad row info from pages received in non-ECM mode. */
            if (output_compression == COMPRESSION_CCITT_T4)
            {
                if (s->decoder.t4_t6.bad_rows)
                {
                    TIFFSetField(t->tiff_file, TIFFTAG_BADFAXLINES, s->decoder.t4_t6.bad_rows);
                    TIFFSetField(t->tiff_file, TIFFTAG_CONSECUTIVEBADFAXLINES, s->decoder.t4_t6.longest_bad_row_run);
                    TIFFSetField(t->tiff_file, TIFFTAG_CLEANFAXDATA, CLEANFAXDATA_REGENERATED);
                }
                else
                {
                    TIFFSetField(t->tiff_file, TIFFTAG_CLEANFAXDATA, CLEANFAXDATA_CLEAN);
                }
            }
        }
        s->metadata.image_length = t4_t6_decode_get_image_length(&s->decoder.t4_t6);
        break;
    case T4_COMPRESSION_T85 | T4_COMPRESSION_T85_L0:
        s->metadata.image_length = t85_decode_get_image_length(&s->decoder.t85);
        break;
#if defined(SPANDSP_SUPPORT_T88)
    case T4_COMPRESSION_T88:
        s->metadata.image_length = t88_decode_get_image_length(&s->decoder.t88);
        break;
#endif
    case T4_COMPRESSION_T42_T81:
        s->metadata.image_length = t42_decode_get_image_length(&s->decoder.t42);
        break;
    case T4_COMPRESSION_T43:
        s->metadata.image_length = t43_decode_get_image_length(&s->decoder.t43);
        break;
#if defined(SPANDSP_SUPPORT_T45)
    case T4_COMPRESSION_T45:
        s->metadata.image_length = t45_decode_get_image_length(&s->decoder.t45);
        break;
#endif
    }
    TIFFSetField(t->tiff_file, TIFFTAG_IMAGELENGTH, s->metadata.image_length);
    TIFFSetField(t->tiff_file, TIFFTAG_ROWSPERSTRIP, s->metadata.image_length);
#if defined(SPANDSP_SUPPORT_TIFF_FX)
    TIFFSetField(t->tiff_file, TIFFTAG_PROFILETYPE, PROFILETYPE_G3_FAX);
    TIFFSetField(t->tiff_file, TIFFTAG_FAXPROFILE, FAXPROFILE_S);
    TIFFSetField(t->tiff_file, TIFFTAG_CODINGMETHODS, CODINGMETHODS_T4_1D | CODINGMETHODS_T4_2D | CODINGMETHODS_T6);
    TIFFSetField(t->tiff_file, TIFFTAG_VERSIONYEAR, "1998");
    if (s->current_page == 0)
    {
        /* Create a placeholder for the global parameters IFD, to be filled in later */
        TIFFSetField(t->tiff_file, TIFFTAG_GLOBALPARAMETERSIFD, 0);
    }

#if 0
    /* Paletised image? */
    TIFFSetField(t->tiff_file, TIFFTAG_INDEXED, 1);
    /* T.44 mode */
    TIFFSetField(t->tiff_file, TIFFTAG_MODENUMBER, 0);
    span_log(&s->logging, SPAN_LOG_FLOW, "TIFF/FX stuff 2\n");
    {
        float xxx[] = {20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0};
        TIFFSetField(t->tiff_file, TIFFTAG_DECODE, (uint16) 2*samples_per_pixel, xxx);
    }
    span_log(&s->logging, SPAN_LOG_FLOW, "TIFF/FX stuff 3\n");
    {
        uint16_t xxx[] = {12, 34, 45, 67};
        TIFFSetField(t->tiff_file, TIFFTAG_IMAGEBASECOLOR, (uint16_t) samples_per_pixel, xxx);
    }
    span_log(&s->logging, SPAN_LOG_FLOW, "TIFF/FX stuff 4\n");
    TIFFSetField(t->tiff_file, TIFFTAG_T82OPTIONS, 0);
    {
        uint32_t xxx[] = {34, 56, 78, 90};
        TIFFSetField(t->tiff_file, TIFFTAG_STRIPROWCOUNTS, (uint16_t) 5, xxx);
    }
    span_log(&s->logging, SPAN_LOG_FLOW, "TIFF/FX stuff 5\n");
    {
        uint32_t xxx[] = {2, 3};
        TIFFSetField(t->tiff_file, TIFFTAG_IMAGELAYER, xxx);
    }
#endif
#endif
    return 0;
}
Ejemplo n.º 6
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;
}