]> git.ipfire.org Git - thirdparty/HylaFAX.git/commitdiff
faxsend/faxgetty: SaveRawImage
authorAidan Van Dyk <aidan@ifax.com>
Mon, 28 Apr 2008 20:35:14 +0000 (20:35 +0000)
committerAidan Van Dyk <aidan@ifax.com>
Mon, 28 Apr 2008 20:35:14 +0000 (20:35 +0000)
Internal debugging config option from Lee:
| commit fd5fde78af93d32d3b0e8ebbd832da2b32214c4a
| Author: Lee Howard <faxguy@howardsilvan.com>
| Date:   Tue Oct 9 22:35:49 2007 +0000
|
|     This adds a new configuration option, SaveRawImage.  Which basically instructs
|     faxsend and faxgetty to save received or sent image data to file in /tmp/out.fax
|     or /tmp/in.fax, respectively.
|
|     As this is not something that will have a useful purpose as-is to the general
|     user I have left it undocumented... although that's probably very bad of me.

faxd/Class1.c++
faxd/Class1.h
faxd/Class1Send.c++
faxd/Class2.c++
faxd/Class2.h
faxd/Class2Send.c++
faxd/CopyQuality.c++
faxd/FaxModem.c++
faxd/FaxModem.h
faxd/ModemConfig.c++
faxd/ModemConfig.h

index a540d1004d7b9c151eb91fc5bb06a0c0cbbc5716..a2ffabe01d1fac1e54c33217d7ed3b624dead21f 100644 (file)
@@ -104,6 +104,7 @@ Class1Modem::Class1Modem(FaxServer& s, const ModemConfig& c)
     gotCTRL = false;
     repeatPhaseB = false;
     silenceHeard = false;
+    imagefd = 0;
 }
 
 Class1Modem::~Class1Modem()
index 0219221aeb5f35957ab8fec5032ff6f201de0b3b..e10ba90428ee202b7e94c83dd93c73f7bf733d0d 100644 (file)
@@ -92,6 +92,7 @@ protected:
     u_long     ecmStuffedBlockPos;     // fill pointer for ecmStuffedBlockPos
     u_int      frameNumber;            // frame sequence number of ecmFrame in ecmBlock
     u_short    blockNumber;            // block sequence number of ecmBlock in page
+    int                imagefd;                // file descriptor for raw image
 
     static const u_int modemPFMCodes[8];// map T.30 FCF to Class 2 PFM
     static const u_int modemPPMCodes[8];// map T.30 FCF to Class 2 PPM
