private/t4_rx.h

00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * private/t4_rx.h - definitions for T.4 FAX receive 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_rx.h,v 1.6.2.8 2009/12/21 17:18:40 steveu Exp $
00026  */
00027 
00028 #if !defined(_SPANDSP_PRIVATE_T4_RX_H_)
00029 #define _SPANDSP_PRIVATE_T4_RX_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 current file name. */
00037     const char *file;
00038     /*! \brief The libtiff context for the current TIFF file */
00039     TIFF *tiff_file;
00040 
00041     /*! \brief The number of pages in the current image file. */
00042     int pages_in_file;
00043 
00044     /*! \brief The compression type for output to the TIFF file. */
00045     int32_t output_compression;
00046     /*! \brief The TIFF photometric setting for the current page. */
00047     uint16_t photo_metric;
00048     /*! \brief The TIFF fill order setting for the current page. */
00049     uint16_t fill_order;
00050     /*! \brief The TIFF G3 FAX options. */
00051     int32_t output_t4_options;
00052 
00053     /* "Background" information about the FAX, which can be stored in the image file. */
00054     /*! \brief The vendor of the machine which produced the file. */ 
00055     const char *vendor;
00056     /*! \brief The model of machine which produced the file. */ 
00057     const char *model;
00058     /*! \brief The local ident string. */ 
00059     const char *local_ident;
00060     /*! \brief The remote end's ident string. */ 
00061     const char *far_ident;
00062     /*! \brief The FAX sub-address. */ 
00063     const char *sub_address;
00064     /*! \brief The FAX DCS information, as an ASCII string. */ 
00065     const char *dcs;
00066 
00067     /*! \brief The first page to transfer. -1 to start at the beginning of the file. */
00068     int start_page;
00069     /*! \brief The last page to transfer. -1 to continue to the end of the file. */
00070     int stop_page;
00071 } t4_tiff_state_t;
00072 
00073 typedef struct t4_t6_decode_state_s t4_t6_decode_state_t;
00074 
00075 /*!
00076     T.4 1D, T4 2D and T6 decompressor state.
00077 */
00078 struct t4_t6_decode_state_s
00079 {
00080     /*! \brief Callback function to write a row of pixels to the image destination. */
00081     t4_row_write_handler_t row_write_handler;
00082     /*! \brief Opaque pointer passed to row_write_handler. */
00083     void *row_write_user_data;
00084 
00085     /*! \brief Incoming bit buffer for decompression. */
00086     uint32_t rx_bitstream;
00087     /*! \brief The number of bits currently in rx_bitstream. */
00088     int rx_bits;
00089     /*! \brief The number of bits to be skipped before trying to match the next code word. */
00090     int rx_skip_bits;
00091 
00092     /*! \brief This variable is used to count the consecutive EOLS we have seen. If it
00093                reaches six, this is the end of the image. It is initially set to -1 for
00094                1D and 2D decoding, as an indicator that we must wait for the first EOL,
00095                before decoding any image data. */
00096     int consecutive_eols;
00097 
00098     /*! \brief The reference or starting changing element on the coding line. At the
00099                start of the coding line, a0 is set on an imaginary white changing element
00100                situated just before the first element on the line. During the coding of
00101                the coding line, the position of a0 is defined by the previous coding mode.
00102                (See T.4/4.2.1.3.2.). */
00103     int a0;
00104     /*! \brief The first changing element on the reference line to the right of a0 and of
00105                opposite colour to a0. */
00106     int b1;
00107     /*! \brief The length of the in-progress run of black or white. */
00108     int run_length;
00109     /*! \brief 2D horizontal mode control. */
00110     int black_white;
00111     /*! \brief TRUE if the current run is black */
00112     int its_black;
00113 
00114     /*! \brief The current step into the current row run-lengths buffer. */
00115     int a_cursor;
00116     /*! \brief The current step into the reference row run-lengths buffer. */
00117     int b_cursor;
00118 
00119     /*! \brief A pointer into the image buffer indicating where the last row begins */
00120     int last_row_starts_at;
00121 
00122     /*! \brief The current number of consecutive bad rows. */
00123     int curr_bad_row_run;
00124     /*! \brief The longest run of consecutive bad rows seen in the current page. */
00125     int longest_bad_row_run;
00126     /*! \brief The total number of bad rows in the current page. */
00127     int bad_rows;
00128 };
00129 
00130 #endif
00131 /*- End of file ------------------------------------------------------------*/