00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * t4_tx.h - definitions for T.4 FAX transmit 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_TX_H_) 00029 #define _SPANDSP_T4_TX_H_ 00030 00031 /*! This function is a callback from the image decoders, to read the unencoded bi-level image, 00032 row by row. It is called for each row, with len set to the number of bytes per row expected. 00033 \return len for OK, or zero to indicate the end of the image data. */ 00034 typedef int (*t4_row_read_handler_t)(void *user_data, uint8_t buf[], size_t len); 00035 00036 /*! 00037 T.4 FAX compression/decompression descriptor. This defines the working state 00038 for a single instance of a T.4 FAX compression or decompression channel. 00039 */ 00040 typedef struct t4_tx_state_s t4_tx_state_t; 00041 00042 /* TIFF-FX related extensions to the TIFF tag set */ 00043 00044 /* 00045 Indexed(346) = 0, 1. SHORT 00046 0: not a palette-color image. 00047 1: palette-color image. 00048 This field is used to indicate that each sample value is an index 00049 into an array of color values specified in the image data stream. 00050 Because the color map is embedded in the image data stream, the 00051 ColorMap field is not used in Profile L. Lossless color fax 00052 profile supports palette-color images with the ITULAB encoding. 00053 The SamplesPerPixel value must be 1. 00054 00055 GlobalParametersIFD (400) IFD/LONG 00056 An IFD containing global parameters. It is recommended that a TIFF 00057 writer place this field in the first IFD, where a TIFF reader would 00058 find it quickly. 00059 00060 Each field in the GlobalParametersIFD is a TIFF field that is legal 00061 in any IFD. Required baseline fields should not be located in the 00062 GlobalParametersIFD, but should be in each image IFD. If a conflict 00063 exists between fields in the GlobalParametersIFD and in the image 00064 IFDs, then the data in the image IFD shall prevail. 00065 00066 Among the GlobalParametersIFD entries is a new ProfileType field 00067 which generally describes information in this IFD and in the TIFF 00068 file. 00069 00070 ProfileType(401) LONG 00071 The type of image data stored in this IFD. 00072 0 = Unspecified 00073 1 = Group 3 fax 00074 No default 00075 00076 The following new global fields are defined in this document as IFD 00077 entries for use with fax applications. 00078 00079 FaxProfile(402) = 0 - 6. BYTE 00080 The profile that applies to this file; a profile is subset of the 00081 full set of permitted fields and field values of TIFF for facsimile. 00082 The currently defined values are: 00083 0: does not conform to a profile defined for TIFF for facsimile 00084 1: minimal black & white lossless, Profile S 00085 2: extended black & white lossless, Profile F 00086 3: lossless JBIG black & white, Profile J 00087 4: lossy color and grayscale, Profile C 00088 5: lossless color and grayscale, Profile L 00089 6: Mixed Raster Content, Profile M 00090 00091 CodingMethods(403) LONG 00092 This field indicates which coding methods are used in the file. A 00093 bit value of 1 indicates which of the following coding methods is 00094 used: 00095 Bit 0: unspecified compression, 00096 Bit 1: 1-dimensional coding, ITU-T Rec. T.4 (MH - Modified Huffman), 00097 Bit 2: 2-dimensional coding, ITU-T Rec. T.4 (MR - Modified Read), 00098 Bit 3: 2-dimensional coding, ITU-T Rec. T.6 (MMR - Modified MR), 00099 Bit 4: ITU-T Rec. T.82 coding, using ITU-T Rec. T.85 (JBIG), 00100 Bit 5: ITU-T Rec. T.81 (Baseline JPEG), 00101 Bit 6: ITU-T Rec. T.82 coding, using ITU-T Rec. T.43 (JBIG color), 00102 Bits 7-31: reserved for future use 00103 Note: There is a limit of 32 compression types to identify standard 00104 compression methods. 00105 00106 VersionYear(404) BYTE 00107 Count: 4 00108 The year of the standard specified by the FaxProfile field, given as 00109 4 characters, e.g. '1997'; used in lossy and lossless color modes. 00110 00111 ModeNumber (405) BYTE 00112 The mode of the standard specified by the FaxProfile field. A 00113 value of 0 indicates Mode 1.0; used in Mixed Raster Content mode. 00114 00115 Decode(433) SRATIONAL 00116 Count = 2 * SamplesPerPixel 00117 Describes how to map image sample values into the range of values 00118 appropriate for the current color space. In general, the values 00119 are taken in pairs and specify the minimum and maximum output 00120 value for each color component. For the base color fax profile, 00121 Decode has a count of 6 values and maps the unsigned ITULAB- 00122 encoded sample values (Lsample, asample, bsample) to signed L*a*b* 00123 values, as follows: 00124 L* = Decode[0] + Lsample x (Decode[1]-Decode[0])/(2^n -1) 00125 a* = Decode[2] + asample x (Decode[3]-Decode[2])/(2^n -1) 00126 b* = Decode[4] + bsample x (Decode[5]-Decode[4])/(2^n -1) 00127 where Decode[0], Decode[2] and Decode[4] are the minimum values 00128 for L*, a*, and b*; Decode[1], Decode[3] and Decode[5] are the 00129 maximum values for L*, a*, and b*; and n is the BitsPerSample. 00130 When n=8,=20 L*=Decode[0] when Lsample=0 and L*=Decode[1] when 00131 Lsample=255. 00132 00133 ImageBaseColor(434) SHORT 00134 Count = SamplesPerPixel 00135 In areas of an image layer where no image data is available (i.e., 00136 where no strips are defined, or where the StripByteCounts entry for 00137 a given strip is 0), the color specified by ImageBaseColor will be 00138 used. 00139 00140 StripRowCounts(559) LONG 00141 Count = number of strips. 00142 The number of scanlines stored in a strip. Profile M allows each 00143 fax strip to store a different number of scanlines. For strips 00144 with more than one layer, the maximum strip size is either 256 00145 scanlines or full page size. The 256 maximum SHOULD be used 00146 unless the capability to receive longer strips has been 00147 negotiated. This field replaces RowsPerStrip for IFDs with 00148 variable-size strips. Only one of the two fields, StripRowCounts 00149 and RowsPerStrip, may be used in an IFD. 00150 00151 ImageLayer(34732) LONG 00152 Count = 2. 00153 Image layers are defined such that layer 1 is the Background 00154 layer, layer 3 is the Foreground layer, and layer 2 is the Mask 00155 layer, which selects pixels from the Background and Foreground 00156 layers. The ImageLayer tag contains two values, which describe 00157 the layer to which the image belongs and the order in which it is 00158 imaged. 00159 00160 ImageLayer[0] = 1, 2, 3. 00161 1: Image is a Background image, i.e. the image that will appear 00162 whenever the Mask contains a value of 0. Background images 00163 typically contain low-resolution, continuous-tone imagery. 00164 2: Image is the Mask layer. In MRC, if the Mask layer is present, 00165 it must be the Primary IFD and be full page in extent. 00166 3: Image is a Foreground image, i.e. the image that will appear 00167 whenever the Mask contains a value of 1. The Foreground image 00168 generally defines the color of text or lines but may also 00169 contain high-resolution imagery. 00170 00171 ImageLayer[1]: 00172 1: first image to be imaged in this layer 00173 2: second image to be imaged in this layer 00174 3: ... 00175 */ 00176 00177 /* Define the TIFF/FX tags to extend libtiff, when using a version of libtiff where this 00178 stuff has not been merged. */ 00179 #if defined(SPANDSP_SUPPORT_TIFF_FX) && !defined(TIFFTAG_FAXPROFILE) 00180 #define TIFFTAG_INDEXED 346 00181 #define TIFFTAG_GLOBALPARAMETERSIFD 400 00182 #define TIFFTAG_PROFILETYPE 401 00183 #define PROFILETYPE_UNSPECIFIED 0 00184 #define PROFILETYPE_G3_FAX 1 00185 #define TIFFTAG_FAXPROFILE 402 00186 #define FAXPROFILE_S 1 00187 #define FAXPROFILE_F 2 00188 #define FAXPROFILE_J 3 00189 #define FAXPROFILE_C 4 00190 #define FAXPROFILE_L 5 00191 #define FAXPROFILE_M 6 00192 #define TIFFTAG_CODINGMETHODS 403 00193 #define CODINGMETHODS_T4_1D (1 << 1) 00194 #define CODINGMETHODS_T4_2D (1 << 2) 00195 #define CODINGMETHODS_T6 (1 << 3) 00196 #define CODINGMETHODS_T85 (1 << 4) 00197 #define CODINGMETHODS_T42 (1 << 5) 00198 #define CODINGMETHODS_T43 (1 << 6) 00199 #define TIFFTAG_VERSIONYEAR 404 00200 #define TIFFTAG_MODENUMBER 405 00201 #define TIFFTAG_DECODE 433 00202 #define TIFFTAG_IMAGEBASECOLOR 434 00203 #define TIFFTAG_T82OPTIONS 435 00204 #define TIFFTAG_STRIPROWCOUNTS 559 00205 #define TIFFTAG_IMAGELAYER 34732 00206 00207 #define COMPRESSION_T85 9 00208 #define COMPRESSION_T43 10 00209 #endif 00210 00211 #if defined(__cplusplus) 00212 extern "C" { 00213 #endif 00214 00215 #if defined(SPANDSP_SUPPORT_TIFF_FX) 00216 /*! \brief Configure libtiff so it recognises the extended tag set for TIFF-FX. */ 00217 SPAN_DECLARE(void) TIFF_FX_init(void); 00218 #endif 00219 00220 /*! \brief Prepare for transmission of a document. 00221 \param s The T.4 context. 00222 \param file The name of the file to be sent. 00223 \param start_page The first page to send. -1 for no restriction. 00224 \param stop_page The last page to send. -1 for no restriction. 00225 \return A pointer to the context, or NULL if there was a problem. */ 00226 SPAN_DECLARE(t4_tx_state_t *) t4_tx_init(t4_tx_state_t *s, const char *file, int start_page, int stop_page); 00227 00228 /*! \brief Prepare to send the next page of the current document. 00229 \param s The T.4 context. 00230 \return zero for success, -1 for failure. */ 00231 SPAN_DECLARE(int) t4_tx_start_page(t4_tx_state_t *s); 00232 00233 /*! \brief Prepare the current page for a resend. 00234 \param s The T.4 context. 00235 \return zero for success, -1 for failure. */ 00236 SPAN_DECLARE(int) t4_tx_restart_page(t4_tx_state_t *s); 00237 00238 /*! \brief Check for the existance of the next page, and whether its format is like the 00239 current one. This information can be needed before it is determined that the current 00240 page is finished with. 00241 \param s The T.4 context. 00242 \return 0 for next page found with the same format as the current page. 00243 1 for next page found with different format from the current page. 00244 -1 for no page found, or file failure. */ 00245 SPAN_DECLARE(int) t4_tx_next_page_has_different_format(t4_tx_state_t *s); 00246 00247 /*! \brief Complete the sending of a page. 00248 \param s The T.4 context. 00249 \return zero for success, -1 for failure. */ 00250 SPAN_DECLARE(int) t4_tx_end_page(t4_tx_state_t *s); 00251 00252 /*! \brief Return the next bit of the current document page, without actually 00253 moving forward in the buffer. The document will be padded for the 00254 current minimum scan line time. 00255 \param s The T.4 context. 00256 \return 0 for more data to come. SIG_STATUS_END_OF_DATA for no more data. */ 00257 SPAN_DECLARE(int) t4_tx_image_complete(t4_tx_state_t *s); 00258 00259 /*! \brief Get the next bit of the current document page. The document will 00260 be padded for the current minimum scan line time. 00261 \param s The T.4 context. 00262 \return The next bit (i.e. 0 or 1). SIG_STATUS_END_OF_DATA for no more data. */ 00263 SPAN_DECLARE(int) t4_tx_get_bit(t4_tx_state_t *s); 00264 00265 /*! \brief Get the next chunk of the current document page. The document will 00266 be padded for the current minimum scan line time. 00267 \param s The T.4 context. 00268 \param buf The buffer into which the chunk is to written. 00269 \param max_len The maximum length of the chunk. 00270 \return The actual length of the chunk. If this is less than max_len it 00271 indicates that the end of the document has been reached. */ 00272 SPAN_DECLARE(int) t4_tx_get(t4_tx_state_t *s, uint8_t buf[], size_t max_len); 00273 00274 /*! \brief End the transmission of a document. Tidy up and close the file. 00275 This should be used to end T.4 transmission started with t4_tx_init. 00276 \param s The T.4 context. 00277 \return 0 for success, otherwise -1. */ 00278 SPAN_DECLARE(int) t4_tx_release(t4_tx_state_t *s); 00279 00280 /*! \brief End the transmission of a document. Tidy up, close the file and 00281 free the context. This should be used to end T.4 transmission 00282 started with t4_tx_init. 00283 \param s The T.4 context. 00284 \return 0 for success, otherwise -1. */ 00285 SPAN_DECLARE(int) t4_tx_free(t4_tx_state_t *s); 00286 00287 /*! \brief Set the encoding for the encoded data. 00288 \param s The T.4 context. 00289 \param encoding The encoding. 00290 \return 0 for success, otherwise -1. */ 00291 SPAN_DECLARE(int) t4_tx_set_tx_encoding(t4_tx_state_t *s, int encoding); 00292 00293 /*! \brief Set the minimum number of encoded bits per row. This allows the 00294 makes the encoding process to be set to comply with the minimum row 00295 time specified by a remote receiving machine. 00296 \param s The T.4 context. 00297 \param bits The minimum number of bits per row. */ 00298 SPAN_DECLARE(void) t4_tx_set_min_bits_per_row(t4_tx_state_t *s, int bits); 00299 00300 /*! \brief Set the width of the image. 00301 \param s The T.4 context. 00302 \param image_width The image width, in pixels. */ 00303 SPAN_DECLARE(void) t4_tx_set_image_width(t4_tx_state_t *s, int image_width); 00304 00305 /*! \brief Set the maximum number of 2D encoded rows between 1D encoded rows. This 00306 is only valid for T.4 2D encoding. 00307 \param s The T.4 context. 00308 \param max The maximum number of 2D rows. */ 00309 SPAN_DECLARE(void) t4_tx_set_max_2d_rows_per_1d_row(t4_tx_state_t *s, int max); 00310 00311 /*! \brief Set the identity of the local machine, for inclusion in page headers. 00312 \param s The T.4 context. 00313 \param ident The identity string. */ 00314 SPAN_DECLARE(void) t4_tx_set_local_ident(t4_tx_state_t *s, const char *ident); 00315 00316 /*! Set the info field, included in the header line included in each page of an encoded 00317 FAX. This is a string of up to 50 characters. Other information (date, local ident, etc.) 00318 are automatically included in the header. If the header info is set to NULL or a zero 00319 length string, no header lines will be added to the encoded FAX. 00320 \brief Set the header info. 00321 \param s The T.4 context. 00322 \param info A string, of up to 50 bytes, which will form the info field. */ 00323 SPAN_DECLARE(void) t4_tx_set_header_info(t4_tx_state_t *s, const char *info); 00324 00325 /*! Set the time zone for the time stamp in page header lines. If this function is not used 00326 the current time zone of the program's environment is used. 00327 \brief Set the header timezone. 00328 \param s The T.4 context. 00329 \param tz A time zone descriptor. */ 00330 SPAN_DECLARE(void) t4_tx_set_header_tz(t4_tx_state_t *s, tz_t *tz); 00331 00332 /*! Set page header extends or overlays the image mode. 00333 \brief Set page header overlay mode. 00334 \param s The T.4 context. 00335 \param header_overlays_image TRUE for overlay, or FALSE for extend the page. */ 00336 SPAN_DECLARE(void) t4_tx_set_header_overlays_image(t4_tx_state_t *s, int header_overlays_image); 00337 00338 /*! \brief Set the row read handler for a T.4 transmit context. 00339 \param s The T.4 transmit context. 00340 \param handler A pointer to the handler routine. 00341 \param user_data An opaque pointer passed to the handler routine. 00342 \return 0 for success, otherwise -1. */ 00343 SPAN_DECLARE(int) t4_tx_set_row_read_handler(t4_tx_state_t *s, t4_row_read_handler_t handler, void *user_data); 00344 00345 /*! \brief Set the row squashing ratio, for adjusting row-to-row (y) resolution of bi-level 00346 images for a T.4 transmit context. 00347 \param s The T.4 transmit context. 00348 \param row_squashing_ratio Vertical squashing ratio. */ 00349 SPAN_DECLARE(void) t4_tx_set_row_squashing_ratio(t4_tx_state_t *s, int row_squashing_ratio); 00350 00351 /*! \brief Get the row-to-row (y) resolution of the current page. 00352 \param s The T.4 context. 00353 \return The resolution, in pixels per metre. */ 00354 SPAN_DECLARE(int) t4_tx_get_y_resolution(t4_tx_state_t *s); 00355 00356 /*! \brief Get the column-to-column (x) resolution of the current page. 00357 \param s The T.4 context. 00358 \return The resolution, in pixels per metre. */ 00359 SPAN_DECLARE(int) t4_tx_get_x_resolution(t4_tx_state_t *s); 00360 00361 /*! \brief Get the width of the current page, in pixel columns. 00362 \param s The T.4 context. 00363 \return The number of columns. */ 00364 SPAN_DECLARE(int) t4_tx_get_image_width(t4_tx_state_t *s); 00365 00366 /*! \brief Get the number of pages in the file. 00367 \param s The T.4 context. 00368 \return The number of pages, or -1 if there is an error. */ 00369 SPAN_DECLARE(int) t4_tx_get_pages_in_file(t4_tx_state_t *s); 00370 00371 /*! \brief Get the currnet page number in the file. 00372 \param s The T.4 context. 00373 \return The page number, or -1 if there is an error. */ 00374 SPAN_DECLARE(int) t4_tx_get_current_page_in_file(t4_tx_state_t *s); 00375 00376 /*! Get the current image transfer statistics. 00377 \brief Get the current transfer statistics. 00378 \param s The T.4 context. 00379 \param t A pointer to a statistics structure. */ 00380 SPAN_DECLARE(void) t4_tx_get_transfer_statistics(t4_tx_state_t *s, t4_stats_t *t); 00381 00382 #if defined(__cplusplus) 00383 } 00384 #endif 00385 00386 #endif 00387 /*- End of file ------------------------------------------------------------*/
1.6.1