コード例 #1
0
ファイル: t4_rx.c プロジェクト: AbrahamJewowich/FreeSWITCH
static void write_tiff_image(t4_state_t *s)
{
    /* Set up the TIFF directory info... */
    set_tiff_directory_info(s);
    /* ..and then write the image... */
    if (TIFFWriteEncodedStrip(s->tiff.tiff_file, 0, s->image_buffer, s->image_length*s->bytes_per_row) < 0)
        span_log(&s->logging, SPAN_LOG_WARNING, "%s: Error writing TIFF strip.\n", s->tiff.file);
    /* ...then the directory entry, and libtiff is happy. */
    TIFFWriteDirectory(s->tiff.tiff_file);
}
コード例 #2
0
static int write_tiff_image(t4_rx_state_t *s)
{
    if (s->tiff.image_buffer == NULL  ||  s->tiff.image_size <= 0)
        return -1;
    /* Set up the TIFF directory info... */
    set_tiff_directory_info(s);
    /* ...and then write the image... */
    if (TIFFWriteEncodedStrip(s->tiff.tiff_file, 0, s->tiff.image_buffer, s->tiff.image_size) < 0)
        span_log(&s->logging, SPAN_LOG_WARNING, "%s: Error writing TIFF strip.\n", s->tiff.file);
    /* ...then the directory entry, and libtiff is happy. */
    TIFFWriteDirectory(s->tiff.tiff_file);
    return 0;
}
コード例 #3
0
ファイル: t4_rx.c プロジェクト: avimar/FreeSWITCH
static int write_tiff_image(t4_rx_state_t *s)
{
    t4_rx_tiff_state_t *t;
#if defined(SPANDSP_SUPPORT_TIFF_FX)
    uint64_t offset;
#endif

    t = &s->tiff;
    if (t->image_buffer == NULL  ||  t->image_size <= 0)
        return -1;
    /* Set up the TIFF directory info... */
    set_tiff_directory_info(s);
    /* ...Put the directory in the file before the image data, to get them in the order specified
       for TIFF/F files... */
    if (!TIFFCheckpointDirectory(t->tiff_file))
        span_log(&s->logging, SPAN_LOG_WARNING, "%s: Failed to checkpoint directory for page %d.\n", t->file, s->current_page);
    /* ...and write out the image... */
    if (TIFFWriteEncodedStrip(t->tiff_file, 0, t->image_buffer, t->image_size) < 0)
        span_log(&s->logging, SPAN_LOG_WARNING, "%s: Error writing TIFF strip.\n", t->file);
    /* ...then finalise the directory entry, and libtiff is happy. */
    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);
#if defined(SPANDSP_SUPPORT_TIFF_FX)
    if (s->current_page == 0)
    {
        if (!TIFFCreateCustomDirectory(t->tiff_file, &tiff_fx_field_array))
        {
            TIFFSetField(t->tiff_file, TIFFTAG_FAXPROFILE, PROFILETYPE_G3_FAX);
            TIFFSetField(t->tiff_file, TIFFTAG_PROFILETYPE, FAXPROFILE_F);
            TIFFSetField(t->tiff_file, TIFFTAG_VERSIONYEAR, "1998");

            offset = 0;
            if (!TIFFWriteCustomDirectory(t->tiff_file, &offset))
                printf("Failed to write custom directory.\n");

            /* Now go back and patch in the pointer to the new IFD */
            if (!TIFFSetDirectory(t->tiff_file, s->current_page))
                printf("Failed to set directory.\n");
            if (!TIFFSetField(t->tiff_file, TIFFTAG_GLOBALPARAMETERSIFD, offset))
                printf("Failed to set field.\n");
            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);
        }
    }
