1 /*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * fax_utils.c
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2009 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2, as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26 #if defined(HAVE_CONFIG_H)
27 #include "config.h"
28 #endif
29
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <assert.h>
34
35 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
36
37 #include "spandsp.h"
38 #include "spandsp-sim.h"
39 #include "fax_utils.h"
40
fax_log_tx_parameters(t30_state_t * s,const char * tag)41 void fax_log_tx_parameters(t30_state_t *s, const char *tag)
42 {
43 const char *u;
44
45 if ((u = t30_get_tx_ident(s)))
46 printf("%s: Local ident '%s'\n", tag, u);
47 if ((u = t30_get_tx_sub_address(s)))
48 printf("%s: Local sub-address '%s'\n", tag, u);
49 if ((u = t30_get_tx_polled_sub_address(s)))
50 printf("%s: Local polled sub-address '%s'\n", tag, u);
51 if ((u = t30_get_tx_selective_polling_address(s)))
52 printf("%s: Local selective polling address '%s'\n", tag, u);
53 if ((u = t30_get_tx_sender_ident(s)))
54 printf("%s: Local sender ident '%s'\n", tag, u);
55 if ((u = t30_get_tx_password(s)))
56 printf("%s: Local password '%s'\n", tag, u);
57 }
58 /*- End of function --------------------------------------------------------*/
59
fax_log_rx_parameters(t30_state_t * s,const char * tag)60 void fax_log_rx_parameters(t30_state_t *s, const char *tag)
61 {
62 const char *u;
63
64 if ((u = t30_get_rx_ident(s)))
65 printf("%s: Remote ident '%s'\n", tag, u);
66 if ((u = t30_get_rx_sub_address(s)))
67 printf("%s: Remote sub-address '%s'\n", tag, u);
68 if ((u = t30_get_rx_polled_sub_address(s)))
69 printf("%s: Remote polled sub-address '%s'\n", tag, u);
70 if ((u = t30_get_rx_selective_polling_address(s)))
71 printf("%s: Remote selective polling address '%s'\n", tag, u);
72 if ((u = t30_get_rx_sender_ident(s)))
73 printf("%s: Remote sender ident '%s'\n", tag, u);
74 if ((u = t30_get_rx_password(s)))
75 printf("%s: Remote password '%s'\n", tag, u);
76 if ((u = t30_get_rx_country(s)))
77 printf("%s: Remote was made in '%s'\n", tag, u);
78 if ((u = t30_get_rx_vendor(s)))
79 printf("%s: Remote was made by '%s'\n", tag, u);
80 if ((u = t30_get_rx_model(s)))
81 printf("%s: Remote is model '%s'\n", tag, u);
82 }
83 /*- End of function --------------------------------------------------------*/
84
fax_log_final_transfer_statistics(t30_state_t * s,const char * tag)85 void fax_log_final_transfer_statistics(t30_state_t *s, const char *tag)
86 {
87 t30_stats_t t;
88
89 t30_get_transfer_statistics(s, &t);
90 printf("%s: Bit rate %d\n", tag, t.bit_rate);
91 printf("%s: ECM %s\n", tag, (t.error_correcting_mode) ? "on" : "off");
92 printf("%s: RTP events %d. RTN events %d\n", tag, t.rtp_events, t.rtn_events);
93 printf("%s: Tx pages %d, rx pages %d\n", tag, t.pages_tx, t.pages_rx);
94 }
95 /*- End of function --------------------------------------------------------*/
96
fax_log_page_transfer_statistics(t30_state_t * s,const char * tag)97 void fax_log_page_transfer_statistics(t30_state_t *s, const char *tag)
98 {
99 t30_stats_t t;
100
101 t30_get_transfer_statistics(s, &t);
102 printf("%s: Page statistics\n", tag);
103 printf("%s: Pages in the file %d\n", tag, t.pages_in_file);
104 printf("%s: Bad rows %d, longest bad row run %d\n", tag, t.bad_rows, t.longest_bad_row_run);
105 printf("%s: Bad ECM frames %d\n", tag, t.error_correcting_mode_retries);
106 printf("%s: Compression type %s (%d)\n", tag, t4_compression_to_str(t.compression), t.compression);
107 printf("%s: Compressed image size %d bytes\n", tag, t.image_size);
108 printf("%s: Image type %s (%s in the file)\n", tag, t4_image_type_to_str(t.type), t4_image_type_to_str(t.image_type));
109 printf("%s: Image size %d pels x %d pels (%d pels x %d pels in the file)\n", tag, t.width, t.length, t.image_width, t.image_length);
110 printf("%s: Image resolution %d pels/m x %d pels/m (%d pels/m x %d pels/m in the file)\n", tag, t.x_resolution, t.y_resolution, t.image_x_resolution, t.image_y_resolution);
111 #if defined(SPANDSP_EXPOSE_INTERNAL_STRUCTURES)
112 printf("%s: Bits per row - min %d, max %d\n", tag, s->t4.tx.encoder.t4_t6.min_row_bits, s->t4.tx.encoder.t4_t6.max_row_bits);
113 #endif
114
115 fax_log_final_transfer_statistics(s, tag);
116 }
117 /*- End of function --------------------------------------------------------*/
118
get_tiff_total_pages(const char * file)119 int get_tiff_total_pages(const char *file)
120 {
121 TIFF *tiff_file;
122 int max;
123
124 if ((tiff_file = TIFFOpen(file, "r")) == NULL)
125 return -1;
126 /* Each page *should* contain the total number of pages, but can this be
127 trusted? Some files say 0. Actually searching for the last page is
128 more reliable. */
129 max = 0;
130 while (TIFFSetDirectory(tiff_file, (tdir_t) max))
131 max++;
132 TIFFClose(tiff_file);
133 return max;
134 }
135 /*- End of function --------------------------------------------------------*/
136 /*- End of file ------------------------------------------------------------*/
137