00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * private/t85.h - ITU T.85 JBIG for FAX image processing 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2008, 2009 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 00026 #if !defined(_SPANDSP_PRIVATE_T85_H_) 00027 #define _SPANDSP_PRIVATE_T85_H_ 00028 00029 /* Maximum number of ATMOVEs per stripe that the decoder can handle */ 00030 #define T85_ATMOVES_MAX 1 00031 00032 /* TP special pixels */ 00033 #define TPB2CX 0x195 00034 #define TPB3CX 0x0E5 00035 00036 /* T.82 table 2 - symbolic constants */ 00037 enum 00038 { 00039 T82_STUFF = 0x00, 00040 T82_RESERVE = 0x01, 00041 T82_SDNORM = 0x02, 00042 T82_SDRST = 0x03, 00043 T82_ABORT = 0x04, 00044 T82_NEWLEN = 0x05, 00045 T82_ATMOVE = 0x06, 00046 T82_COMMENT = 0x07, 00047 T82_ESC = 0xFF 00048 }; 00049 00050 /* State of a working instance of the T.85 JBIG FAX encoder */ 00051 struct t85_encode_state_s 00052 { 00053 /*! \brief Callback function to read a row of pixels from the image source. */ 00054 t4_row_read_handler_t row_read_handler; 00055 /*! \brief Opaque pointer passed to row_read_handler. */ 00056 void *row_read_user_data; 00057 00058 /*! The number of bit planes. Always 1 for true T.85 */ 00059 uint8_t bit_planes; 00060 uint8_t current_bit_plane; 00061 /*! The width of the full image, in pixels */ 00062 uint32_t xd; 00063 /*! The height of the full image, in pixels */ 00064 uint32_t yd; 00065 /*! The number of rows per stripe */ 00066 uint32_t l0; 00067 /*! Maximum ATMOVE window size (0 - 127) */ 00068 int mx; 00069 /*! Encoding parameters */ 00070 int options; 00071 /*! The contents for a COMMENT marker segment, to be added to the 00072 image at the next opportunity. This is set to NULL when nothing is 00073 pending. */ 00074 const uint8_t *comment; 00075 /*! Length of data pointed to by comment */ 00076 size_t comment_len; 00077 00078 /*! Next row number to be encoded */ 00079 uint32_t y; 00080 /*! Next row within current stripe */ 00081 uint32_t i; 00082 /*! Flag for handling NEWLEN processing. */ 00083 int newlen; 00084 /*! X-offset of adaptive template pixel */ 00085 int32_t tx; 00086 /*! Adaptive template algorithm variables */ 00087 uint32_t c_all; 00088 /*! Adaptive template algorithm variables */ 00089 uint32_t c[128]; 00090 /*! New TX value, or <0 for analysis in progress */ 00091 int32_t new_tx; 00092 /*! TRUE if previous row was typical */ 00093 int prev_ltp; 00094 /*! Pointers to the 3 row buffers */ 00095 uint8_t *prev_row[3]; 00096 /*! Pointer to a block of allocated memory 3 rows long, which 00097 we divide up for the 3 row buffers. */ 00098 uint8_t *row_buf; 00099 uint8_t *bitstream; 00100 int bitstream_len; 00101 int bitstream_iptr; 00102 int bitstream_optr; 00103 int fill_with_white; 00104 00105 /*! \brief The size of the compressed image, in bytes. */ 00106 int compressed_image_size; 00107 00108 /*! Arithmetic encoder state */ 00109 t81_t82_arith_encode_state_t s; 00110 00111 /*! \brief Error and flow logging control */ 00112 logging_state_t logging; 00113 }; 00114 00115 /* State of a working instance of the T.85 JBIG FAX decoder */ 00116 struct t85_decode_state_s 00117 { 00118 /*! A callback routine to handle decoded pixel rows */ 00119 t4_row_write_handler_t row_write_handler; 00120 /*! An opaque pointer passed to row_write_handler() */ 00121 void *row_write_user_data; 00122 /*! A callback routine to handle decoded comments */ 00123 t4_row_write_handler_t comment_handler; 00124 /*! An opaque pointer passed to comment_handler() */ 00125 void *comment_user_data; 00126 /*! The maximum length of comment to be passed to the comment handler */ 00127 uint32_t max_comment_len; 00128 00129 uint8_t min_bit_planes; 00130 uint8_t max_bit_planes; 00131 /*! The maximum permitted width of the full image, in pixels */ 00132 uint32_t max_xd; 00133 /*! The maximum permitted height of the full image, in pixels */ 00134 uint32_t max_yd; 00135 00136 /*! The number of bit planes expected, according to the header. Always 1 for true T.85 */ 00137 uint8_t bit_planes; 00138 uint8_t current_bit_plane; 00139 00140 /*! The width of the full image, in pixels */ 00141 uint32_t xd; 00142 /*! The height of the full image, in pixels */ 00143 uint32_t yd; 00144 /*! The number of rows per stripe */ 00145 uint32_t l0; 00146 /*! Maximum ATMOVE window size */ 00147 int mx; 00148 /*! Encoding parameters */ 00149 int options; 00150 00151 /*! The current row and the previous 2 rows of image data */ 00152 int p[3]; 00153 /*! Pointers to the 3 row buffers */ 00154 uint8_t *prev_row[3]; 00155 /*! Pointer to a block of allocated memory 3 rows long, which 00156 we divide up for the 3 row buffers. */ 00157 uint8_t *row_buf; 00158 /*! The length of the row buffer */ 00159 int row_buf_len; 00160 /*! Bytes per pixel row */ 00161 size_t bytes_per_row; 00162 /*! X-offset of AT pixel */ 00163 int32_t tx; 00164 /*! Number of bytes read so far */ 00165 uint32_t bie_len; 00166 /*! Buffer space for the BIH or marker segments fragments */ 00167 uint8_t buffer[20]; 00168 /*! Number of bytes in buffer. */ 00169 int buf_len; 00170 /*! Required number of bytes in buffer to proceed with processing 00171 its contents. */ 00172 int buf_needed; 00173 /*! The content of a decoded COMMENT marker segment. */ 00174 uint8_t *comment; 00175 /*! The expected length of a decoded COMMENT segment */ 00176 uint32_t comment_len; 00177 /*! The length of COMMENT decoded to date */ 00178 uint32_t comment_progress; 00179 /*! Current column */ 00180 uint32_t x; 00181 /*! Current row */ 00182 uint32_t y; 00183 /*! Current row within the current stripe */ 00184 uint32_t i; 00185 /*! Number of AT moves in the current stripe */ 00186 int at_moves; 00187 /*! Rows at which an AT move will happen */ 00188 uint32_t at_row[T85_ATMOVES_MAX]; 00189 /*! ATMOVE x-offsets in current stripe */ 00190 int at_tx[T85_ATMOVES_MAX]; 00191 /*! Working data for decode_pscd() */ 00192 uint32_t row_h[3]; 00193 /*! Flag for TPBON/TPDON: next pixel is a pseudo pixel */ 00194 int pseudo; 00195 /*! Line is not typical flag. */ 00196 int lntp; 00197 /*! Flag that row_write_handler() requested an interrupt. */ 00198 int interrupt; 00199 /*! Flag that the data to be decoded has run out. */ 00200 int end_of_data; 00201 /*! Arithmetic decoder state */ 00202 t81_t82_arith_decode_state_t s; 00203 00204 /*! \brief The size of the compressed image, in bytes. */ 00205 int compressed_image_size; 00206 00207 /*! \brief Error and flow logging control */ 00208 logging_state_t logging; 00209 }; 00210 00211 #endif 00212 /*- End of file ------------------------------------------------------------*/
1.6.1