00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * 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 00026 /*! \file */ 00027 00028 #if !defined(_SPANDSP_T4_RX_H_) 00029 #define _SPANDSP_T4_RX_H_ 00030 00031 /*! \page t4_page T.4 image compression and decompression 00032 00033 \section t4_page_sec_1 What does it do? 00034 The T.4 image compression and decompression routines implement the 1D and 2D 00035 encoding methods defined in ITU specification T.4. They also implement the pure 00036 2D encoding method defined in T.6. These are image compression algorithms used 00037 for FAX transmission. 00038 00039 \section t4_page_sec_1 How does it work? 00040 */ 00041 00042 /*! This function is a callback from the image decoders, to write the decoded bi-level image, 00043 row by row. It is called for each row, with len set to the number of bytes per row. At the 00044 end of the image it is called with len set to zero, to indicate the end of image condition. 00045 \return 0 for OK, or non-zero for a problem that requires the image be interrupted. */ 00046 typedef int (*t4_row_write_handler_t)(void *user_data, const uint8_t buf[], size_t len); 00047 00048 /*! Supported compression modes. */ 00049 typedef enum 00050 { 00051 /*! No compression */ 00052 T4_COMPRESSION_NONE = 0, 00053 /*! T.1 1D compression */ 00054 T4_COMPRESSION_ITU_T4_1D = 1, 00055 /*! T.4 2D compression */ 00056 T4_COMPRESSION_ITU_T4_2D = 2, 00057 /*! T.6 2D compression */ 00058 T4_COMPRESSION_ITU_T6 = 3, 00059 /*! T.85 monochrome JBIG coding with L0 fixed. */ 00060 T4_COMPRESSION_ITU_T85 = 4, 00061 /*! T.85 monochrome JBIG coding with L0 variable. */ 00062 T4_COMPRESSION_ITU_T85_L0 = 5, 00063 /*! T.43 colour JBIG coding */ 00064 T4_COMPRESSION_ITU_T43 = 6, 00065 /*! T.45 run length colour compression */ 00066 T4_COMPRESSION_ITU_T45 = 7, 00067 /*! T.42 + T.81 + T.30 Annex E colour JPEG coding */ 00068 T4_COMPRESSION_ITU_T42 = 8, 00069 /*! T.42 + T.81 + T.30 Annex K colour sYCC-JPEG coding */ 00070 T4_COMPRESSION_ITU_SYCC_T42 = 9 00071 } t4_image_compression_t; 00072 00073 /*! Image type */ 00074 typedef enum 00075 { 00076 T4_IMAGE_TYPE_BILEVEL = 0, 00077 T4_IMAGE_TYPE_COLOUR_BILEVEL = 1, 00078 T4_IMAGE_TYPE_GRAY_8BIT = 2, 00079 T4_IMAGE_TYPE_GRAY_12BIT = 3, 00080 T4_IMAGE_TYPE_COLOUR_8BIT = 4, 00081 T4_IMAGE_TYPE_COLOUR_12BIT = 5 00082 } t4_image_types_t; 00083 00084 /*! Supported X resolutions, in pixels per metre. */ 00085 typedef enum 00086 { 00087 T4_X_RESOLUTION_R4 = 4016, 00088 T4_X_RESOLUTION_R8 = 8031, 00089 T4_X_RESOLUTION_300 = 11811, 00090 T4_X_RESOLUTION_R16 = 16063, 00091 T4_X_RESOLUTION_600 = 23622, 00092 T4_X_RESOLUTION_800 = 31496, 00093 T4_X_RESOLUTION_1200 = 47244 00094 } t4_image_x_resolution_t; 00095 00096 /*! Supported Y resolutions, in pixels per metre. */ 00097 typedef enum 00098 { 00099 T4_Y_RESOLUTION_STANDARD = 3850, 00100 T4_Y_RESOLUTION_FINE = 7700, 00101 T4_Y_RESOLUTION_300 = 11811, 00102 T4_Y_RESOLUTION_SUPERFINE = 15400, /* 400 is 15748 */ 00103 T4_Y_RESOLUTION_600 = 23622, 00104 T4_Y_RESOLUTION_800 = 31496, 00105 T4_Y_RESOLUTION_1200 = 47244 00106 } t4_image_y_resolution_t; 00107 00108 /*! 00109 Exact widths in PELs for the difference resolutions, and page widths. 00110 Note: 00111 The A4 widths also apply to North American letter and legal. 00112 The R4 resolution widths are not supported in recent versions of T.30 00113 Only images of exactly these widths are acceptable for FAX transmisson. 00114 00115 R4 864 pels/215mm for ISO A4, North American Letter and Legal 00116 R4 1024 pels/255mm for ISO B4 00117 R4 1216 pels/303mm for ISO A3 00118 R8 1728 pels/215mm for ISO A4, North American Letter and Legal 00119 R8 2048 pels/255mm for ISO B4 00120 R8 2432 pels/303mm for ISO A3 00121 R16 3456 pels/215mm for ISO A4, North American Letter and Legal 00122 R16 4096 pels/255mm for ISO B4 00123 R16 4864 pels/303mm for ISO A3 00124 */ 00125 typedef enum 00126 { 00127 T4_WIDTH_R4_A4 = 864, 00128 T4_WIDTH_R4_B4 = 1024, 00129 T4_WIDTH_R4_A3 = 1216, 00130 T4_WIDTH_R8_A4 = 1728, 00131 T4_WIDTH_R8_B4 = 2048, 00132 T4_WIDTH_R8_A3 = 2432, 00133 T4_WIDTH_300_A4 = 2592, 00134 T4_WIDTH_300_B4 = 3072, 00135 T4_WIDTH_300_A3 = 3648, 00136 T4_WIDTH_R16_A4 = 3456, 00137 T4_WIDTH_R16_B4 = 4096, 00138 T4_WIDTH_R16_A3 = 4864, 00139 T4_WIDTH_600_A4 = 5184, 00140 T4_WIDTH_600_B4 = 6144, 00141 T4_WIDTH_600_A3 = 7296, 00142 T4_WIDTH_1200_A4 = 10368, 00143 T4_WIDTH_1200_B4 = 12288, 00144 T4_WIDTH_1200_A3 = 14592 00145 } t4_image_width_t; 00146 00147 /*! 00148 Length of the various supported paper sizes, in pixels at the various Y resolutions. 00149 Paper sizes are 00150 A4 (215mm x 297mm) 00151 B4 (255mm x 364mm) 00152 A3 (303mm x 418.56mm) 00153 North American Letter (215.9mm x 279.4mm) 00154 North American Legal (215.9mm x 355.6mm) 00155 Unlimited 00156 00157 T.4 does not accurately define the maximum number of scan lines in a page. A wide 00158 variety of maximum row counts are used in the real world. It is important not to 00159 set our sending limit too high, or a receiving machine might split pages. It is 00160 important not to set it too low, or we might clip pages. 00161 00162 Values seen for standard resolution A4 pages include 1037, 1045, 1109, 1126 and 1143. 00163 1109 seems the most-popular. At fine res 2150, 2196, 2200, 2237, 2252-2262, 2264, 00164 2286, and 2394 are used. 2255 seems the most popular. We try to use balanced choices 00165 here. 00166 */ 00167 typedef enum 00168 { 00169 /* A4 is 297mm long */ 00170 T4_LENGTH_STANDARD_A4 = 1143, 00171 T4_LENGTH_FINE_A4 = 2286, 00172 T4_LENGTH_300_A4 = 4665, 00173 T4_LENGTH_SUPERFINE_A4 = 4573, 00174 T4_LENGTH_600_A4 = 6998, 00175 T4_LENGTH_800_A4 = 9330, 00176 T4_LENGTH_1200_A4 = 13996, 00177 /* B4 is 364mm long */ 00178 T4_LENGTH_STANDARD_B4 = 1401, 00179 T4_LENGTH_FINE_B4 = 2802, 00180 T4_LENGTH_300_B4 = 0, 00181 T4_LENGTH_SUPERFINE_B4 = 5605, 00182 T4_LENGTH_600_B4 = 0, 00183 T4_LENGTH_800_B4 = 0, 00184 T4_LENGTH_1200_B4 = 0, 00185 /* North American letter is 279.4mm long */ 00186 T4_LENGTH_STANDARD_US_LETTER = 1075, 00187 T4_LENGTH_FINE_US_LETTER = 2151, 00188 T4_LENGTH_300_US_LETTER = 0, 00189 T4_LENGTH_SUPERFINE_US_LETTER = 4302, 00190 T4_LENGTH_600_US_LETTER = 0, 00191 T4_LENGTH_800_US_LETTER = 0, 00192 T4_LENGTH_1200_US_LETTER = 0, 00193 /* North American legal is 355.6mm long */ 00194 T4_LENGTH_STANDARD_US_LEGAL = 1369, 00195 T4_LENGTH_FINE_US_LEGAL = 2738, 00196 T4_LENGTH_300_US_LEGAL = 0, 00197 T4_LENGTH_SUPERFINE_US_LEGAL = 5476, 00198 T4_LENGTH_600_US_LEGAL = 0, 00199 T4_LENGTH_800_US_LEGAL = 0, 00200 T4_LENGTH_1200_US_LEGAL = 0 00201 } t4_image_length_t; 00202 00203 /*! Return values from the T.85 decoder */ 00204 typedef enum 00205 { 00206 /*! More image data is needed */ 00207 T4_DECODE_MORE_DATA = 0, 00208 /*! Image completed successfully */ 00209 T4_DECODE_OK = -1, 00210 /*! The decoder has interrupted */ 00211 T4_DECODE_INTERRUPT = -2, 00212 /*! An abort was found in the image data */ 00213 T4_DECODE_ABORTED = -3, 00214 /*! A memory allocation error occurred */ 00215 T4_DECODE_NOMEM = -4, 00216 /*! The image data is invalid. */ 00217 T4_DECODE_INVALID_DATA = -5 00218 } t4_decoder_status_t; 00219 00220 /*! 00221 T.4 FAX compression/decompression descriptor. This defines the working state 00222 for a single instance of a T.4 FAX compression or decompression channel. 00223 */ 00224 typedef struct t4_rx_state_s t4_rx_state_t; 00225 00226 /*! 00227 T.4 FAX compression/decompression statistics. 00228 */ 00229 typedef struct 00230 { 00231 /*! \brief The number of pages transferred so far. */ 00232 int pages_transferred; 00233 /*! \brief The number of pages in the file (<0 if unknown). */ 00234 int pages_in_file; 00235 /*! \brief The number of horizontal pixels in the most recent page. */ 00236 int width; 00237 /*! \brief The number of vertical pixels in the most recent page. */ 00238 int length; 00239 /*! \brief The number of bad pixel rows in the most recent page. */ 00240 int bad_rows; 00241 /*! \brief The largest number of bad pixel rows in a block in the most recent page. */ 00242 int longest_bad_row_run; 00243 /*! \brief The horizontal resolution of the page in pixels per metre */ 00244 int x_resolution; 00245 /*! \brief The vertical resolution of the page in pixels per metre */ 00246 int y_resolution; 00247 /*! \brief The type of compression used between the FAX machines */ 00248 int encoding; 00249 /*! \brief The size of the image on the line, in bytes */ 00250 int line_image_size; 00251 } t4_stats_t; 00252 00253 #if defined(__cplusplus) 00254 extern "C" { 00255 #endif 00256 00257 /*! \brief Prepare for reception of a document. 00258 \param s The T.4 context. 00259 \param file The name of the file to be received. 00260 \param output_encoding The output encoding. 00261 \return A pointer to the context, or NULL if there was a problem. */ 00262 SPAN_DECLARE(t4_rx_state_t *) t4_rx_init(t4_rx_state_t *s, const char *file, int output_encoding); 00263 00264 /*! \brief Prepare to receive the next page of the current document. 00265 \param s The T.4 context. 00266 \return zero for success, -1 for failure. */ 00267 SPAN_DECLARE(int) t4_rx_start_page(t4_rx_state_t *s); 00268 00269 /*! \brief Put a bit of the current document page. 00270 \param s The T.4 context. 00271 \param bit The data bit. 00272 \return TRUE when the bit ends the document page, otherwise FALSE. */ 00273 SPAN_DECLARE(int) t4_rx_put_bit(t4_rx_state_t *s, int bit); 00274 00275 /*! \brief Put a byte of the current document page. 00276 \param s The T.4 context. 00277 \param buf The buffer containing the chunk. 00278 \param len The length of the chunk. 00279 \return TRUE when the byte ends the document page, otherwise FALSE. */ 00280 SPAN_DECLARE(int) t4_rx_put(t4_rx_state_t *s, const uint8_t buf[], size_t len); 00281 00282 /*! \brief Complete the reception of a page. 00283 \param s The T.4 receive context. 00284 \return 0 for success, otherwise -1. */ 00285 SPAN_DECLARE(int) t4_rx_end_page(t4_rx_state_t *s); 00286 00287 /*! \brief End reception of a document. Tidy up and close the file. 00288 This should be used to end T.4 reception started with 00289 t4_rx_init. 00290 \param s The T.4 receive context. 00291 \return 0 for success, otherwise -1. */ 00292 SPAN_DECLARE(int) t4_rx_release(t4_rx_state_t *s); 00293 00294 /*! \brief End reception of a document. Tidy up, close the file and 00295 free the context. This should be used to end T.4 reception 00296 started with t4_rx_init. 00297 \param s The T.4 receive context. 00298 \return 0 for success, otherwise -1. */ 00299 SPAN_DECLARE(int) t4_rx_free(t4_rx_state_t *s); 00300 00301 /*! \brief Set the row write handler for a T.4 receive context. 00302 \param s The T.4 receive context. 00303 \param handler A pointer to the handler routine. 00304 \param user_data An opaque pointer passed to the handler routine. 00305 \return 0 for success, otherwise -1. */ 00306 SPAN_DECLARE(int) t4_rx_set_row_write_handler(t4_rx_state_t *s, t4_row_write_handler_t handler, void *user_data); 00307 00308 /*! \brief Set the encoding for the received data. 00309 \param s The T.4 context. 00310 \param encoding The encoding. 00311 \return 0 for success, otherwise -1. */ 00312 SPAN_DECLARE(int) t4_rx_set_rx_encoding(t4_rx_state_t *s, int encoding); 00313 00314 /*! \brief Set the expected width of the received image, in pixel columns. 00315 \param s The T.4 context. 00316 \param width The number of pixels across the image. */ 00317 SPAN_DECLARE(void) t4_rx_set_image_width(t4_rx_state_t *s, int width); 00318 00319 /*! \brief Set the row-to-row (y) resolution to expect for a received image. 00320 \param s The T.4 context. 00321 \param resolution The resolution, in pixels per metre. */ 00322 SPAN_DECLARE(void) t4_rx_set_y_resolution(t4_rx_state_t *s, int resolution); 00323 00324 /*! \brief Set the column-to-column (x) resolution to expect for a received image. 00325 \param s The T.4 context. 00326 \param resolution The resolution, in pixels per metre. */ 00327 SPAN_DECLARE(void) t4_rx_set_x_resolution(t4_rx_state_t *s, int resolution); 00328 00329 /*! \brief Set the DCS information of the fax, for inclusion in the file. 00330 \param s The T.4 context. 00331 \param dcs The DCS information, formatted as an ASCII string. */ 00332 SPAN_DECLARE(void) t4_rx_set_dcs(t4_rx_state_t *s, const char *dcs); 00333 00334 /*! \brief Set the sub-address of the fax, for inclusion in the file. 00335 \param s The T.4 context. 00336 \param sub_address The sub-address string. */ 00337 SPAN_DECLARE(void) t4_rx_set_sub_address(t4_rx_state_t *s, const char *sub_address); 00338 00339 /*! \brief Set the identity of the remote machine, for inclusion in the file. 00340 \param s The T.4 context. 00341 \param ident The identity string. */ 00342 SPAN_DECLARE(void) t4_rx_set_far_ident(t4_rx_state_t *s, const char *ident); 00343 00344 /*! \brief Set the vendor of the remote machine, for inclusion in the file. 00345 \param s The T.4 context. 00346 \param vendor The vendor string, or NULL. */ 00347 SPAN_DECLARE(void) t4_rx_set_vendor(t4_rx_state_t *s, const char *vendor); 00348 00349 /*! \brief Set the model of the remote machine, for inclusion in the file. 00350 \param s The T.4 context. 00351 \param model The model string, or NULL. */ 00352 SPAN_DECLARE(void) t4_rx_set_model(t4_rx_state_t *s, const char *model); 00353 00354 /*! Get the current image transfer statistics. 00355 \brief Get the current transfer statistics. 00356 \param s The T.4 context. 00357 \param t A pointer to a statistics structure. */ 00358 SPAN_DECLARE(void) t4_rx_get_transfer_statistics(t4_rx_state_t *s, t4_stats_t *t); 00359 00360 /*! Get the short text name of an encoding format. 00361 \brief Get the short text name of an encoding format. 00362 \param encoding The encoding type. 00363 \return A pointer to the string. */ 00364 SPAN_DECLARE(const char *) t4_encoding_to_str(int encoding); 00365 00366 #if defined(__cplusplus) 00367 } 00368 #endif 00369 00370 #endif 00371 /*- End of file ------------------------------------------------------------*/
1.6.1