Changeset 479 for pkpgcounter

Show
Ignore:
Timestamp:
09/30/07 11:22:07 (17 years ago)
Author:
jerome
Message:

The PCLXL parser now should correctly handle Canon ImageRunner? tags.
Needs more testing since testsuite was very very small (a single file).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/pkpgpdls/pclxl.py

    r478 r479  
    9595    def beginPage(self, nextpos) : 
    9696        """Indicates the beginning of a new page, and extracts media information.""" 
     97        # self.logdebug("BeginPage at %x" % nextpos) 
    9798        self.pagecount += 1 
    9899         
     
    181182    def endPage(self, nextpos) :     
    182183        """Indicates the end of a page.""" 
     184        # self.logdebug("EndPage at %x" % nextpos) 
    183185        pos3 = nextpos - 3 
    184186        minfile = self.minfile 
     
    199201        """Changes the color space.""" 
    200202        if self.minfile[nextpos-4:nextpos-1] == self.RGBColorSpace : # TODO : doesn't seem to handle all cases ! 
    201             self.iscolor = 1 
     203            self.iscolor = True 
    202204        return 0 
    203205             
     
    224226         
    225227    def array_32(self, nextpos) : 
    226         """Handles 32 bits arrays.""" 
    227         return self.array_Generic(nextpos, 4) 
     228        """Handles 32 bits arrays and Canon ImageRunner tags.""" 
     229        minfile = self.minfile 
     230        irtag = minfile[nextpos-1:nextpos+3] 
     231        if irtag in (self.imagerunnermarker1, self.imagerunnermarker2) : 
     232            # This is the beginning of a Canon ImageRunner tag 
     233            # self.logdebug("Canon ImageRunner tag at %x" % (nextpos-1)) 
     234            codop = minfile[nextpos+1:nextpos+3] 
     235            length = unpack(">H", minfile[nextpos+7:nextpos+9])[0] 
     236            # self.logdebug("Canon ImageRunner block length=%04x" % length) 
     237            toskip = 19 
     238            if irtag != self.imagerunnermarker2 : 
     239                toskip += length 
     240            # self.logdebug("Canon ImageRunner skip until %x" % (nextpos+toskip)) 
     241            return toskip     
     242        else : 
     243            # This is a normal PCLXL array 
     244            return self.array_Generic(nextpos, 4) 
    228245         
    229246    def embeddedDataSmall(self, nextpos) : 
     
    234251        """Handle normal amounts of data.""" 
    235252        return 4 + unpack(self.unpackLong, self.minfile[nextpos:nextpos+4])[0] 
     253         
     254    def skipHPPCLXL(self, nextpos) :     
     255        """Skip the 'HP-PCL XL' statement if needed.""" 
     256        minfile = self.minfile 
     257        if nextpos and (minfile[nextpos:nextpos+11] == " HP-PCL XL;") : 
     258            pos = nextpos 
     259            while minfile[pos] != '\n' : 
     260                pos += 1 
     261            length = (pos - nextpos + 1)     
     262            # self.logdebug("Skip HP PCLXL statement until %x" % (nextpos + length))   
     263            return length 
     264        else :     
     265            return 0 
    236266         
    237267    def littleEndian(self, nextpos) : 
     
    240270        self.unpackShort = self.unpackType[2] 
    241271        self.unpackLong = self.unpackType[4] 
    242         return 0 
     272        # self.logdebug("LittleEndian at %x" % (nextpos - 1)) 
     273        return self.skipHPPCLXL(nextpos) 
    243274         
    244275    def bigEndian(self, nextpos) : 
     
    247278        self.unpackShort = self.unpackType[2] 
    248279        self.unpackLong = self.unpackType[4] 
    249         return 0 
     280        # self.logdebug("BigEndian at %x" % (nextpos - 1)) 
     281        return self.skipHPPCLXL(nextpos) 
    250282     
    251283    def reservedForFutureUse(self, nextpos) : 
     
    335367           xl_refsup30r089.pdf 
    336368        """ 
    337         self.iscolor = None 
     369         
     370        infileno = self.infile.fileno() 
     371        self.minfile = minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) 
     372         
     373        self.iscolor = False 
     374         
    338375        found = False 
    339376        while not found : 
     
    349386                elif endian == 0x28 :     
    350387                    self.bigEndian(0) 
    351                 # elif endian == 0x27 : # TODO : This is the ESC code : parse it for PJL statements ! 
     388                # elif endian == 0x27 : # TODO : This is the ASCII binding code : what does it do exactly ? 
    352389                #  
    353390                else :     
     
    446483        self.tags[0xcb] = self.array_16 # sint16_array 
    447484        self.tags[0xcc] = self.array_32 # sint32_array 
    448         self.tags[0xcd] = self.array_32 # real32_array 
     485        self.tags[0xcd] = self.array_32 # real32_array and unfortunately Canon ImageRunner 
    449486         
    450487        self.tags[0xce] = self.reservedForFutureUse # reserved 
     
    525562                             } 
    526563                              
    527         infileno = self.infile.fileno() 
     564        # Markers for Canon ImageRunner printers 
     565        self.imagerunnermarker1 = chr(0xcd) + chr(0xca) + chr(0x10) + chr(0x00) 
     566        self.imagerunnermarker2 = chr(0xcd) + chr(0xca) + chr(0x10) + chr(0x02) 
     567                              
    528568        self.pages = { 0 : { "copies" : 1,  
    529569                             "orientation" : "Default",  
     
    534574                           }  
    535575                     }       
    536         self.minfile = minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) 
    537576        tags = self.tags 
    538577        self.pagecount = 0