File: fax_utils.c

package info (click to toggle)
spandsp 0.0.6%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 15,796 kB
  • sloc: ansic: 123,211; xml: 13,229; sh: 12,189; cpp: 1,521; makefile: 1,097
file content (137 lines) | stat: -rw-r--r-- 5,114 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
 * SpanDSP - a series of DSP components for telephony
 *
 * fax_utils.c
 *
 * Written by Steve Underwood <steveu@coppice.org>
 *
 * Copyright (C) 2009 Steve Underwood
 *
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>

//#if defined(WITH_SPANDSP_INTERNALS)
#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
//#endif

#include "spandsp.h"
#include "spandsp-sim.h"
#include "fax_utils.h"

void fax_log_tx_parameters(t30_state_t *s, const char *tag)
{
    const char *u;
    
    if ((u = t30_get_tx_ident(s)))
        printf("%s: Local ident '%s'\n", tag, u);
    if ((u = t30_get_tx_sub_address(s)))
        printf("%s: Local sub-address '%s'\n", tag, u);
    if ((u = t30_get_tx_polled_sub_address(s)))
        printf("%s: Local polled sub-address '%s'\n", tag, u);
    if ((u = t30_get_tx_selective_polling_address(s)))
        printf("%s: Local selective polling address '%s'\n", tag, u);
    if ((u = t30_get_tx_sender_ident(s)))
        printf("%s: Local sender ident '%s'\n", tag, u);
    if ((u = t30_get_tx_password(s)))
        printf("%s: Local password '%s'\n", tag, u);
}
/*- End of function --------------------------------------------------------*/

void fax_log_rx_parameters(t30_state_t *s, const char *tag)
{
    const char *u;

    if ((u = t30_get_rx_ident(s)))
        printf("%s: Remote ident '%s'\n", tag, u);
    if ((u = t30_get_rx_sub_address(s)))
        printf("%s: Remote sub-address '%s'\n", tag, u);
    if ((u = t30_get_rx_polled_sub_address(s)))
        printf("%s: Remote polled sub-address '%s'\n", tag, u);
    if ((u = t30_get_rx_selective_polling_address(s)))
        printf("%s: Remote selective polling address '%s'\n", tag, u);
    if ((u = t30_get_rx_sender_ident(s)))
        printf("%s: Remote sender ident '%s'\n", tag, u);
    if ((u = t30_get_rx_password(s)))
        printf("%s: Remote password '%s'\n", tag, u);
    if ((u = t30_get_rx_country(s)))
        printf("%s: Remote was made in '%s'\n", tag, u);
    if ((u = t30_get_rx_vendor(s)))
        printf("%s: Remote was made by '%s'\n", tag, u);
    if ((u = t30_get_rx_model(s)))
        printf("%s: Remote is model '%s'\n", tag, u);
}
/*- End of function --------------------------------------------------------*/

void fax_log_final_transfer_statistics(t30_state_t *s, const char *tag)
{
    t30_stats_t t;

    t30_get_transfer_statistics(s, &t);
    printf("%s: Bit rate %d\n", tag, t.bit_rate);
    printf("%s: ECM %s\n", tag, (t.error_correcting_mode)  ?  "on"  :  "off");
    //printf("%s: RTP events %d. RTN events %d\n", tag, t.rtp_events, t.rtn_events);
    printf("%s: Tx pages %d, rx pages %d\n", tag, t.pages_tx, t.pages_rx);
}
/*- End of function --------------------------------------------------------*/

void fax_log_page_transfer_statistics(t30_state_t *s, const char *tag)
{
    t30_stats_t t;

    t30_get_transfer_statistics(s, &t);
    printf("%s: Page statistics\n", tag);
    printf("%s:   Pages in the file %d\n", tag, t.pages_in_file);
    printf("%s:   Bad rows %d, longest bad row run %d\n", tag, t.bad_rows, t.longest_bad_row_run);
    printf("%s:   Bad ECM frames %d\n", tag, t.error_correcting_mode_retries);
    printf("%s:   Compression type %s (%d)\n", tag, t4_encoding_to_str(t.encoding), t.encoding);
    printf("%s:   Compressed image size %d bytes\n", tag, t.image_size);
    printf("%s:   Image size %d pels x %d pels\n", tag, t.width, t.length);
    printf("%s:   Image resolution %d pels/m x %d pels/m\n", tag, t.x_resolution, t.y_resolution);
#if defined(WITH_SPANDSP_INTERNALS)
    printf("%s:   Bits per row - min %d, max %d\n", tag, s->t4.min_row_bits, s->t4.max_row_bits);
#endif

    fax_log_final_transfer_statistics(s, tag);
}
/*- End of function --------------------------------------------------------*/

int get_tiff_total_pages(const char *file)
{
    TIFF *tiff_file;
    int max;

    if ((tiff_file = TIFFOpen(file, "r")) == NULL)
        return -1;
    /* Each page *should* contain the total number of pages, but can this be
       trusted? Some files say 0. Actually searching for the last page is
       more reliable. */
    max = 0;
    while (TIFFSetDirectory(tiff_file, (tdir_t) max))
        max++;
    TIFFClose(tiff_file);
    return max;
}
/*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/