提交 ccbee256 authored 作者: Steve Underwood's avatar Steve Underwood

Added some new files for spandsp

上级 f029f7ef
<?xml version="1.0"?>
<!DOCTYPE fax-tests SYSTEM "./fax-tests.dtd">
<fax-tests>
<config>
<path type="IMAGE" value="../test-data/etsi/fax"/>
</config>
<messages>
<!-- TCF = 2700 bytes at 14400, 2250 at 12000, 1800 at 9600, 1350 at 7200, 900 at 4800 or 450 at 2400 -->
<!-- Bad TCF == 10101010.... -->
<!-- slow HDLC preamble == 37 flag bytes -->
<!-- slow HDLC inter-frame flag sequence == 1 flag byte -->
<!-- slow HDLC end flag sequence == 5 flag bytes -->
<!-- synchronisation sequence == 250ms of zeros. = 450 bytes at 14400, 375 at 12000, 300 at 9600, 225 at 7200, 150 at 4800 or 75 at 2400 -->
<!-- fast HDLC inter-frame flag sequence == 1 flag byte -->
<!-- fast HDLC end flag sequence == 10 flag bytes -->
<!-- STAIRSTEP image is 1728x1728 pixels. Its is about 15k, so an average of 68.2 bits per row. To
cook it as a 31k page requires a min_bits of 141. To cook it as a 63k page requires a min_bits of
286. To cook it as a 64k page requires a min_bits of 291 -->
</messages>
<test-group name="Supplementary">
<test name="PPS-MPS-lost-PPS">
<!-- Tester calls DUT and sends one 31k byte STAIRSTEP page and one 15k byte STAIRSTEP page. -->
<step type="CALL"/>
<!--<step dir="T" type="CNG"/>-->
<step dir="R" type="CED"/>
<step dir="R" type="HDLC" modem="V.21" tag="DIS" value="FF C8 01 ..." timeout="60000"/>
<step dir="R" type="SILENCE"/>
<step type="WAIT" value="75"/>
<step dir="T" type="PREAMBLE" modem="V.21"/>
<step dir="T" type="HDLC" tag="DCS" value="FF C8 41 00 50 1F 30"/>
<step dir="T" type="POSTAMBLE"/>
<step type="WAIT" value="75"/>
<step dir="T" type="TCF" modem="V.27ter/4800" value="900"/>
<step dir="R" type="HDLC" modem="V.21" tag="CFR" value="FF C8 21"/>
<step dir="R" type="SILENCE"/>
<step type="WAIT" value="75"/>
<step dir="T" type="PREAMBLE" modem="V.27ter/4800"/>
<step dir="T" type="PP" value="etsi_300_242_a4_stairstep.tif" min_bits="141"/>
<step dir="T" type="POSTAMBLE"/>
<step type="WAIT" value="75"/>
<step dir="T" type="PREAMBLE" modem="V.21"/>
<step dir="T" type="HDLC" tag="PPS-NULL" value="FF C8 7D 00 00 00 08"/>
<step dir="T" type="POSTAMBLE"/>
<step dir="R" type="HDLC" modem="V.21" tag="MCF" value="FF C8 31"/>
<step dir="R" type="SILENCE"/>
<step type="WAIT" value="75"/>
<step dir="T" type="PREAMBLE" modem="V.27ter/4800"/>
<step dir="T" type="PP" value="etsi_300_242_a4_stairstep.tif"/>
<step dir="T" type="POSTAMBLE"/>
<step type="WAIT" value="75"/>
<step dir="T" type="PREAMBLE" modem="V.21"/>
<step dir="T" type="HDLC" tag="PPS-MPS" value="FF C8 7D 72 00 80 08"/>
<step dir="T" type="POSTAMBLE"/>
<step dir="R" type="HDLC" modem="V.21" tag="MCF" value="FF C8 31"/>
<step dir="R" type="SILENCE"/>
<!-- Repeat the last chunk, as though we missed the MCF -->
<step type="WAIT" value="75"/>
<step dir="T" type="PREAMBLE" modem="V.27ter/4800"/>
<step dir="T" type="PP" value="etsi_300_242_a4_stairstep.tif"/>
<step dir="T" type="POSTAMBLE"/>
<step type="WAIT" value="75"/>
<step dir="T" type="PREAMBLE" modem="V.21"/>
<step dir="T" type="HDLC" tag="PPS-MPS" value="FF C8 7D 72 00 80 08"/>
<step dir="T" type="POSTAMBLE"/>
<step dir="R" type="HDLC" modem="V.21" tag="MCF" value="FF C8 31"/>
<step dir="R" type="SILENCE"/>
<step type="WAIT" value="75"/>
<step dir="T" type="PREAMBLE" modem="V.27ter/4800"/>
<step dir="T" type="PP" value="etsi_300_242_a4_white.tif"/>
<step dir="T" type="POSTAMBLE"/>
<step type="WAIT" value="75"/>
<step dir="T" type="PREAMBLE" modem="V.21"/>
<step dir="T" type="HDLC" tag="PPS-MPS" value="FF C8 7D 72 80 00 08"/>
<step dir="T" type="POSTAMBLE"/>
<step dir="R" type="HDLC" modem="V.21" tag="MCF" value="FF C8 31"/>
<step dir="R" type="SILENCE"/>
<step type="WAIT" value="75"/>
<step dir="T" type="PREAMBLE" modem="V.21"/>
<step dir="T" type="HDLC" tag="DCN" value="FF C8 5F"/>
<step dir="T" type="POSTAMBLE"/>
</test>
</test-group>
</fax-tests>
差异被折叠。
/*
* SpanDSP - a series of DSP components for telephony
*
* image_translate.h - Image translation routines for reworking colour
* and gray scale images to be bi-level images of an
* appropriate size to be FAX compatible.
*
* 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 Lesser General Public License version 2.1,
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*! \file */
#if !defined(_SPANDSP_IMAGE_TRANSLATE_H_)
#define _SPANDSP_IMAGE_TRANSLATE_H_
/*! \page image_translate_page Image translation
\section image_translate_page_sec_1 What does it do?
\section image_translate_page_sec_2 How does it work?
\section image_translate_page_sec_3 How do I use it?
*/
typedef struct image_translate_state_s image_translate_state_t;
enum
{
IMAGE_TRANSLATE_FROM_MONO = 1,
IMAGE_TRANSLATE_FROM_GRAY_8 = 2,
IMAGE_TRANSLATE_FROM_GRAY_16 = 3,
IMAGE_TRANSLATE_FROM_COLOUR_8 = 4,
IMAGE_TRANSLATE_FROM_COLOUR_16 = 5
};
#if defined(__cplusplus)
extern "C"
{
#endif
/*! \brief Get the next row of a translated image.
\param s The image translation context.
\return the length of the row buffer, in bytes */
SPAN_DECLARE(int) image_translate_row(image_translate_state_t *s, uint8_t buf[], size_t len);
/*! \brief Get the width of the image being produced by an image translation context.
\param s The image translation context.
\return The width of the output image, in pixel. */
SPAN_DECLARE(int) image_translate_get_output_width(image_translate_state_t *s);
/*! \brief Get the length of the image being produced by an image translation context.
\param s The image translation context.
\return The length of the output image, in pixel. */
SPAN_DECLARE(int) image_translate_get_output_length(image_translate_state_t *s);
/*! \brief Initialise an image translation context for rescaling and squashing a gray scale
or colour image to a bi-level FAX type image.
\param s The image translation context.
\param input_format x
\param input_width The width of the source image, in pixels.
\param input_length The length of the source image, in pixels.
\param output_width The width of the output image, in pixels. The length of the output image
will be derived automatically from this and the source image dimension, to main the
geometry of the original image.
\param row_read_handler A callback routine used to pull rows of pixels from the source image
into the translation process.
\param row_read_user_data An opaque point passed to read_row_handler
\return A pointer to the context, or NULL if there was a problem. */
SPAN_DECLARE(image_translate_state_t *) image_translate_init(image_translate_state_t *s,
int input_format,
int input_width,
int input_length,
int output_width,
t4_row_read_handler_t row_read_handler,
void *row_read_user_data);
/*! \brief Release the resources associated with an image translation context.
\param s The image translation context.
\return 0 for success, otherwise -1. */
SPAN_DECLARE(int) image_translate_release(image_translate_state_t *s);
/*! \brief Free the resources associated with an image translation context.
\param s The image translation context.
\return 0 for success, otherwise -1. */
SPAN_DECLARE(int) image_translate_free(image_translate_state_t *s);
#if defined(__cplusplus)
}
#endif
#endif
/*- End of file ------------------------------------------------------------*/
/*
* SpanDSP - a series of DSP components for telephony
*
* private/image_translate.c - Image translation routines for reworking colour
* and gray scale images to be bi-level images of an
* appropriate size to be FAX compatible.
*
* 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 Lesser General Public License version 2.1,
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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(_SPANDSP_PRIVATE_IMAGE_TRANSLATE_H_)
#define _SPANDSP_PRIVATE_IMAGE_TRANSLATE_H_
struct image_translate_state_s
{
int input_format;
int input_width;
int input_length;
int output_width;
int output_length;
int resize;
int bytes_per_pixel;
int raw_input_row;
int raw_output_row;
int output_row;
uint8_t *raw_pixel_row[2];
uint8_t *pixel_row[2];
t4_row_read_handler_t row_read_handler;
void *row_read_user_data;
};
#endif
/*- End of file ------------------------------------------------------------*/
/*
* SpanDSP - a series of DSP components for telephony
*
* private/t4_t6_decode.h - definitions for T.4/T.6 fax decoding
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2003, 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 Lesser General Public License version 2.1,
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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(_SPANDSP_PRIVATE_T4_T6_DECODE_H_)
#define _SPANDSP_PRIVATE_T4_T6_DECODE_H_
/*!
T.4 1D, T4 2D and T6 decompressor state.
*/
struct t4_t6_decode_state_s
{
/*! \brief The type of compression used between the FAX machines. */
//int encoding;
/*! \brief Width of the current page, in pixels. */
//int image_width;
/*! \brief Callback function to write a row of pixels to the image destination. */
t4_row_write_handler_t row_write_handler;
/*! \brief Opaque pointer passed to row_write_handler. */
void *row_write_user_data;
/*! \brief A pointer into the image buffer indicating where the last row begins */
int last_row_starts_at;
/*! \brief This variable is used to count the consecutive EOLS we have seen. If it
reaches six, this is the end of the image. It is initially set to -1 for
1D and 2D decoding, as an indicator that we must wait for the first EOL,
before decoding any image data. */
int consecutive_eols;
/*! \brief The reference or starting changing element on the coding line. At the
start of the coding line, a0 is set on an imaginary white changing element
situated just before the first element on the line. During the coding of
the coding line, the position of a0 is defined by the previous coding mode.
(See T.4/4.2.1.3.2.). */
int a0;
/*! \brief The first changing element on the reference line to the right of a0 and of
opposite colour to a0. */
int b1;
/*! \brief The length of the in-progress run of black or white. */
int run_length;
/*! \brief 2D horizontal mode control. */
int black_white;
/*! \brief TRUE if the current run is black */
int its_black;
/*! \brief The current step into the current row run-lengths buffer. */
int a_cursor;
/*! \brief The current step into the reference row run-lengths buffer. */
int b_cursor;
/*! \brief Incoming bit buffer for decompression. */
uint32_t rx_bitstream;
/*! \brief The number of bits currently in rx_bitstream. */
int rx_bits;
/*! \brief The number of bits to be skipped before trying to match the next code word. */
int rx_skip_bits;
/*! \brief Decoded pixel buffer. */
//uint32_t pixel_stream;
/*! \brief The number of bits currently in pixel_stream. */
//int tx_bits;
/*! \brief Current pixel row number. */
//int row;
/*! \brief The current number of consecutive bad rows. */
int curr_bad_row_run;
/*! \brief The longest run of consecutive bad rows seen in the current page. */
int longest_bad_row_run;
/*! \brief The total number of bad rows in the current page. */
int bad_rows;
/*! \brief Error and flow logging control */
//logging_state_t logging;
};
#endif
/*- End of file ------------------------------------------------------------*/
/*
* SpanDSP - a series of DSP components for telephony
*
* private/t4_t6_encode.h - definitions for T.4/T.6 fax compression
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2003 Steve Underwood
*
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1,
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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(_SPANDSP_PRIVATE_T4_T6_ENCODE_H_)
#define _SPANDSP_PRIVATE_T4_T6_ENCODE_H_
/*!
T.4 1D, T4 2D and T6 compressor state.
*/
struct t4_t6_encode_state_s
{
/*! \brief The minimum number of encoded bits per row. This is a timing thing
for hardware FAX machines. */
int min_bits_per_row;
/*! \brief The current maximum contiguous rows that may be 2D encoded. */
int max_rows_to_next_1d_row;
/*! \brief Number of rows left that can be 2D encoded, before a 1D encoded row
must be used. */
int rows_to_next_1d_row;
/*! \brief The number of runs currently in the reference row. */
int ref_steps;
/*! \brief Pointer to the byte containing the next image bit to transmit. */
int bit_pos;
/*! \brief Pointer to the bit within the byte containing the next image bit to transmit. */
int bit_ptr;
/*! \brief Callback function to read a row of pixels from the image source. */
t4_row_read_handler_t row_read_handler;
/*! \brief Opaque pointer passed to row_read_handler. */
void *row_read_user_data;
};
#endif
/*- End of file ------------------------------------------------------------*/
/*
* SpanDSP - a series of DSP components for telephony
*
* private/timezone.h - Timezone handling for time interpretation
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2010 Steve Underwood
*
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1,
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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(_SPANDSP_PRIVATE_TIMEZONE_H_)
#define _SPANDSP_PRIVATE_TIMEZONE_H_
#define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
#define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */
#define TZNAME_MAX 255
/* The TZ_MAX_TIMES value below is enough to handle a bit more than a
* year's worth of solar time (corrected daily to the nearest second) or
* 138 years of Pacific Presidential Election time
* (where there are three time zone transitions every fourth year). */
#define TZ_MAX_TIMES 370
#if !defined(NOSOLAR)
#define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
#else
/* Must be at least 14 for Europe/Riga as of Jan 12 1995,
* as noted by Earl Chew <earl@hpato.aus.hp.com>. */
#define TZ_MAX_TYPES 20 /* Maximum number of local time types */
#endif
#define TZ_BIGGEST(a, b) (((a) > (b)) ? (a) : (b))
/* Time type information */
struct tz_ttinfo_s
{
int32_t gmtoff; /* UTC offset in seconds */
int isdst; /* Used to set tm_isdst */
int abbrind; /* Abbreviation list index */
int ttisstd; /* TRUE if transition is std time */
int ttisgmt; /* TRUE if transition is UTC */
};
/* Leap second information */
struct tz_lsinfo_s
{
time_t trans; /* Transition time */
int32_t corr; /* Correction to apply */
};
struct tz_state_s
{
int leapcnt;
int timecnt;
int typecnt;
int charcnt;
time_t ats[TZ_MAX_TIMES];
uint8_t types[TZ_MAX_TIMES];
struct tz_ttinfo_s ttis[TZ_MAX_TYPES];
char chars[TZ_BIGGEST(TZ_MAX_CHARS + 1, (2*(TZNAME_MAX + 1)))];
struct tz_lsinfo_s lsis[TZ_MAX_LEAPS];
};
struct tz_s
{
struct tz_state_s state;
char lcl_tzname[TZNAME_MAX + 1];
int lcl_is_set;
const char *tzname[2];
};
#endif
/*- End of file ------------------------------------------------------------*/
/*
* SpanDSP - a series of DSP components for telephony
*
* t4_t6_decode.h - definitions for T.4/T.6 fax decoding
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2003, 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 Lesser General Public License version 2.1,
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*! \file */
#if !defined(_SPANDSP_T4_T6_DECODE_H_)
#define _SPANDSP_T4_T6_DECODE_H_
/*! \page t4_t6_decode_page T.4 and T.6 FAX image decompression
\section t4_t6_decode_page_sec_1 What does it do?
The T.4 image compression and decompression routines implement the 1D and 2D
encoding methods defined in ITU specification T.4. They also implement the pure
2D encoding method defined in T.6. These are image compression algorithms used
for FAX transmission.
\section t4_t6_decode_page_sec_1 How does it work?
*/
typedef struct t4_t6_decode_state_s t4_t6_decode_state_t;
#if defined(__cplusplus)
extern "C" {
#endif
#if defined(__cplusplus)
}
#endif
#endif
/*- End of file ------------------------------------------------------------*/
/*
* SpanDSP - a series of DSP components for telephony
*
* t4_t6_encode.h - definitions for T.4/T.6 fax encoding
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2003, 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 Lesser General Public License version 2.1,
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*! \file */
#if !defined(_SPANDSP_T4_T6_ENCODE_H_)
#define _SPANDSP_T4_T6_ENCODE_H_
typedef struct t4_t6_encode_state_s t4_t6_encode_state_t;
#if defined(__cplusplus)
extern "C" {
#endif
#if defined(__cplusplus)
}
#endif
#endif
/*- End of file ------------------------------------------------------------*/
/*
* SpanDSP - a series of DSP components for telephony
*
* timezone.h - Timezone handling for time interpretation
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2010 Steve Underwood
*
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1,
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*! \file */
#if !defined(_SPANDSP_TIMEZONE_H_)
#define _SPANDSP_TIMEZONE_H_
/*! \page timezone_page Timezone handling
\section timezone_sec_1 What does it do?
\section timezone_sec_2 How does it work?
*/
typedef struct tz_s tz_t;
enum
{
TM_SUNDAY = 0,
TM_MONDAY,
TM_TUESDAY,
TM_WEDNESDAY,
TM_THURSDAY,
TM_FRIDAY,
TM_SATURDAY
};
enum
{
TM_JANUARY = 0,
TM_FEBRUARY,
TM_MARCH,
TM_APRIL,
TM_MAY,
TM_JUNE,
TM_JULY,
TM_AUGUST,
TM_SEPTEMBER,
TM_OCTOBER,
TM_NOVEMBER,
TM_DECEMBER
};
#if defined(__cplusplus)
extern "C"
{
#endif
SPAN_DECLARE(tz_t *) tz_init(tz_t *tz, const char *tzstring);
SPAN_DECLARE(int) tz_release(tz_t *tz);
SPAN_DECLARE(int) tz_free(tz_t *tz);
SPAN_DECLARE(int) tz_localtime(tz_t *tz, struct tm *tm, time_t t);
SPAN_DECLARE(const char *) tz_tzname(tz_t *tz, int isdst);
#if defined(__cplusplus)
}
#endif
#endif
/*- End of file ------------------------------------------------------------*/
差异被折叠。
/*
* SpanDSP - a series of DSP components for telephony
*
* generate_striped_pages.c
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2010 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.
*/
/*! \file */
/*
This program generates an TIFF image as a number of small image striped, rather than
the usual all in one page FAX images usually consist of in TIFF files.
*/
#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif
#include <stdio.h>
#include <inttypes.h>
#include <limits.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <string.h>
#if defined(HAVE_TGMATH_H)
#include <tgmath.h>
#endif
#if defined(HAVE_MATH_H)
#include <math.h>
#endif
#include <tiffio.h>
#include "spandsp.h"
#define IMAGE_WIDTH 1728
#define IMAGE_LENGTH 2600
#define ROWS_PER_STRIPE 37
int main(int argc, char *argv[])
{
TIFF *tiff_file;
uint8_t image_buffer[10000];
int image_size;
time_t now;
struct tm *tm;
char buf[256 + 1];
int i;
if ((tiff_file = TIFFOpen("striped.tif", "w")) == NULL)
return -1;
TIFFSetField(tiff_file, TIFFTAG_COMPRESSION, COMPRESSION_CCITT_T6);
TIFFSetField(tiff_file, TIFFTAG_BITSPERSAMPLE, 1);
TIFFSetField(tiff_file, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tiff_file, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(tiff_file, TIFFTAG_ROWSPERSTRIP, (int32_t) ROWS_PER_STRIPE);
TIFFSetField(tiff_file, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tiff_file, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
TIFFSetField(tiff_file, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB);
TIFFSetField(tiff_file, TIFFTAG_XRESOLUTION, 204.0f);
TIFFSetField(tiff_file, TIFFTAG_YRESOLUTION, 196.0f);
TIFFSetField(tiff_file, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
TIFFSetField(tiff_file, TIFFTAG_SOFTWARE, "Spandsp");
TIFFSetField(tiff_file, TIFFTAG_HOSTCOMPUTER, "host");
TIFFSetField(tiff_file, TIFFTAG_FAXSUBADDRESS, "1111");
TIFFSetField(tiff_file, TIFFTAG_IMAGEDESCRIPTION, "Image in stripes");
TIFFSetField(tiff_file, TIFFTAG_MAKE, "spandsp");
TIFFSetField(tiff_file, TIFFTAG_MODEL, "testy");
time(&now);
tm = localtime(&now);
sprintf(buf,
"%4d/%02d/%02d %02d:%02d:%02d",
tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday,
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
TIFFSetField(tiff_file, TIFFTAG_DATETIME, buf);
TIFFSetField(tiff_file, TIFFTAG_FAXRECVTIME, 10);
TIFFSetField(tiff_file, TIFFTAG_IMAGEWIDTH, IMAGE_WIDTH);
TIFFSetField(tiff_file, TIFFTAG_IMAGELENGTH, IMAGE_LENGTH);
TIFFSetField(tiff_file, TIFFTAG_PAGENUMBER, 0, 1);
image_size = IMAGE_WIDTH*ROWS_PER_STRIPE/8;
memset(image_buffer, 0x18, image_size);
for (i = 0; i < IMAGE_LENGTH/ROWS_PER_STRIPE; i++)
{
if (IMAGE_LENGTH > (i + 1)*ROWS_PER_STRIPE)
image_size = IMAGE_WIDTH*ROWS_PER_STRIPE/8;
else
image_size = IMAGE_WIDTH*(IMAGE_LENGTH - i*ROWS_PER_STRIPE)/8;
if (TIFFWriteEncodedStrip(tiff_file, i, image_buffer, image_size) < 0)
return -1;
}
TIFFWriteDirectory(tiff_file);
TIFFClose(tiff_file);
return 0;
}
/*
* SpanDSP - a series of DSP components for telephony
*
* bitstream_tests.c
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2007 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.
*/
/*! \page bitstream_tests_page Bitstream tests
\section bitstream_tests_page_sec_1 What does it do?
\section bitstream_tests_page_sec_2 How is it used?
*/
#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
//#if defined(WITH_SPANDSP_INTERNALS)
#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
//#endif
#include "spandsp.h"
uint8_t buffer[256];
#define PATTERN 0x11111111
#define SEQUENCE_LENGTH 17
uint8_t left[] =
{
0x28, /* 2 of 4, 3, 2, 1 */
0xC8, /* 1 of 6, 5, 2 of 4 */
0xAE, /* 3 of 7, 5 of 6 */
0x67, /* 4 of 8, 4 of 7 */
0x74, /* 4 of 9, 4 of 8 */
0x43, /* 3 of 10, 5 of 9 */
0x32, /* 1 of 11, 7 of 10 */
0xAA, /* 8 of 11 */
0xAE, /* 6 of 12, 2 of 11 */
0xED, /* 2 of 13, 6 of 12 */
0x99, /* 8 of 13 */
0x8E, /* 5 of 14, 3 of 13 */
0xEE, /* 8 of 14 */
0xEE, /* 7 of 15, 1 of 14 */
0xEE, /* 8 of 15 */
0xFF, /* 8 of 16 */
0xFF, /* 8 of 16 */
0x88, /* 8 of 17 */
0x88, /* 8 of 17 */
0x00 /* 1 of 17 */
};
uint8_t right[] =
{
0xD2, /* 1, 2, 3, 2 of 4 */
0x90, /* 2 of 4, 5, 1 of 6 */
0xCA, /* 5 of 6, 3 of 7 */
0x7C, /* 4 of 7, 4 of 8 */
0x87, /* 4 of 8, 4 of 9 */
0x28, /* 5 of 9, 3 of 10 */
0x33, /* 7 of 10, 1 of 11 */
0x55, /* 8 of 11 */
0xED, /* 2 of 11, 6 of 12 */
0x2E, /* 6 of 12, 2 of 13 */
0x33, /* 8 of 13 */
0xEB, /* 3 of 13, 5 of 14 */
0xEE, /* 8 of 14 */
0xDC, /* 1 of 14, 7 of 15 */
0xDD, /* 8 of 15 */
0xFF, /* 8 of 16 */
0xFF, /* 8 of 16 */
0x10, /* 8 of 17 */
0x11, /* 8 of 17 */
0x01 /* 1 of 17 */
};
int main(int argc, char *argv[])
{
int i;
bitstream_state_t state;
bitstream_state_t *s;
const uint8_t *r;
uint8_t *w;
uint8_t *cc;
unsigned int x;
int total_bits;
s = bitstream_init(&state, TRUE);
w = buffer;
total_bits = 0;
for (i = 0; i < SEQUENCE_LENGTH; i++)
{
bitstream_put(s, &w, PATTERN*i, i + 1);
total_bits += (i + 1);
}
bitstream_flush(s, &w);
printf("%d bits written\n", total_bits);
for (cc = buffer; cc < w; cc++)
printf("%02X ", *cc);
printf("\n");
for (cc = right; cc < right + sizeof(right); cc++)
printf("%02X ", *cc);
printf("\n");
if ((w - buffer) != sizeof(right) || memcmp(buffer, right, sizeof(right)))
{
printf("Test failed\n");
exit(2);
}
s = bitstream_init(&state, TRUE);
r = buffer;
for (i = 0; i < SEQUENCE_LENGTH; i++)
{
x = bitstream_get(s, &r, i + 1);
if (x != ((PATTERN*i) & ((1 << (i + 1)) - 1)))
{
printf("Error 0x%X 0x%X\n", x, ((PATTERN*i) & ((1 << (i + 1)) - 1)));
printf("Test failed\n");
exit(2);
}
}
s = bitstream_init(&state, FALSE);
w = buffer;
total_bits = 0;
for (i = 0; i < SEQUENCE_LENGTH; i++)
{
bitstream_put(s, &w, PATTERN*i, i + 1);
total_bits += (i + 1);
}
bitstream_flush(s, &w);
printf("%d bits written\n", total_bits);
for (cc = buffer; cc < w; cc++)
printf("%02X ", *cc);
printf("\n");
for (cc = left; cc < left + sizeof(left); cc++)
printf("%02X ", *cc);
printf("\n");
if ((w - buffer) != sizeof(left) || memcmp(buffer, left, sizeof(left)))
{
printf("Test failed\n");
exit(2);
}
s = bitstream_init(&state, FALSE);
r = buffer;
for (i = 0; i < SEQUENCE_LENGTH; i++)
{
x = bitstream_get(s, &r, i + 1);
if (x != ((PATTERN*i) & ((1 << (i + 1)) - 1)))
{
printf("Error 0x%X 0x%X\n", x, ((PATTERN*i) & ((1 << (i + 1)) - 1)));
printf("Test failed\n");
exit(2);
}
}
printf("Tests passed.\n");
return 0;
}
/*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/
差异被折叠。
/*
* SpanDSP - a series of DSP components for telephony
*
* saturated_tests.c
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2004 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.
*/
/*! \page saturated_tests_page Saturated arithmetic function tests
\section saturated_tests_page_sec_1 What does it do?
???.
\section saturated_tests_page_sec_2 How does it work?
???.
*/
#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
#include "spandsp.h"
int main(int argc, char *argv[])
{
printf("Testing 16 bit saturation\n");
if (saturate16(10000) != 10000
||
saturate16(-10000) != -10000
||
saturate16(32767) != 32767
||
saturate16(-32768) != -32768
||
saturate16(32768) != 32767
||
saturate16(-32769) != -32768)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 15 bit saturation\n");
if (saturate15(10000) != 10000
||
saturate15(-10000) != -10000
||
saturate15(16383) != 16383
||
saturate15(-16384) != -16384
||
saturate15(16384) != 16383
||
saturate15(-16385) != -16384)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 bit unsigned saturation\n");
if (saturateu16(10000) != 10000
||
saturateu16(32767) != 32767
||
saturateu16(65535) != 65535
||
saturateu16(65536) != 65535)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 8 bit unsigned saturation\n");
if (saturateu8(100) != 100
||
saturateu8(127) != 127
||
saturateu8(255) != 255
||
saturateu8(256) != 255)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 bit saturation from float\n");
if (fsaturatef(10000.0f) != 10000
||
fsaturatef(-10000.0f) != -10000
||
fsaturatef(32767.0f) != 32767
||
fsaturatef(-32768.0f) != -32768
||
fsaturatef(32768.0f) != 32767
||
fsaturatef(-32769.0f) != -32768)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 bit saturation from double\n");
if (fsaturate(10000.0) != 10000
||
fsaturate(-10000.0) != -10000
||
fsaturate(32767.0) != 32767
||
fsaturate(-32768.0) != -32768
||
fsaturate(32768.0) != 32767
||
fsaturate(-32769.0) != -32768)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 bit fast saturation from float\n");
if (ffastsaturatef(10000.0f) != 10000
||
ffastsaturatef(-10000.0f) != -10000
||
ffastsaturatef(32767.0f) != 32767
||
ffastsaturatef(-32768.0f) != -32768
||
ffastsaturatef(32768.0f) != 32767
||
ffastsaturatef(-32769.0f) != -32768)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 bit fast saturation from double\n");
if (ffastsaturate(10000.0) != 10000
||
ffastsaturate(-10000.0) != -10000
||
ffastsaturate(32767.0) != 32767
||
ffastsaturate(-32768.0) != -32768
||
ffastsaturate(32768.0) != 32767
||
ffastsaturate(-32769.0) != -32768)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 bit float saturation from float\n");
if (ffsaturatef(10000.0f) != 10000.0f
||
ffsaturatef(-10000.0f) != -10000.0f
||
ffsaturatef(32767.0f) != 32767.0f
||
ffsaturatef(-32768.0f) != -32768.0f
||
ffsaturatef(32768.0f) != 32767.0f
||
ffsaturatef(-32769.0f) != -32768.0f)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 bit double saturation from double\n");
if (ffsaturate(10000.0) != 10000.0
||
ffsaturate(-10000.0) != -10000.0
||
ffsaturate(32767.0) != 32767.0
||
ffsaturate(-32768.0) != -32768.0
||
ffsaturate(32768.0) != 32767.0
||
ffsaturate(-32769.0) != -32768.0)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 bit add\n");
if (saturated_add16(10000, 10000) != 20000
||
saturated_add16(10000, -10000) != 0
||
saturated_add16(-10000, 10000) != 0
||
saturated_add16(-10000, -10000) != -20000
||
saturated_add16(-30000, -30000) != INT16_MIN
||
saturated_add16(30000, 30000) != INT16_MAX)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 32 bit add\n");
if (saturated_add32(10000, 10000) != 20000
||
saturated_add32(10000, -10000) != 0
||
saturated_add32(-10000, 10000) != 0
||
saturated_add32(-10000, -10000) != -20000
||
saturated_add32(-2000000000, -2000000000) != INT32_MIN
||
saturated_add32(2000000000, 2000000000) != INT32_MAX)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 bit subtract\n");
if (saturated_sub16(10000, 10000) != 0
||
saturated_sub16(10000, -10000) != 20000
||
saturated_sub16(-10000, 10000) != -20000
||
saturated_sub16(-10000, -10000) != 0
||
saturated_sub16(-30000, 30000) != INT16_MIN
||
saturated_sub16(30000, -30000) != INT16_MAX)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 32 bit subtract\n");
if (saturated_sub32(10000, 10000) != 0
||
saturated_sub32(10000, -10000) != 20000
||
saturated_sub32(-10000, 10000) != -20000
||
saturated_sub32(-10000, -10000) != 0
||
saturated_sub32(-2000000000, 2000000000) != INT32_MIN
||
saturated_sub32(2000000000, -2000000000) != INT32_MAX)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 x 16 => 16 bit multiply\n");
if (saturated_mul16(100, 100) != 0
||
saturated_mul16(255, 255) != 1
||
saturated_mul16(32767, -32768) != -32767
||
saturated_mul16(-32768, 32767) != -32767
||
saturated_mul16(32767, 32767) != 32766
||
saturated_mul16(-32768, -32768) != 32767)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 x 16 => 32 bit multiply\n");
if (saturated_mul16_32(100, 100) != 20000
||
saturated_mul16_32(-100, 100) != -20000
||
saturated_mul16_32(32767, -32768) != -2147418112
||
saturated_mul16_32(-32768, 32767) != -2147418112
||
saturated_mul16_32(32767, 32767) != 2147352578
||
saturated_mul16_32(-32768, -32768) != -2147483648)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 bit absolute\n");
if (saturated_abs16(10000) != 10000
||
saturated_abs16(-10000) != 10000
||
saturated_abs16(32767) != 32767
||
saturated_abs16(-32768) != 32767)
{
printf("Test failed.\n");
exit(2);
}
printf("Tests passed.\n");
return 0;
}
/*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/
/*
* SpanDSP - a series of DSP components for telephony
*
* timezone_tests.c - Timezone handling for time interpretation
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2010 Steve Underwood
*
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1,
* 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*! \page timezone_tests_page Timezone handling tests
\section timezone_tests_page_sec_1 What does it do?
*/
#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif
#include <stdlib.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
//#if defined(WITH_SPANDSP_INTERNALS)
#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
//#endif
#include "spandsp.h"
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
int main(int argc, char *argv[])
{
struct tm tms;
struct tm *tmp = &tms;
time_t ltime;
tz_t *tz;
/* Get the current time */
ltime = time(NULL);
/* Compute the local current time now for several localities, based on Posix tz strings */
tz = tz_init(NULL, "GMT0GMT0,M10.5.0,M3.5.0");
tz_localtime(tz, tmp, ltime);
printf("Local time is %02d:%02d:%02d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
printf("Time zone is %s\n", tz_tzname(tz, tmp->tm_isdst));
tz_init(tz, "CST-8CST-8,M10.5.0,M3.5.0");
tz_localtime(tz, tmp, ltime);
printf("Local time is %02d:%02d:%02d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
printf("Time zone is %s\n", tz_tzname(tz, tmp->tm_isdst));
tz_init(tz, "AEST-10AEDT-11,M10.5.0,M3.5.0");
tz_localtime(tz, tmp, ltime);
printf("Local time is %02d:%02d:%02d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
printf("Time zone is %s\n", tz_tzname(tz, tmp->tm_isdst));
tz_free(tz);
return 0;
}
/*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/
#!/bin/sh
#
# spandsp fax tests
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 2.1,
# 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 Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
run_tsb85_test()
{
rm -f fax_tests_1.tif
echo ./tsb85_tests ${TEST}
./tsb85_tests -x ../spandsp/fax-tests.xml ${TEST} 2>xyzzy2
RETVAL=$?
if [ $RETVAL != 0 ]
then
echo tsb85_tests ${TEST} failed!
exit $RETVAL
fi
}
for TEST in PPS-MPS-lost-PPS ; do
run_tsb85_test
done
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论