fax_utils.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. #if defined(HAVE_CONFIG_H)
  26. #include "config.h"
  27. #endif
  28. #include <stdlib.h>
  29. #include <stdio.h>
  30. #include <string.h>
  31. #include <assert.h>
  32. #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
  33. #include "spandsp.h"
  34. #include "spandsp-sim.h"
  35. #include "fax_utils.h"
  36. void fax_log_tx_parameters(t30_state_t *s, const char *tag)
  37. {
  38. const char *u;
  39. if ((u = t30_get_tx_ident(s)))
  40. printf("%s: Local ident '%s'\n", tag, u);
  41. if ((u = t30_get_tx_sub_address(s)))
  42. printf("%s: Local sub-address '%s'\n", tag, u);
  43. if ((u = t30_get_tx_polled_sub_address(s)))
  44. printf("%s: Local polled sub-address '%s'\n", tag, u);
  45. if ((u = t30_get_tx_selective_polling_address(s)))
  46. printf("%s: Local selective polling address '%s'\n", tag, u);
  47. if ((u = t30_get_tx_sender_ident(s)))
  48. printf("%s: Local sender ident '%s'\n", tag, u);
  49. if ((u = t30_get_tx_password(s)))
  50. printf("%s: Local password '%s'\n", tag, u);
  51. }
  52. /*- End of function --------------------------------------------------------*/
  53. void fax_log_rx_parameters(t30_state_t *s, const char *tag)
  54. {
  55. const char *u;
  56. if ((u = t30_get_rx_ident(s)))
  57. printf("%s: Remote ident '%s'\n", tag, u);
  58. if ((u = t30_get_rx_sub_address(s)))
  59. printf("%s: Remote sub-address '%s'\n", tag, u);
  60. if ((u = t30_get_rx_polled_sub_address(s)))
  61. printf("%s: Remote polled sub-address '%s'\n", tag, u);
  62. if ((u = t30_get_rx_selective_polling_address(s)))
  63. printf("%s: Remote selective polling address '%s'\n", tag, u);
  64. if ((u = t30_get_rx_sender_ident(s)))
  65. printf("%s: Remote sender ident '%s'\n", tag, u);
  66. if ((u = t30_get_rx_password(s)))
  67. printf("%s: Remote password '%s'\n", tag, u);
  68. if ((u = t30_get_rx_country(s)))
  69. printf("%s: Remote was made in '%s'\n", tag, u);
  70. if ((u = t30_get_rx_vendor(s)))
  71. printf("%s: Remote was made by '%s'\n", tag, u);
  72. if ((u = t30_get_rx_model(s)))
  73. printf("%s: Remote is model '%s'\n", tag, u);
  74. }
  75. /*- End of function --------------------------------------------------------*/
  76. void fax_log_final_transfer_statistics(t30_state_t *s, const char *tag)
  77. {
  78. t30_stats_t t;
  79. t30_get_transfer_statistics(s, &t);
  80. printf("%s: Bit rate %d\n", tag, t.bit_rate);
  81. printf("%s: ECM %s\n", tag, (t.error_correcting_mode) ? "on" : "off");
  82. printf("%s: RTP events %d. RTN events %d\n", tag, t.rtp_events, t.rtn_events);
  83. printf("%s: Tx pages %d, rx pages %d\n", tag, t.pages_tx, t.pages_rx);
  84. }
  85. /*- End of function --------------------------------------------------------*/
  86. void fax_log_page_transfer_statistics(t30_state_t *s, const char *tag)
  87. {
  88. t30_stats_t t;
  89. t30_get_transfer_statistics(s, &t);
  90. printf("%s: Page statistics\n", tag);
  91. printf("%s: Pages in the file %d\n", tag, t.pages_in_file);
  92. printf("%s: Bad rows %d, longest bad row run %d\n", tag, t.bad_rows, t.longest_bad_row_run);
  93. printf("%s: Bad ECM frames %d\n", tag, t.error_correcting_mode_retries);
  94. printf("%s: Compression type %s (%d)\n", tag, t4_compression_to_str(t.compression), t.compression);
  95. printf("%s: Compressed image size %d bytes\n", tag, t.image_size);
  96. 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));
  97. 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);
  98. 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);
  99. #if defined(SPANDSP_EXPOSE_INTERNAL_STRUCTURES)
  100. 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);
  101. #endif
  102. fax_log_final_transfer_statistics(s, tag);
  103. }
  104. /*- End of function --------------------------------------------------------*/
  105. int get_tiff_total_pages(const char *file)
  106. {
  107. TIFF *tiff_file;
  108. int max;
  109. if ((tiff_file = TIFFOpen(file, "r")) == NULL)
  110. return -1;
  111. /* Each page *should* contain the total number of pages, but can this be
  112. trusted? Some files say 0. Actually searching for the last page is
  113. more reliable. */
  114. max = 0;
  115. while (TIFFSetDirectory(tiff_file, (tdir_t) max))
  116. max++;
  117. TIFFClose(tiff_file);
  118. return max;
  119. }
  120. /*- End of function --------------------------------------------------------*/
  121. /*- End of file ------------------------------------------------------------*/