index 5df875e42a7d91e605e6d297bc837d5422b2f877..20de4768129c3bcce54a8d8dbe11fdecebd8eea2 100644 (file)
@@ -1598,6 +1598,7 @@ Class1Modem::sendClass1ECMData(const u_char* data, u_int cc, const u_char* bitre
 bool
 Class1Modem::sendPageData(u_char* data, u_int cc, const u_char* bitrev, bool ecm, Status& eresult)
 {
+    if (imagefd > 0) Sys::write(imagefd, (const char*) data, cc);
     beginTimedTransfer();
     bool rc;
     if (ecm)
@@ -1845,6 +1846,10 @@ Class1Modem::sendPage(TIFF* tif, Class2Params& params, u_int pageChop, u_int ppm
        if (params.df <= DF_2DMMR && fillorder != FILLORDER_LSB2MSB) {
            TIFFReverseBits(dp, totdata);
        }
+
+       /* For debugging purposes we may want to write the image-data to file. */
+       if (conf.saverawimage) imagefd = Sys::open("/tmp/out.fax", O_RDWR|O_CREAT|O_EXCL);
+
        u_int minLen = params.minScanlineSize();
        if (minLen > 0) {                       // only in non-ECM
            /*
@@ -1927,8 +1932,9 @@ Class1Modem::sendPage(TIFF* tif, Class2Params& params, u_int pageChop, u_int ppm
            /*
             * Flush anything that was not sent above.
             */
-           if (fp > fill && rc)
+           if (fp > fill && rc) {
                rc = sendPageData(fill, fp-fill, bitrev, (params.ec != EC_DISABLE), eresult);
+           }
            delete fill;
        } else {
            /*
@@ -1937,6 +1943,10 @@ Class1Modem::sendPage(TIFF* tif, Class2Params& params, u_int pageChop, u_int ppm
            rc = sendPageData(dp, (u_int) totdata, bitrev, (params.ec != EC_DISABLE), eresult);
        }
        delete data;
+       if (imagefd > 0) {
+           Sys::close(imagefd);
+           imagefd = 0;
+       }
     }
     if (rc || abortRequested())
        rc = sendRTC(params, ppmcmd, rowsperstrip, eresult);
index bbe1740f772b95194b3c674879514c2a9fcdf6a2..fdb9a9f8359670a8a0463548518add4ec7058090 100644 (file)
@@ -34,6 +34,7 @@ Class2Modem::Class2Modem(FaxServer& s, const ModemConfig& c) : FaxModem(s,c)
     serviceType = 0;                   // must be set in derived class
     useExtendedDF = false;             // T.32 Amendment 1 extension for data format is detectable
     useJP = false;                     // JP +FCC option support is detectable
+    imagefd = 0;
 }
 
 Class2Modem::~Class2Modem()
index d6f3da9c0424bbf1ee6d78b29ed112f707974e44..b338a77d1f8ac6e8ece08da5bc648d3016edac0e 100644 (file)
@@ -72,6 +72,7 @@ protected:
     char       hangupCode[5];          // hangup reason (from modem)
     bool       hadHangup;              // true if +FHNG:/+FHS: received
     fxStr      lid;                    // prepared local identifier string
+    int                imagefd;                // file descriptor for raw image data
 
 // modem setup stuff
     virtual bool setupModem(bool isSend = true);
index 490fd645b51a953a99dbfa8985a6781598e52731..a074355320773912feaec9503bb347f903092a6e 100644 (file)
@@ -24,6 +24,7 @@
  * OF THIS SOFTWARE.
  */
 #include <stdio.h>
+#include "Sys.h"
 #include "Class2.h"
 #include "ModemConfig.h"
 #include "FaxRequest.h"
@@ -415,6 +416,9 @@ Class2Modem::sendPageData(TIFF* tif, u_int pageChop)
 {
     bool rc = true;
 
+    /* For debugging purposes we may want to write the image-data to file. */
+    if (conf.saverawimage) imagefd = Sys::open("/tmp/out.fax", O_RDWR|O_CREAT|O_EXCL);
+
     tstrip_t nstrips = TIFFNumberOfStrips(tif);
     if (nstrips > 0) {
 
@@ -508,11 +512,16 @@ Class2Modem::sendPageData(TIFF* tif, u_int pageChop)
            TIFFReverseBits(dp, totdata);
        }
 
+       if (imagefd > 0) Sys::write(imagefd, (const char*) dp, (u_int) totdata);
        beginTimedTransfer();
        rc = putModemDLEData(dp, (u_int) totdata, bitrev, getDataTimeout(), conf.doPhaseCDebug);
        endTimedTransfer();
        protoTrace("SENT %u bytes of data", totdata);
     }
+    if (imagefd > 0) {
+       Sys::close(imagefd);
+       imagefd = 0;
+    }
     return (rc);
 }
 
index 0e6b7fb498e51867fe450d828771f1ce3f82e905..72eccc30296a7a74a6b71ed0bcc49a142909b26d 100644 (file)
@@ -126,6 +126,9 @@ bool
 FaxModem::recvPageDLEData(TIFF* tif, bool checkQuality,
     const Class2Params& params, Status& eresult)
 {
+    /* For debugging purposes we may want to write the image-data to file. */
+    if (conf.saverawimage) imagefd = Sys::open("/tmp/in.fax", O_RDWR|O_CREAT|O_EXCL);
+
     initializeDecoder(params);
     u_int rowpixels = params.pageWidth();      // NB: assume rowpixels <= 4864
     /*
@@ -412,6 +415,7 @@ FaxModem::recvPageDLEData(TIFF* tif, bool checkQuality,
                if (params.df == DF_JBIG) clearSDNORMCount();
                else fixupJPEG(tif);
            }
+           if (imagefd > 0) Sys::close(imagefd);
            recvEndPage(tif, params);
            return (true);
        }
@@ -460,6 +464,7 @@ FaxModem::recvPageDLEData(TIFF* tif, bool checkQuality,
            recvEOLCount = getRTCRow();
        }
     }
+    if (imagefd > 0) Sys::close(imagefd);
     recvEndPage(tif, params);
     return (true);
 }
@@ -549,6 +554,7 @@ setupCompression(TIFF* tif, u_int df, u_int jp, uint32 opts)
 void
 FaxModem::flushEncodedData(TIFF* tif, tstrip_t strip, const u_char* buf, u_int cc)
 {
+    if (imagefd > 0) Sys::write(imagefd, (const char*) buf, cc);
     // NB: must update ImageLength for each new strip
     TIFFSetField(tif, TIFFTAG_IMAGELENGTH, recvEOLCount);
     if (TIFFWriteEncodedStrip(tif, strip, (tdata_t)buf, cc) == -1)
@@ -561,6 +567,7 @@ FaxModem::flushEncodedData(TIFF* tif, tstrip_t strip, const u_char* buf, u_int c
 void
 FaxModem::flushRawData(TIFF* tif, tstrip_t strip, const u_char* buf, u_int cc)
 {
+    if (imagefd > 0) Sys::write(imagefd, (const char*) buf, cc);
     recvTrace("%u bytes of data, %lu total lines", cc, recvEOLCount);
     if (TIFFWriteRawStrip(tif, strip, (tdata_t)buf, cc) == -1)
        serverTrace("RECV: %s: write error", TIFFFileName(tif));
index 2cad1e78540c284cbf91314d876a73c3e117cf76..cc5c6e86ff1fa9cf679549e3d152745f521b9601 100644 (file)
@@ -41,6 +41,7 @@ FaxModem::FaxModem(FaxServer& s, const ModemConfig& c)
     minsp = BR_2400;
     curreq = NULL;
     group3opts = 0;
+    imagefd = 0;
     // fill order settings may be overwritten in derived class
     recvFillOrder = (conf.recvFillOrder != 0)? conf.recvFillOrder : FILLORDER_LSB2MSB;
     sendFillOrder = (conf.sendFillOrder != 0)? conf.sendFillOrder : FILLORDER_LSB2MSB;
index 17c9e1d2dc75b672a0499dfa77ddc65ee0f95829..25dcfa62e98e7ab6e00ea1f3238ccd9a9d391c09 100644 (file)
@@ -88,6 +88,7 @@ private:
     pid_t      decoderPid;     // process id for the decoding process
     u_char     parserBuf[16];  // buffer used for parsing JBIG and JPEG
     u_long     parserCount[3]; // counters used in parsing JBIG and JPEG
+    int                imagefd;        // file descriptor for image file
 
     void       flushEncodedData(TIFF*, tstrip_t, const u_char*, u_int);
     void       flushRawData(TIFF*, tstrip_t, const u_char*, u_int);
index 9a7da397b4c1fac636b02ec4aa3177c738f9d2c6..4ddd186817692cb9e61c6eb7bb956d6db31cb155 100644 (file)
@@ -291,6 +291,7 @@ ModemConfig::setupConfig()
     softRTFCC          = true;                 // real-time fax comp. conv. (software)
     doPhaseCDebug      = false;                // query modem for responses in Phase C transmit
     noAnswerVoice      = false;                // answer voice calls
+    saverawimage       = false;                // don't save raw image data by default
 
     idConfig.resize(0);
     callidIndex                = (u_int) -1;
@@ -801,6 +802,8 @@ ModemConfig::setConfigItem(const char* tag, const char* value)
        class2RTFCC = getBoolean(value);
     else if (streq(tag, "noanswervoice"))
        noAnswerVoice = getBoolean(value);
+    else if (streq(tag, "saverawimage"))
+       saverawimage = getBoolean(value);
     else if (streq(tag, "modemsoftrtfcc"))
        softRTFCC = getBoolean(value);
     else if (streq(tag, "modemdophasecdebug"))
index 516f1add3ce4317e5ea01278769c802d32f89fe8..c6bc77c80a05d321f2640541b56789b6c182c572 100644 (file)
@@ -128,6 +128,7 @@ public:
     fxStr      dringOn;                // pattern for distinctive ring silence interval
     fxStr      dringOff;               // pattern for distinctive ring ring interval
     bool       noAnswerVoice;          // leave voice calls unanswered
+    bool       saverawimage;           // debugging feature to save raw image data
                                        // call identification
     IDConfArray        idConfig;               // pattern for ID info
                                        // protocol timers