Show
Ignore:
Timestamp:
07/02/05 11:23:23 (19 years ago)
Author:
jerome
Message:

Added basic support for the TIFF format (which can handle
multiple pages in the same file)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/pdlanalyzer/analyzer.py

    r216 r217  
    2323import tempfile 
    2424 
    25 from pdlanalyzer import version, pdlparser, postscript, pdf, pcl345, pclxl, escp2, dvi 
     25from pdlanalyzer import version, pdlparser, postscript, pdf, pcl345, pclxl, escp2, dvi, tiff 
    2626 
    2727KILOBYTE = 1024     
     
    5858            psyco.bind(pclxl.PCLXLParser.getJobSize) 
    5959            psyco.bind(dvi.DVIParser.getJobSize) 
     60            psyco.bind(tiff.TIFFParser.getJobSize) 
    6061         
    6162    def getJobSize(self) :     
     
    181182        if (ord(sdata[0]) == 0xf7) and (ord(edata[-1]) == 0xdf) : 
    182183            if self.debug :   
    183                 sys.stderr.write("%s is an DVI file\n" % str(self.filename)) 
     184                sys.stderr.write("%s is a DVI file\n" % str(self.filename)) 
     185            return 1 
     186        else :     
     187            return 0 
     188             
     189    def isTIFF(self, sdata, edata) :         
     190        """Returns 1 if data is TIFF, else 0.""" 
     191        littleendian = (chr(0x49)*2) + chr(0x2a) + chr(0) 
     192        bigendian = (chr(0x4d)*2) + chr(0) + chr(0x2a) 
     193        if sdata[:4] in (littleendian, bigendian) : 
     194            if self.debug :   
     195                sys.stderr.write("%s is a TIFF file\n" % str(self.filename)) 
    184196            return 1 
    185197        else :     
     
    200212            lastblock = "" 
    201213        self.infile.seek(0) 
    202         if self.isPostScript(firstblock, lastblock) : 
    203             return postscript.PostScriptParser 
    204         elif self.isPCLXL(firstblock, lastblock) :     
    205             return pclxl.PCLXLParser 
    206         elif self.isPDF(firstblock, lastblock) :     
    207             return pdf.PDFParser 
    208         elif self.isPCL(firstblock, lastblock) :     
    209             return pcl345.PCL345Parser 
    210         elif self.isESCP2(firstblock, lastblock) :     
    211             return escp2.ESCP2Parser 
    212         elif self.isDVI(firstblock, lastblock) :     
    213             return dvi.DVIParser 
    214         else :     
    215             raise pdlparser.PDLParserError, "Analysis of first data block failed." 
     214        if not firstblock : 
     215            sys.stderr.write("ERROR: input file %s is empty !\n" % str(self.filename)) 
     216        else :     
     217            if self.isPostScript(firstblock, lastblock) : 
     218                return postscript.PostScriptParser 
     219            elif self.isPCLXL(firstblock, lastblock) :     
     220                return pclxl.PCLXLParser 
     221            elif self.isPDF(firstblock, lastblock) :     
     222                return pdf.PDFParser 
     223            elif self.isPCL(firstblock, lastblock) :     
     224                return pcl345.PCL345Parser 
     225            elif self.isESCP2(firstblock, lastblock) :     
     226                return escp2.ESCP2Parser 
     227            elif self.isDVI(firstblock, lastblock) :     
     228                return dvi.DVIParser 
     229            elif self.isTIFF(firstblock, lastblock) : 
     230                return tiff.TIFFParser 
     231        raise pdlparser.PDLParserError, "Analysis of first data block failed." 
    216232             
    217233def main() :