コード例 #1
0
def floatable(mem_addr: bitstring.BitArray, mask: bitstring.BitArray):
    amount_of_trues = mask.count(True)
    for possible_setting in range(2**amount_of_trues):
        possible_setting = get_bitsstring(possible_setting)
        possible_setting_index = -1
        for index in mask.findall([1]):
            mem_addr[index] = possible_setting[possible_setting_index]
            possible_setting_index -= 1
        yield mem_addr
コード例 #2
0
 def testByteAligned(self):
     bitstring.bytealigned = True
     a = BitArray("0x00 ff 0f f")
     l = list(a.findall("0xff"))
     self.assertEqual(l, [8])
     p = a.find("0x0f")[0]
     self.assertEqual(p, 16)
     p = a.rfind("0xff")[0]
     self.assertEqual(p, 8)
     s = list(a.split("0xff"))
     self.assertEqual(s, ["0x00", "0xff0ff"])
     a.replace("0xff", "")
     self.assertEqual(a, "0x000ff")
コード例 #3
0
ファイル: test_bitarray.py プロジェクト: arnaudMDM/divers
 def testByteAligned(self):
     bitstring.bytealigned = True
     a = BitArray('0x00 ff 0f f')
     l = list(a.findall('0xff'))
     self.assertEqual(l, [8])
     p = a.find('0x0f')[0]
     self.assertEqual(p, 16)
     p = a.rfind('0xff')[0]
     self.assertEqual(p, 8)
     s = list(a.split('0xff'))
     self.assertEqual(s, ['0x00', '0xff0ff'])
     a.replace('0xff', '')
     self.assertEqual(a, '0x000ff')
コード例 #4
0
ファイル: test_bitarray.py プロジェクト: flynnsark/bitstring
 def testByteAligned(self):
     bitstring.settings.bytealigned = True
     a = BitArray('0x00 ff 0f f')
     l = list(a.findall('0xff'))
     self.assertEqual(l, [8])
     p = a.find('0x0f')[0]
     self.assertEqual(p, 16)
     p = a.rfind('0xff')[0]
     self.assertEqual(p, 8)
     s = list(a.split('0xff'))
     self.assertEqual(s, ['0x00', '0xff0ff'])
     a.replace('0xff', '')
     self.assertEqual(a, '0x000ff')
コード例 #5
0
ファイル: test_bitarray.py プロジェクト: nssllc/carver
 def testNotByteAligned(self):
     bitstring.bytealigned = False
     a = BitArray('0x00 ff 0f f')
     l = list(a.findall('0xff'))
     self.assertEqual(l, [8, 20])
     p = a.find('0x0f')[0]
     self.assertEqual(p, 4)
     p = a.rfind('0xff')[0]
     self.assertEqual(p, 20)
     s = list(a.split('0xff'))
     self.assertEqual(s, ['0x00', '0xff0', '0xff'])
     a.replace('0xff', '')
     self.assertEqual(a, '0x000')
コード例 #6
0
 def testNotByteAligned(self):
     bitstring.settings.bytealigned = False
     a = BitArray('0x00 ff 0f f')
     l = list(a.findall('0xff'))
     self.assertEqual(l, [8, 20])
     p = a.find('0x0f')[0]
     self.assertEqual(p, 4)
     p = a.rfind('0xff')[0]
     self.assertEqual(p, 20)
     s = list(a.split('0xff'))
     self.assertEqual(s, ['0x00', '0xff0', '0xff'])
     a.replace('0xff', '')
     self.assertEqual(a, '0x000')
コード例 #7
0
def parse_tables(imageFile):
    """
    Grab all quantization tables from jpg header
    :param imageFile: string containing jpg image filename
    :return: list of lists of unsorted quantization tables
    """

    # if not (os.path.splitext(imageFile.lower())[1][1:] not in ['jpeg','jpg','tiff','tif'] ):
    #   return []

    # open the image and scan for q table marker "FF DB"
    s = open(imageFile, 'rb')
    b = BitArray(s)
    ffdb = b.findall('0xffdb', bytealigned=True)

    # grab the tables, based on format
    tables = []
    for start in ffdb:
        subset = b[start + 5 * 8:start + 134 * 8]
        check = subset.find('0xff', bytealigned=True)
        if check:
            subsubset = subset[0:check[0]]
            tables.append(subsubset)
        else:
            tables.append(subset[0:64 * 8])
            tables.append(subset[65 * 8:])

    # concatenate the tables, and convert them from bitarray to list
    finalTable = []
    for table in tables:
        tempTable = []

        bi = table.bin
        for i in xrange(0, len(bi), 8):
            byte = bi[i:i + 8]
            val = int(byte, 2)
            tempTable.append(val)
        finalTable.append(tempTable)
    s.close()
    return finalTable
コード例 #8
0
ファイル: compress_as.py プロジェクト: anddrrw/maskgen
def parse_tables(imageFile):
    """
    Grab all quantization tables from jpg header
    :param imageFile: string containing jpg image filename
    :return: list of lists of unsorted quantization tables
    """

    # open the image and scan for q table marker "FF DB"
    s = open(imageFile, 'rb')
    b = BitArray(s)
    ffdb = b.findall('0xffdb', bytealigned=True)

    # grab the tables, based on format
    tables = []
    for start in ffdb:
        subset = b[start + 5 * 8:start + 134 * 8]
        check = subset.find('0xff', bytealigned=True)
        if check:
            subsubset = subset[0:check[0]]
            tables.append(subsubset)
        else:
            tables.append(subset[0:64 * 8])
            tables.append(subset[65 * 8:])

    # concatenate the tables, and convert them from bitarray to list
    finalTable = []
    for table in tables:
        tempTable = []

        bi = table.bin
        for i in xrange(0, len(bi), 8):
            byte = bi[i:i + 8]
            val = int(byte, 2)
            tempTable.append(val)
        finalTable.append(tempTable)
    s.close()
    return finalTable