~ubuntu-branches/ubuntu/saucy/iaxmodem/saucy

« back to all changes in this revision

Viewing changes to lib/spandsp/tests/t4_tests.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien BLACHE
  • Date: 2006-10-28 10:54:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20061028105455-qdnaih9tmq0uc29w
Tags: 0.1.15~dfsg-1
* New upstream release.
* debian/rules:
  + Use new ~dfsg versionning scheme.
  + Do not remove config.* in get-orig-source.
* debian/patches/11_build_configure-stamp.dpatch:
  + Updated.
* debian/iaxmodem.init:
  + Added LSB header.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 * along with this program; if not, write to the Free Software
24
24
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
25
 *
26
 
 * $Id: t4_tests.c,v 1.25 2006/05/05 10:58:18 steveu Exp $
 
26
 * $Id: t4_tests.c,v 1.30 2006/07/31 12:57:37 steveu Exp $
27
27
 */
28
28
 
29
29
/*! \file */
46
46
 
47
47
#include "spandsp.h"
48
48
 
49
 
#define IN_FILE_NAME    "itutests.tif"
 
49
#define IN_FILE_NAME    "../itutests/fax/itutests.tif"
50
50
#define OUT_FILE_NAME   "t4_tests_receive.tif"
51
51
 
52
52
#define XSIZE           1728
66
66
    int compression;
67
67
    int compression_step;
68
68
    int add_page_headers;
 
69
    int min_row_bits;
69
70
    int restart_pages;
70
71
    char buf[512];
71
72
    t4_stats_t stats;
 
73
    const char *in_file_name;
72
74
 
73
75
    i = 1;
74
76
    decode_test = FALSE;
75
 
    compression = T4_COMPRESSION_ITU_T4_1D;
 
77
    compression = -1;
76
78
    add_page_headers = FALSE;
77
79
    restart_pages = FALSE;
 
80
    in_file_name = IN_FILE_NAME;
 
81
    min_row_bits = 0;
78
82
    while (i < argc)
79
83
    {
80
84
        if (strcmp(argv[i], "-d") == 0)
89
93
            add_page_headers = TRUE;
90
94
        else if (strcmp(argv[i], "-r") == 0)
91
95
            restart_pages = TRUE;
 
96
        else if (strcmp(argv[i], "-i") == 0)
 
97
            in_file_name = argv[++i];
 
98
        else if (strcmp(argv[i], "-m") == 0)
 
99
            min_row_bits = atoi(argv[++i]);
92
100
        i++;
93
101
    }
94
102
    /* Create a send and a receive end */
97
105
 
98
106
    if (decode_test)
99
107
    {
 
108
        if (compression < 0)
 
109
            compression = T4_COMPRESSION_ITU_T4_1D;
100
110
        /* Receive end puts TIFF to a new file. We assume the receive width here. */
101
111
        if (t4_rx_init(&receive_state, OUT_FILE_NAME, T4_COMPRESSION_ITU_T4_2D))
102
112
        {
115
125
        {
116
126
            if (sscanf(buf, "Rx bit %*d - %d", &bit) == 1)
117
127
            {
118
 
                end_of_page = t4_rx_putbit(&receive_state, bit);
119
 
                if (end_of_page)
 
128
                if ((end_of_page = t4_rx_put_bit(&receive_state, bit)))
120
129
                {
121
130
                    printf("End of page detected\n");
122
131
                    break;
149
158
    }
150
159
    else
151
160
    {
152
 
        /* Send end gets TIFF from a file, using 1D compression */
153
 
        if (t4_tx_init(&send_state, IN_FILE_NAME, -1, -1))
 
161
        /* Send end gets TIFF from a file */
 
162
        if (t4_tx_init(&send_state, in_file_name, -1, -1))
154
163
        {
155
164
            printf("Failed to init TIFF send\n");
156
165
            exit(2);
163
172
            exit(2);
164
173
        }
165
174
    
166
 
        t4_tx_set_min_row_bits(&send_state, 144);
 
175
        t4_tx_set_min_row_bits(&send_state, min_row_bits);
167
176
 
168
177
        t4_rx_set_x_resolution(&receive_state, t4_tx_get_x_resolution(&send_state));
169
178
        t4_rx_set_y_resolution(&receive_state, t4_tx_get_y_resolution(&send_state));
173
182
        page_no = 1;
174
183
        t4_tx_set_local_ident(&send_state, "852 2666 0542");
175
184
        sends = 0;
176
 
        compression_step = 0;
 
185
        /* Select whether we step round the compression schemes, or use a single specified one. */
 
186
        compression_step = (compression < 0)  ?  0  :  -1;
177
187
        for (;;)
178
188
        {
179
189
            end_marks = 0;
194
204
                {
195
205
                case 0:
196
206
                    compression = T4_COMPRESSION_ITU_T4_1D;
 
207
                    compression_step++;
197
208
                    break;
198
209
                case 1:
199
210
                    compression = T4_COMPRESSION_ITU_T4_2D;
 
211
                    compression_step++;
200
212
                    break;
201
213
                case 2:
202
214
                    compression = T4_COMPRESSION_ITU_T6;
203
 
                    break;
204
 
                }
205
 
                if (++compression_step > 2)
206
215
                    compression_step = 0;
 
216
                    break;
 
217
                }
207
218
                t4_tx_set_tx_encoding(&send_state, compression);
208
219
                t4_rx_set_rx_encoding(&receive_state, compression);
209
220
 
213
224
            t4_rx_start_page(&receive_state);
214
225
            do
215
226
            {
216
 
                bit = t4_tx_getbit(&send_state);
 
227
                bit = t4_tx_get_bit(&send_state);
217
228
#if 0
218
229
                if (--next_hit <= 0)
219
230
                {
223
234
                    bit ^= (rand() & 1);
224
235
                }
225
236
#endif
226
 
                if ((bit & 2))
 
237
                if (bit == PUTBIT_END_OF_DATA)
227
238
                {
 
239
                    /* T.6 data does not contain an image termination sequence.
 
240
                       T.4 1D and 2D do, and should locate that sequence. */
 
241
                    if (compression == T4_COMPRESSION_ITU_T6)
 
242
                        break;
228
243
                    if (++end_marks > 50)
229
244
                    {
230
245
                        printf("Receiver missed the end of page mark\n");
231
246
                        exit(2);
232
247
                    }
233
248
                }
234
 
                end_of_page = t4_rx_putbit(&receive_state, bit & 1);
 
249
                end_of_page = t4_rx_put_bit(&receive_state, bit & 1);
235
250
            }
236
251
            while (!end_of_page);
237
252
            t4_get_transfer_statistics(&receive_state, &stats);