def updateCmdForDeltaScanning(commandLine, Framework): originalScanFileFolderPath = CollectorsParameters.PROBE_MGR_INVENTORY_XMLENRICHER_FILES_FOLDER + XmlEnricherConstants.ORIGINAL_FOLDER_NAME originalScanFile = File(originalScanFileFolderPath, InventoryUtils.generateScanFileName(Framework)) if originalScanFile.exists(): scan = None try: try: buffer = jarray.zeros(0x24, 'b') fileSize = originalScanFile.length() if fileSize > 0x24: scan = RandomAccessFile(originalScanFile, "r") scan.readFully(buffer) if (buffer[0] == 0x1F) and ((buffer[1] & 0xFF) == 0x8B) and (buffer[2] == 0x08): scan.seek(fileSize - 8) scan.readFully(buffer, 0, 8) crc32 = getInt(buffer, 0) size = getInt(buffer, 4) deltaParams = ' -oldscanid:' + str(crc32) + ' -oldscansize:' + str(size) + ' ' index = String(commandLine).indexOf(ENTERPRISE_MODE) + String(ENTERPRISE_MODE).length() commandLine = commandLine[0:index] + deltaParams + commandLine[index + 1:] logger.debug('Scanner execution command updated to ', commandLine) except: logger.debugException("Failed to calculate CRC32 and size of zipped scan file " + originalScanFile.getAbsolutePath()) finally: if scan is not None: try: scan.close() except: pass return commandLine
def read2DImageROI(path, dimensions, interval, pixelType=UnsignedShortType, header=0, byte_order=ByteOrder.LITTLE_ENDIAN): """ Read a region of interest (the interval) of an image in a file. Assumes the image is written with the first dimension moving slowest. path: the file path to the image file. dimensions: a sequence of integer values e.g. [512, 512, 512] interval: two sequences of integer values defining the min and max coordinates, e.g. [[20, 0], [400, 550]] pixeltype: e.g. UnsignedShortType, FloatType header: defaults to zero, the number of bytes between the start of the file and the start of the image data. Supports only these types: UnsignedByteType, UnsignedShortType, FloatType. Returns an ArrayImg of the given type. """ ra = RandomAccessFile(path, 'r') try: width, height = dimensions minX, minY = interval[0] maxX, maxY = interval[1] roi_width, roi_height = maxX - minX + 1, maxY - minY + 1 tailX = width - roi_width - minX #print minX, minY #print maxX, maxY #print roi_width, roi_height size = roi_width * roi_height n_bytes_per_pixel = pixelType().getBitsPerPixel() / 8 #print n_bytes_per_pixel bytes = zeros(size * n_bytes_per_pixel, 'b') # Read only the 2D ROI ra.seek(header + (minY * width + minX) * n_bytes_per_pixel) for h in xrange(roi_height): ra.readFully(bytes, h * roi_width * n_bytes_per_pixel, roi_width * n_bytes_per_pixel) ra.skipBytes((tailX + minX) * n_bytes_per_pixel) # Make an image roiDims = [roi_width, roi_height] if UnsignedByteType == pixelType: return ArrayImgs.unsignedBytes(bytes, roiDims) if UnsignedShortType == pixelType: shorts = zeros(size, 'h') ByteBuffer.wrap(bytes).order(byte_order).asShortBuffer().get(shorts) return ArrayImgs.shorts(shorts, roiDims) if FloatType == pixelType: floats = zeros(size, 'f') ByteBuffer.wrap(bytes).order(byte_order).asFloatBuffer().get(floats) return ArrayImgs.floats(floats, roiDims) finally: ra.close()
def updateCmdForDeltaScanning(commandLine, Framework): originalScanFileFolderPath = CollectorsParameters.PROBE_MGR_INVENTORY_XMLENRICHER_FILES_FOLDER + XmlEnricherConstants.ORIGINAL_FOLDER_NAME originalScanFile = File(originalScanFileFolderPath, InventoryUtils.generateScanFileName(Framework)) if originalScanFile.exists(): scan = None try: try: buffer = jarray.zeros(0x24, 'b') fileSize = originalScanFile.length() if fileSize > 0x24: scan = RandomAccessFile(originalScanFile, "r") scan.readFully(buffer) if (buffer[0] == 0x1F) and ( (buffer[1] & 0xFF) == 0x8B) and (buffer[2] == 0x08): scan.seek(fileSize - 8) scan.readFully(buffer, 0, 8) crc32 = getInt(buffer, 0) size = getInt(buffer, 4) deltaParams = ' -oldscanid:' + str( crc32) + ' -oldscansize:' + str(size) + ' ' index = String(commandLine).indexOf( ENTERPRISE_MODE) + String( ENTERPRISE_MODE).length() commandLine = commandLine[ 0:index] + deltaParams + commandLine[index + 1:] logger.debug('Scanner execution command updated to ', commandLine) except: logger.debugException( "Failed to calculate CRC32 and size of zipped scan file " + originalScanFile.getAbsolutePath()) finally: if scan is not None: try: scan.close() except: pass return commandLine