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.4 2009/02/20 12:34:20 steveu Exp $
00026  */
00027 
00028 #if !defined(_SPANDSP_PRIVATE_T4_H_)
00029 #define _SPANDSP_PRIVATE_T4_H_
00030 
00031 /*!
00032     TIFF specific state information to go with T.4 compression or decompression handling.
00033 */
00034 typedef struct
00035 {
00036     /*! \brief The libtiff context for the current TIFF file */
00037     TIFF *tiff_file;
00038 
00039     /*! \brief The compression type for output to the TIFF file. */
00040     int output_compression;
00041     /*! \brief The TIFF G3 FAX options. */
00042     int output_t4_options;
00043     /*! \brief The TIFF photometric setting for the current page. */
00044     uint16_t photo_metric;
00045     /*! \brief The TIFF fill order setting for the current page. */
00046     uint16_t fill_order;
00047 
00048     /* "Background" information about the FAX, which can be stored in the image file. */
00049     /*! \brief The vendor of the machine which produced the file. */ 
00050     const char *vendor;
00051     /*! \brief The model of machine which produced the file. */ 
00052     const char *model;
00053     /*! \brief The local ident string. */ 
00054     const char *local_ident;
00055     /*! \brief The remote end's ident string. */ 
00056     const char *far_ident;
00057     /*! \brief The FAX sub-address. */ 
00058     const char *sub_address;
00059     /*! \brief The FAX DCS information, as an ASCII string. */ 
00060     const char *dcs;
00061 } t4_tiff_state_t;
00062 
00063 /*!
00064     T.4 FAX compression/decompression descriptor. This defines the working state
00065     for a single instance of a T.4 FAX compression or decompression channel.
00066 */
00067 struct t4_state_s
00068 {
00069     /*! \brief The same structure is used for T.4 transmit and receive. This variable
00070                records which mode is in progress. */
00071     int rx;
00072 
00073     /*! \brief The type of compression used between the FAX machines. */
00074     int line_encoding;
00075     /*! \brief The minimum number of encoded bits per row. This is a timing thing
00076                for hardware FAX machines. */
00077     int min_bits_per_row;
00078     
00079     /*! \brief Callback function to read a row of pixels from the image source. */
00080     t4_row_read_handler_t row_read_handler;
00081     /*! \brief Opaque pointer passed to row_read_handler. */
00082     void *row_read_user_data;
00083     /*! \brief Callback function to write a row of pixels to the image destination. */
00084     t4_row_write_handler_t row_write_handler;
00085     /*! \brief Opaque pointer passed to row_write_handler. */
00086     void *row_write_user_data;
00087 
00088     /*! \brief The time at which handling of the current page began. */
00089     time_t page_start_time;
00090 
00091     /*! \brief The current number of bytes per row of uncompressed image data. */
00092     int bytes_per_row;
00093     /*! \brief The size of the image in the image buffer, in bytes. */
00094     int image_size;
00095     /*! \brief The size of the compressed image on the line side, in bits. */
00096     int line_image_size;
00097     /*! \brief The current size of the image buffer. */
00098     int image_buffer_size;
00099     /*! \brief A point to the image buffer. */
00100     uint8_t *image_buffer;
00101 
00102     /*! \brief The current file name. */
00103     const char *file;
00104     /*! \brief The first page to transfer. -1 to start at the beginning of the file. */
00105     int start_page;
00106     /*! \brief The last page to transfer. -1 to continue to the end of the file. */
00107     int stop_page;
00108 
00109     /*! \brief The number of pages transferred to date. */
00110     int current_page;
00111     /*! \brief The number of pages in the current image file. */
00112     int pages_in_file;
00113     /*! \brief Column-to-column (X) resolution in pixels per metre. */
00114     int x_resolution;
00115     /*! \brief Row-to-row (Y) resolution in pixels per metre. */
00116     int y_resolution;
00117     /*! \brief Width of the current page, in pixels. */
00118     int image_width;
00119     /*! \brief Length of the current page, in pixels. */
00120     int image_length;
00121     /*! \brief Current pixel row number. */
00122     int row;
00123     /*! \brief The current number of consecutive bad rows. */
00124     int curr_bad_row_run;
00125     /*! \brief The longest run of consecutive bad rows seen in the current page. */
00126     int longest_bad_row_run;
00127     /*! \brief The total number of bad rows in the current page. */
00128     int bad_rows;
00129 
00130     /*! \brief Incoming bit buffer for decompression. */
00131     uint32_t rx_bitstream;
00132     /*! \brief The number of bits currently in rx_bitstream. */
00133     int rx_bits;
00134     /*! \brief The number of bits to be skipped before trying to match the next code word. */
00135     int rx_skip_bits;
00136 
00137     /*! \brief This variable is set if we are treating the current row as a 2D encoded
00138                one. */
00139     int row_is_2d;
00140     /*! \brief TRUE if the current run is black */
00141     int its_black;
00142     /*! \brief The current length of the current row. */
00143     int row_len;
00144     /*! \brief This variable is used to count the consecutive EOLS we have seen. If it
00145                reaches six, this is the end of the image. It is initially set to -1 for
00146                1D and 2D decoding, as an indicator that we must wait for the first EOL,
00147                before decodin any image data. */
00148     int consecutive_eols;
00149 
00150     /*! \brief Black and white run-lengths for the current row. */
00151     uint32_t *cur_runs;
00152     /*! \brief Black and white run-lengths for the reference row. */
00153     uint32_t *ref_runs;
00154     /*! \brief The number of runs currently in the reference row. */
00155     int ref_steps;
00156     /*! \brief The current step into the reference row run-lengths buffer. */
00157     int b_cursor;
00158     /*! \brief The current step into the current row run-lengths buffer. */
00159     int a_cursor;
00160 
00161     /*! \brief The reference or starting changing element on the coding line. At the
00162                start of the coding line, a0 is set on an imaginary white changing element
00163                situated just before the first element on the line. During the coding of
00164                the coding line, the position of a0 is defined by the previous coding mode.
00165                (See 4.2.1.3.2.). */
00166     int a0;
00167     /*! \brief The first changing element on the reference line to the right of a0 and of
00168                opposite colour to a0. */
00169     int b1;
00170     /*! \brief The length of the in-progress run of black or white. */
00171     int run_length;
00172     /*! \brief 2D horizontal mode control. */
00173     int black_white;
00174 
00175     /*! \brief Encoded data bits buffer. */
00176     uint32_t tx_bitstream;
00177     /*! \brief The number of bits currently in tx_bitstream. */
00178     int tx_bits;
00179 
00180     /*! \brief A pointer into the image buffer indicating where the last row begins */
00181     int last_row_starts_at;
00182     /*! \brief A pointer into the image buffer indicating where the current row begins */
00183     int row_starts_at;
00184     
00185     /*! \brief Pointer to the buffer for the current pixel row. */
00186     uint8_t *row_buf;
00187     
00188     /*! \brief Pointer to the byte containing the next image bit to transmit. */
00189     int bit_pos;
00190     /*! \brief Pointer to the bit within the byte containing the next image bit to transmit. */
00191     int bit_ptr;
00192 
00193     /*! \brief The current maximum contiguous rows that may be 2D encoded. */
00194     int max_rows_to_next_1d_row;
00195     /*! \brief Number of rows left that can be 2D encoded, before a 1D encoded row
00196                must be used. */
00197     int rows_to_next_1d_row;
00198     /*! \brief The current number of bits in the current encoded row. */
00199     int row_bits;
00200     /*! \brief The minimum bits in any row of the current page. For monitoring only. */
00201     int min_row_bits;
00202     /*! \brief The maximum bits in any row of the current page. For monitoring only. */
00203     int max_row_bits;
00204 
00205     /*! \brief The text which will be used in FAX page header. No text results
00206                in no header line. */
00207     const char *header_info;
00208 
00209     /*! \brief Error and flow logging control */
00210     logging_state_t logging;
00211 
00212     /*! \brief All TIFF file specific state information for the T.4 context. */
00213     t4_tiff_state_t tiff;
00214 };
00215 
00216 #endif
00217 /*- End of file ------------------------------------------------------------*/

Generated on Tue Aug 4 03:36:08 2009 for spandsp by  doxygen 1.5.9