#endif
    return 0;
}
コード例 #4
0
ファイル: t4_rx.c プロジェクト: odmanV2/freecenter
static int write_tiff_image(t4_rx_state_t *s)
{
    t4_rx_tiff_state_t *t;
#if defined(SPANDSP_SUPPORT_TIFF_FX)  &&  TIFFLIB_VERSION >= 20120922  &&  defined(HAVE_TIF_DIR_H)
    toff_t diroff;
#endif

    t = &s->tiff;
    if (s->decoder.no_decoder.buf_ptr <= 0  &&  (t->image_buffer == NULL  ||  t->image_size <= 0))
        return -1;
    /* Set up the TIFF directory info... */
    set_tiff_directory_info(s);
    /* ...Put the directory in the file before the image data, to get them in the order specified
       for TIFF/F files... */
    //if (!TIFFCheckpointDirectory(t->tiff_file))
    //    span_log(&s->logging, SPAN_LOG_WARNING, "%s: Failed to checkpoint directory for page %d.\n", t->file, s->current_page);
    /* ...and write out the image... */
    if (s->current_decoder == 0)
    {
        if (TIFFWriteRawStrip(s->tiff.tiff_file, 0, s->decoder.no_decoder.buf, s->decoder.no_decoder.buf_ptr) < 0)
            span_log(&s->logging, SPAN_LOG_WARNING, "%s: Error writing TIFF strip.\n", s->tiff.file);
    }
    else
    {
        switch (t->compression)
        {
        case T4_COMPRESSION_T85:
        case T4_COMPRESSION_T85_L0:
            /* We need to perform this compression here, as libtiff does not understand it. */
            if (write_tiff_t85_image(s) < 0)
                return -1;
            break;
#if defined(SPANDSP_SUPPORT_T88)
        case T4_COMPRESSION_T88:
            /* We need to perform this compression here, as libtiff does not understand it. */
            if (write_tiff_t88_image(s) < 0)
                return -1;
            break;
#endif
        case T4_COMPRESSION_T43:
            /* We need to perform this compression here, as libtiff does not understand it. */
            if (write_tiff_t43_image(s) < 0)
                return -1;
            break;
#if defined(SPANDSP_SUPPORT_T45)
        case T4_COMPRESSION_T45:
            /* We need to perform this compression here, as libtiff does not understand it. */
            if (write_tiff_t45_image(s) < 0)
                return -1;
            break;
#endif
        default:
            /* Let libtiff do the compression */
            if (TIFFWriteEncodedStrip(t->tiff_file, 0, t->image_buffer, t->image_size) < 0)
                span_log(&s->logging, SPAN_LOG_WARNING, "%s: Error writing TIFF strip.\n", t->file);
            break;
        }
    }
    /* ...then finalise the directory entry, and libtiff is happy. */
    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);
#if defined(SPANDSP_SUPPORT_TIFF_FX)
    /* According to the TIFF/FX spec, a global parameters IFD should only be inserted into
       the first page in the file */
    if (s->current_page == 0)
    {
#if TIFFLIB_VERSION >= 20120922  &&  defined(HAVE_TIF_DIR_H)
        if (!TIFFCreateCustomDirectory(t->tiff_file, &tiff_fx_field_array))
        {
            TIFFSetField(t->tiff_file, TIFFTAG_FAXPROFILE, PROFILETYPE_G3_FAX);
            TIFFSetField(t->tiff_file, TIFFTAG_PROFILETYPE, FAXPROFILE_F);
            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, 3);

            diroff = 0;
            if (!TIFFWriteCustomDirectory(t->tiff_file, &diroff))
                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 */
            if (!TIFFSetDirectory(t->tiff_file, s->current_page))
                span_log(&s->logging, SPAN_LOG_WARNING, "Failed to set directory.\n");
            if (!TIFFSetField(t->tiff_file, TIFFTAG_GLOBALPARAMETERSIFD, diroff))
                span_log(&s->logging, SPAN_LOG_WARNING, "Failed to set field.\n");
            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);
        }
#endif
    }
#endif
    return 0;
}