| 74 | |
| 75 | def getInkCoverage(self, colorspace=None, resolution=None) : |
| 76 | """Extracts the percents of ink coverage from the input file.""" |
| 77 | result = None |
| 78 | cspace = colorspace or self.options.colorspace |
| 79 | res = resolution or self.options.resolution |
| 80 | if (not cspace) or (not res) : |
| 81 | raise ValueError, "Invalid colorspace (%s) or resolution (%s)" % (cspace, res) |
| 82 | self.openFile() |
| 83 | try : |
| 84 | pdlhandler = self.detectPDLHandler() |
| 85 | except pdlparser.PDLParserError, msg : |
| 86 | self.closeFile() |
| 87 | raise pdlparser.PDLParserError, "Unknown file format for %s (%s)" % (self.filename, msg) |
| 88 | else : |
| 89 | try : |
| 90 | tiffname = self.convertToTiffMultiPage24NC(pdlhandler) |
| 91 | result = inkcoverage.getInkCoverage(tiffname, cspace) |
| 92 | try : |
| 93 | os.remove(tiffname) |
| 94 | except OSError : |
| 95 | sys.stderr.write("Problem when trying to remove temporary file %s\n" % tiffname) |
| 96 | finally : |
| 97 | self.closeFile() |
| 98 | return result |
| 99 | |
| 100 | def convertToTiffMultiPage24NC(self, handler) : |
| 101 | """Converts the input file to TIFF format, X dpi, 24 bits per pixel, uncompressed. |
| 102 | Returns a temporary filename which names a file containing the TIFF datas. |
| 103 | The temporary file has to be deleted by the caller. |
| 104 | """ |
| 105 | self.infile.seek(0) |
| 106 | (handle, filename) = tempfile.mkstemp(".tmp", "pkpgcounter") |
| 107 | os.close(handle) |
| 108 | handler.convertToTiffMultiPage24NC(filename, self.options.resolution) |
| 109 | return filename |
182 | | cichoices=["bw", "cmyk", "cmy", "all"], |
183 | | help="Activate the computation of ink usage, and defines the colorspace to use. Supported values are 'BW', 'CMYK', 'CMY' and 'ALL'.") |
| 219 | cichoices=["bw", "rgb", "cmyk", "cmy"], |
| 220 | help="Activate the computation of ink usage, and defines the colorspace to use. Supported values are 'BW', 'RGB', 'CMYK', and 'CMY'.") |