예제 #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
 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
 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
 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
 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
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