Did I find the right examples for you? yes no Crawl my project Python Jobs
All Samples(4) | Call(2) | Derive(0) | Import(2)
Makes the conversion between bytes and numbers, depending on the number of bits used per component. @param bytes: String representing the bytes to be converted @param bitsPerComponent: Number of bits needed to represent a component @return: A tuple (status,statusContent), where statusContent is a list of numbers in case status = 0 or an error in case status = -1
def getNumsFromBytes(bytes, bitsPerComponent = 8): ''' Makes the conversion between bytes and numbers, depending on the number of bits used per component. @param bytes: String representing the bytes to be converted @param bitsPerComponent: Number of bits needed to represent a component @return: A tuple (status,statusContent), where statusContent is a list of numbers in case status = 0 or an error in case status = -1 ''' if not isinstance(bytes,str): return (-1,'bytes must be a string') if not isinstance(bitsPerComponent,int): return (-1,'bitsPerComponent must be an integer') outputComponents = [] bitsStream = '' for byte in bytes: try: bitsRepresentation = bin(ord(byte)) bitsRepresentation = bitsRepresentation.replace('0b','') bitsRepresentation = '0'*(8-len(bitsRepresentation)) + bitsRepresentation bitsStream += bitsRepresentation except: return (-1,'Error in conversion from bytes to bits') try: for i in range(0,len(bitsStream),bitsPerComponent): bytes = '' bits = bitsStream[i:i+bitsPerComponent] num = int(bits,2) outputComponents.append(num) except: return (-1,'Error in conversion from bits to bytes') return (0,outputComponents)
import sys, zlib, lzw, struct from PDFUtils import getNumsFromBytes, getBytesFromBits, getBitsFromNum from ccitt import CCITTFax
for rowIndex in range(numRows): row = decodedStream[rowIndex*bytesPerRow:rowIndex*bytesPerRow+bytesPerRow] ret,colorNums = getNumsFromBytes(row, bits) if ret == -1: return (ret,colorNums)
src/c/l/classyPDF-HEAD/peepdf_classy/PDFFilters.py classyPDF(Download)
import sys, zlib, lzw, struct from PDFUtils import getNumsFromBytes, getBytesFromBits, getBitsFromNum def decodeStream(stream, filter, parameters = {}):
for rowIndex in range(numRows): row = decodedStream[rowIndex*bytesPerRow:rowIndex*bytesPerRow+bytesPerRow] ret,colorNums = getNumsFromBytes(row, bits) if ret == -1: return (ret,colorNums)