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