2009-02-20 18:30:05 +00:00
/*
* 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 0213 9 , USA .
*/
# if defined(HAVE_CONFIG_H)
# include "config.h"
# endif
# include <stdlib.h>
# include <stdio.h>
# include <string.h>
# include <assert.h>
# define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
# include "spandsp.h"
# include "spandsp-sim.h"
# include "fax_utils.h"
2011-07-02 13:16:52 +00:00
void fax_log_tx_parameters ( t30_state_t * s , const char * tag )
2009-02-20 18:30:05 +00:00
{
const char * u ;
2013-03-14 13:22:51 +00:00
2009-02-20 18:30:05 +00:00
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 --------------------------------------------------------*/
2011-07-02 13:16:52 +00:00
void fax_log_rx_parameters ( t30_state_t * s , const char * tag )
2009-02-20 18:30:05 +00:00
{
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 --------------------------------------------------------*/
2012-03-28 13:43:13 +00:00
void fax_log_final_transfer_statistics ( t30_state_t * s , const char * tag )
2009-02-20 18:30:05 +00:00
{
t30_stats_t t ;
t30_get_transfer_statistics ( s , & t ) ;
2012-03-28 13:43:13 +00:00
printf ( " %s: Bit rate %d \n " , tag , t . bit_rate ) ;
2010-07-24 19:29:44 +00:00
printf ( " %s: ECM %s \n " , tag , ( t . error_correcting_mode ) ? " on " : " off " ) ;
2012-07-14 17:47:55 +00:00
printf ( " %s: RTP events %d. RTN events %d \n " , tag , t . rtp_events , t . rtn_events ) ;
2012-03-28 13:43:13 +00:00
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 ) ;
2013-05-29 02:07:08 +00:00
printf ( " %s: Compression type %s (%d) \n " , tag , t4_compression_to_str ( t . compression ) , t . compression ) ;
2012-03-28 13:43:13 +00:00
printf ( " %s: Compressed image size %d bytes \n " , tag , t . image_size ) ;
2013-03-10 12:55:21 +00:00
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 ) ) ;
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 ) ;
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 ) ;
2013-01-01 15:07:55 +00:00
# if defined(SPANDSP_EXPOSE_INTERNAL_STRUCTURES)
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 ) ;
2009-02-20 18:30:05 +00:00
# endif
2012-03-28 13:43:13 +00:00
fax_log_final_transfer_statistics ( s , tag ) ;
2009-02-20 18:30:05 +00:00
}
/*- End of function --------------------------------------------------------*/
2011-07-02 13:16:52 +00:00
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 --------------------------------------------------------*/
2009-02-20 18:30:05 +00:00
/*- End of file ------------------------------------------------------------*/