private/t4.h

00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * private/t4.h - definitions for T.4 fax processing
00005  *
00006  * Written by Steve Underwood <steveu@coppice.org>
00007  *
00008  * Copyright (C) 2003 Steve Underwood
00009  *
00010  * All rights reserved.
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 2.1,
00014  * as published by the Free Software Foundation.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024  *
00025  * $Id: t4.h,v 1.1 2008/10/13 13:14:01 steveu Exp $
00026  */
00027 
00028 #if !defined(_SPANDSP_PRIVATE_T4_H_)
00029 #define _SPANDSP_PRIVATE_T4_H_
00030 
00031 /*!
00032     T.4 FAX compression/decompression descriptor. This defines the working state
00033     for a single instance of a T.4 FAX compression or decompression channel.
00034 */
00035 struct t4_state_s
00036 {
00037     /*! \brief The same structure is used for T.4 transmit and receive. This variable
00038                records which mode is in progress. */
00039     int rx;
00040     /* "Background" information about the FAX, which can be stored in a TIFF file. */
00041     /*! \brief The vendor of the machine which produced the TIFF file. */ 
00042     const char *vendor;
00043     /*! \brief The model of machine which produced the TIFF file. */ 
00044     const char *model;
00045     /*! \brief The local ident string. */ 
00046     const char *local_ident;
00047     /*! \brief The remote end's ident string. */ 
00048     const char *far_ident;
00049     /*! \brief The FAX sub-address. */ 
00050     const char *sub_address;
00051     /*! \brief The FAX DCS information, as an ASCII string. */ 
00052     const char *dcs;
00053     /*! \brief The text which will be used in FAX page header. No text results
00054                in no header line. */
00055     const char *header_info;
00056 
00057     /*! \brief The type of compression used between the FAX machines. */
00058     int line_encoding;
00059     /*! \brief The minimum number of encoded bits per row. This is a timing thing
00060                for hardware FAX machines. */
00061     int min_bits_per_row;
00062     
00063     /*! \brief The compression type for output to the TIFF file. */
00064     int output_compression;
00065     /*! \brief The TIFF G3 FAX options. */
00066     int output_t4_options;
00067 
00068     /*! \brief Callback function to read a row of pixels from the image source. */
00069     t4_row_read_handler_t row_read_handler;
00070     /*! \brief Opaque pointer passed to row_read_handler. */
00071     void *row_read_user_data;
00072     /*! \brief Callback function to write a row of pixels to the image destination. */
00073     t4_row_write_handler_t row_write_handler;
00074     /*! \brief Opaque pointer passed to row_write_handler. */
00075     void *row_write_user_data;
00076 
00077     /*! \brief The time at which handling of the current page began. */
00078     time_t page_start_time;
00079 
00080     /*! \brief The current number of bytes per row of uncompressed image data. */
00081     int bytes_per_row;
00082     /*! \brief The size of the image in the image buffer, in bytes. */
00083     int image_size;
00084     /*! \brief The size of the compressed image on the line side, in bits. */
00085     int line_image_size;
00086     /*! \brief The current size of the image buffer. */
00087     int image_buffer_size;
00088     /*! \brief A point to the image buffer. */
00089     uint8_t *image_buffer;
00090 
00091     /*! \brief The libtiff context for the current TIFF file */
00092     TIFF *tiff_file;
00093     /*! \brief The current file name. */
00094     const char *file;
00095     /*! \brief The first page to transfer. -1 to start at the beginning of the file. */
00096     int start_page;
00097     /*! \brief The last page to transfer. -1 to continue to the end of the file. */
00098     int stop_page;
00099 
00100     /*! \brief The number of pages transferred to date. */
00101     int pages_transferred;
00102     /*! \brief The number of pages in the current TIFF file. */
00103     int pages_in_file;
00104     /*! \brief Column-to-column (X) resolution in pixels per metre. */
00105     int x_resolution;
00106     /*! \brief Row-to-row (Y) resolution in pixels per metre. */
00107     int y_resolution;
00108     /*! \brief Width of the current page, in pixels. */
00109     int image_width;
00110     /*! \brief Length of the current page, in pixels. */
00111     int image_length;
00112     /*! \brief Current pixel row number. */
00113     int row;
00114     /*! \brief The current number of consecutive bad rows. */
00115     int curr_bad_row_run;
00116     /*! \brief The longest run of consecutive bad rows seen in the current page. */
00117     int longest_bad_row_run;
00118     /*! \brief The total number of bad rows in the current page. */
00119     int bad_rows;
00120 
00121     /*! \brief Incoming bit buffer for decompression. */
00122     uint32_t rx_bitstream;
00123     /*! \brief The number of bits currently in rx_bitstream. */
00124     int rx_bits;
00125     /*! \brief The number of bits to be skipped before trying to match the next code word. */
00126     int rx_skip_bits;
00127 
00128     /*! \brief This variable is set if we are treating the current row as a 2D encoded
00129                one. */
00130     int row_is_2d;
00131     /*! \brief TRUE if the current run is black */
00132     int its_black;
00133     /*! \brief The current length of the current row. */
00134     int row_len;
00135     /*! \brief This variable is used to count the consecutive EOLS we have seen. If it
00136                reaches six, this is the end of the image. It is initially set to -1 for
00137                1D and 2D decoding, as an indicator that we must wait for the first EOL,
00138                before decodin any image data. */
00139     int consecutive_eols;
00140 
00141     /*! \brief Black and white run-lengths for the current row. */
00142     uint32_t *cur_runs;
00143     /*! \brief Black and white run-lengths for the reference row. */
00144     uint32_t *ref_runs;
00145     /*! \brief The number of runs currently in the reference row. */
00146     int ref_steps;
00147     /*! \brief The current step into the reference row run-lengths buffer. */
00148     int b_cursor;
00149     /*! \brief The current step into the current row run-lengths buffer. */
00150     int a_cursor;
00151 
00152     /*! \brief The reference or starting changing element on the coding line. At the
00153                start of the coding line, a0 is set on an imaginary white changing element
00154                situated just before the first element on the line. During the coding of
00155                the coding line, the position of a0 is defined by the previous coding mode.
00156                (See 4.2.1.3.2.). */
00157     int a0;
00158     /*! \brief The first changing element on the reference line to the right of a0 and of
00159                opposite colour to a0. */
00160     int b1;
00161     /*! \brief The length of the in-progress run of black or white. */
00162     int run_length;
00163     /*! \brief 2D horizontal mode control. */
00164     int black_white;
00165 
00166     /*! \brief Encoded data bits buffer. */
00167     uint32_t tx_bitstream;
00168     /*! \brief The number of bits currently in tx_bitstream. */
00169     int tx_bits;
00170 
00171     /*! \brief A pointer into the image buffer indicating where the last row begins */
00172     int last_row_starts_at;
00173     /*! \brief A pointer into the image buffer indicating where the current row begins */
00174     int row_starts_at;
00175     
00176     /*! \brief Pointer to the buffer for the current pixel row. */
00177     uint8_t *row_buf;
00178     
00179     /*! \brief Pointer to the byte containing the next image bit to transmit. */
00180     int bit_pos;
00181     /*! \brief Pointer to the bit within the byte containing the next image bit to transmit. */
00182     int bit_ptr;
00183 
00184     /*! \brief The current maximum contiguous rows that may be 2D encoded. */
00185     int max_rows_to_next_1d_row;
00186     /*! \brief Number of rows left that can be 2D encoded, before a 1D encoded row
00187                must be used. */
00188     int rows_to_next_1d_row;
00189     /*! \brief The current number of bits in the current encoded row. */
00190     int row_bits;
00191     /*! \brief The minimum bits in any row of the current page. For monitoring only. */
00192     int min_row_bits;
00193     /*! \brief The maximum bits in any row of the current page. For monitoring only. */
00194     int max_row_bits;
00195 
00196     /*! \brief Error and flow logging control */
00197     logging_state_t logging;
00198 };
00199 
00200 #endif
00201 /*- End of file ------------------------------------------------------------*/

Generated on Thu Feb 12 14:16:08 2009 for spandsp by  doxygen 1.5.5