35 | | """Returns True if data is ZjStream, else False.""" |
36 | | if self.firstblock[:4] == "ZJZJ" : |
37 | | self.logdebug("DEBUG: Input file is in the Zenographics ZjStream (little endian) format.") |
38 | | self.littleEndian() |
39 | | return True |
40 | | elif self.firstblock[:4] == "JZJZ" : |
41 | | self.logdebug("DEBUG: Input file is in the Zenographics ZjStream (big endian) format.") |
42 | | self.bigEndian() |
| 35 | """Returns True if data is LIDIL, else False.""" |
| 36 | # Beginning Of File marker is a Sync packet, followed with |
| 37 | # a Sync Complete packet followed with a Reset packet. |
| 38 | # We just look at the start of the Sync packet for simplicity's sake. |
| 39 | BOFMarker = "$\x01\x00\x00\x07" |
| 40 | # End Of File marker is a Sync Complete packet followed |
| 41 | # with a Reset packet. We ignore the preceding Sync packet |
| 42 | # for simplicity's sake. |
| 43 | EOFMarker = "$\x00\x10\x00\x08\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff$$\x00\x10\x00\x06\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff$" |
| 44 | if self.firstblock.startswith(BOFMarker) \ |
| 45 | and self.lastblock.endswith(EOFMarker) : |
| 46 | self.logdebug("DEBUG: Input file is in the Hewlett-Packard LIDIL format.") |
53 | | |
54 | | def bigEndian(self) : |
55 | | """Toggles to big endianness.""" |
56 | | self.unpackType = { 1 : "B", 2 : ">H", 4 : ">I" } |
57 | | self.unpackShort = self.unpackType[2] |
58 | | self.unpackLong = self.unpackType[4] |
59 | | return 0 |
60 | | |
61 | | def getJobSize(self) : |
62 | | """Computes the number of pages in a ZjStream document.""" |
63 | | infileno = self.infile.fileno() |
64 | | minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) |
65 | | pos = 4 |
66 | | startpagecount = endpagecount = 0 |
67 | | try : |
68 | | try : |
69 | | while 1 : |
70 | | header = minfile[pos:pos+16] |
71 | | if len(header) != 16 : |
72 | | break |
73 | | totalChunkSize = unpack(self.unpackLong, header[:4])[0] |
74 | | chunkType = unpack(self.unpackLong, header[4:8])[0] |
75 | | numberOfItems = unpack(self.unpackLong, header[8:12])[0] |
76 | | reserved = unpack(self.unpackShort, header[12:14])[0] |
77 | | signature = unpack(self.unpackShort, header[14:])[0] |
78 | | pos += totalChunkSize |
79 | | if chunkType == 0 : |
80 | | self.logdebug("startDoc") |
81 | | elif chunkType == 1 : |
82 | | self.logdebug("endDoc") |
83 | | elif chunkType == 2 : |
84 | | self.logdebug("startPage") |
85 | | startpagecount += 1 |
86 | | elif chunkType == 3 : |
87 | | self.logdebug("endPage") |
88 | | endpagecount += 1 |
89 | | |
90 | | #self.logdebug("Chunk size : %s" % totalChunkSize) |
91 | | #self.logdebug("Chunk type : 0x%08x" % chunkType) |
92 | | #self.logdebug("# items : %s" % numberOfItems) |
93 | | #self.logdebug("reserved : 0x%04x" % reserved) |
94 | | #self.logdebug("signature : 0x%04x" % signature) |
95 | | #self.logdebug("\n") |
96 | | except IndexError : # EOF ? |
97 | | pass |
98 | | finally : |
99 | | minfile.close() |
100 | | |
101 | | if startpagecount != endpagecount : |
102 | | sys.stderr.write("ERROR: Incorrect ZjStream datas.\n") |
103 | | return max(startpagecount, endpagecount) |
104 | | |
| 54 | |