Exemplo n.º 1
0
def get_coordinates(symbol_version):
    """Given a symbol version number returns a list of alignment patterns
    center coordinates."""
    centers = get_centers(symbol_version)
    coordinates = [x for x in product(centers, centers)]
    coordinates = [x for x in coordinates if is_valid(x,
        qr_size(symbol_version))]
    return coordinates
Exemplo n.º 2
0
def get_coordinates(symbol_version):
    """Given a symbol version number returns a list of alignment patterns
    center coordinates."""
    centers = get_centers(symbol_version)
    coordinates = [x for x in product(centers, centers)]
    coordinates = [
        x for x in coordinates if is_valid(x, qr_size(symbol_version))
    ]
    return coordinates
Exemplo n.º 3
0
def place_data(code, symbol_array):
    """An alternative method for placement in the symbol, which yields the
    same result, is to regard the interleaved codeword sequence as a single
    bit stream, which is placed (starting with the most significant bit) in
    the two-module wide columns alternately upwards and downwards from the
    right to left of the symbol. In each column the bits are placed
    alternately in the right and left modules, moving upwards or downwards
    according to the direction of placement and skipping areas occupied by
    function patterns, changing direction at the top or bottom of the column.
    Each bit shall always be placed in the first available module position.
    """
    # Rotate the array 180 degrees so that data positioning start from
    # symbol_array[0][0]
    symbol_array = rot90(symbol_array, 2)
    flat_data_list = list("".join(list_to_bin(code.final_sequence))) + ([0] *
            symbol_version_data[code.symbol_version]['remainder_bits'])
    top = 0
    bottom = qr_size(code.symbol_version) - 1
    direction = 1
    left_column = 0
    row = 0
    column = 0
    while flat_data_list:
        # If we have reached top or bottom margins
        if direction == 1:
            if row > bottom:
                # reset row to bottom index
                row = bottom
                # shift by 2 columns
                left_column += 2
                column = left_column
                # invert direction
                direction *= -1
        else:
            if row < top:
                # reset row to top index
                row = top
                left_column += 2
                column = left_column
                direction *= -1

        try:
            if symbol_array[row][column] == 9:
                data = flat_data_list.pop(0)
                symbol_array[row][column] = data
        except IndexError:
            pass

        if column % 2 == 0:
            column += 1
        else:
            column = left_column
            row += 1 * direction

    # rotate back the symbol
    return rot90(symbol_array, 2)
Exemplo n.º 4
0
def place_data(code, symbol_array):
    """An alternative method for placement in the symbol, which yields the
    same result, is to regard the interleaved codeword sequence as a single
    bit stream, which is placed (starting with the most significant bit) in
    the two-module wide columns alternately upwards and downwards from the
    right to left of the symbol. In each column the bits are placed
    alternately in the right and left modules, moving upwards or downwards
    according to the direction of placement and skipping areas occupied by
    function patterns, changing direction at the top or bottom of the column.
    Each bit shall always be placed in the first available module position.
    """
    # Rotate the array 180 degrees so that data positioning start from
    # symbol_array[0][0]
    symbol_array = rot90(symbol_array, 2)
    flat_data_list = list("".join(list_to_bin(code.final_sequence))) + (
        [0] * symbol_version_data[code.symbol_version]['remainder_bits'])
    top = 0
    bottom = qr_size(code.symbol_version) - 1
    direction = 1
    left_column = 0
    row = 0
    column = 0
    while flat_data_list:
        # If we have reached top or bottom margins
        if direction == 1:
            if row > bottom:
                # reset row to bottom index
                row = bottom
                # shift by 2 columns
                left_column += 2
                column = left_column
                # invert direction
                direction *= -1
        else:
            if row < top:
                # reset row to top index
                row = top
                left_column += 2
                column = left_column
                direction *= -1

        try:
            if symbol_array[row][column] == 9:
                data = flat_data_list.pop(0)
                symbol_array[row][column] = data
        except IndexError:
            pass

        if column % 2 == 0:
            column += 1
        else:
            column = left_column
            row += 1 * direction

    # rotate back the symbol
    return rot90(symbol_array, 2)
Exemplo n.º 5
0
def position_detection_pattern(symbol_version):
    """Assign Position Detection Pattern bits and relative separators."""
    side_size = qr_size(symbol_version)

    arr = array([[9] * side_size] * side_size)
    arr[0] = arr[6] = [7] * 7 + [6] + [9] * (side_size - 16) + [6] + [7] * 7
    arr[1] = arr[5] = ([7, 6, 6, 6, 6, 6, 7, 6] + [9] * (side_size - 16) +
                       [6, 7, 6, 6, 6, 6, 6, 7])
    arr[2] = arr[3] = arr[4] = ([7, 6, 7, 7, 7, 6, 7, 6] + [9] *
                                (side_size - 16) + [6, 7, 6, 7, 7, 7, 6, 7])
    arr[7] = [6] * 8 + [9] * (side_size - 16) + [6] * 8

    arr[-8] = [6] * 8 + [9] * (side_size - 8)
    arr[-1] = arr[-7] = [7] * 7 + [6] + [9] * (side_size - 8)
    arr[-2] = arr[-6] = [7, 6, 6, 6, 6, 6, 7, 6] + [9] * (side_size - 8)
    arr[-3] = arr[-4] = arr[-5] = ([7, 6, 7, 7, 7, 6, 7, 6] + [9] *
                                   (side_size - 8))
    return arr
Exemplo n.º 6
0
def position_detection_pattern(symbol_version):
    """Assign Position Detection Pattern bits and relative separators."""
    side_size = qr_size(symbol_version)

    arr = array([[9] * side_size] * side_size)
    arr[0] = arr[6] = [7] * 7 + [6] + [9] * (side_size - 16) + [6] + [7] * 7
    arr[1] = arr[5] = ([7, 6, 6, 6, 6, 6, 7, 6] +
            [9] * (side_size - 16) +
            [6, 7, 6, 6, 6, 6, 6, 7])
    arr[2] = arr[3] = arr[4] = ([7, 6, 7, 7, 7, 6, 7, 6] +
            [9] * (side_size - 16) +
            [6, 7, 6, 7, 7, 7, 6, 7])
    arr[7] = [6] * 8 + [9] * (side_size - 16) + [6] * 8

    arr[-8] = [6] * 8 + [9] * (side_size - 8)
    arr[-1] = arr[-7] = [7] * 7 + [6] + [9] * (side_size - 8)
    arr[-2] = arr[-6] = [7, 6, 6, 6, 6, 6, 7, 6] + [9] * (side_size - 8)
    arr[-3] = arr[-4] = arr[-5] = ([7, 6, 7, 7, 7, 6, 7, 6] +
            [9] * (side_size - 8))
    return arr