Beispiel #1
0
    def map_data(self, data, mask_pattern):
        inc = -1
        row = self.modules_count - 1
        bitIndex = 7
        byteIndex = 0
        mask_func = util.mask_func(mask_pattern)
        data_len = len(data)
        for col in six.moves.xrange(self.modules_count - 1, 0, -2):
            if col <= 6:
                col -= 1
            col_range = (col, col-1)

            while True:
                for c in col_range:
                    if self.modules[row][c] is None:

                        dark = False
                        if byteIndex < data_len:
                            dark = (((data[byteIndex] >> bitIndex) & 1) == 1)
                        if mask_func(row, c):
                            dark = not dark
                        self.modules[row][c] = dark
                        bitIndex -= 1
                        if bitIndex == -1:
                            byteIndex += 1
                            bitIndex = 7
                row += inc
                if row < 0 or self.modules_count <= row:
                    row -= inc
                    inc = -inc
                    break
Beispiel #2
0
    def map_data(self, data, mask_pattern):
        inc = -1
        row = self.modules_count - 1
        bitIndex = 7
        byteIndex = 0

        mask_func = util.mask_func(mask_pattern)

        data_len = len(data)

        for col in six.moves.xrange(self.modules_count - 1, 0, -2):

            if col <= 6:
                col -= 1

            col_range = (col, col-1)

            while True:

                for c in col_range:

                    if self.modules[row][c] is None:

                        dark = False

                        if byteIndex < data_len:
                            dark = (((data[byteIndex] >> bitIndex) & 1) == 1)

                        if mask_func(row, c):
                            dark = not dark

                        self.modules[row][c] = dark
                        bitIndex -= 1

                        if bitIndex == -1:
                            byteIndex += 1
                            bitIndex = 7

                row += inc

                if row < 0 or self.modules_count <= row:
                    row -= inc
                    inc = -inc
                    break
Beispiel #3
0
    def map_data(self, data, mask_pattern):
        inc = -1
        row = self.modules_count - 1
        bitIndex = 7
        byteIndex = 0

        mask_func = util.mask_func(mask_pattern)

        for col in range(self.modules_count - 1, -1, -2):

            if col == 6:
                col -= 1

            while True:

                for c in range(2):

                    # Note that col - c looks like a dangerous range (col could
                    # be 0, causing lookup of -1). However, this isn't possible
                    # because self.modules_count is always odd so the last
                    # range item will always be 1.
                    if self.modules[row][col - c] is None:

                        dark = False

                        if byteIndex < len(data):
                            dark = (((data[byteIndex] >> bitIndex) & 1) == 1)

                        if mask_func(row, col - c):
                            dark = not dark

                        self.modules[row][col - c] = dark
                        bitIndex -= 1

                        if bitIndex == -1:
                            byteIndex += 1
                            bitIndex = 7

                row += inc

                if row < 0 or self.modules_count <= row:
                    row -= inc
                    inc = -inc
                    break
Beispiel #4
0
    def map_data(self, data, mask_pattern, use_colors=True):
        inc = -1
        row = self.modules_count - 1
        bit_index = 0
        false_color, true_color = self.get_false_and_true_colors('padding', use_colors)

        mask_func = util.mask_func(mask_pattern)

        for col in six.moves.xrange(self.modules_count - 1, 0, -2):

            if col <= 6:
                col -= 1

            col_range = (col, col-1)

            while row >= 0 and self.modules_count > row:
                for c in col_range:
                    if self.modules[row][c] is None:
                        if bit_index < len(data):
                            bit = data[bit_index]
                            value = bit[0]
                            color = bit[1]
                        else:
                            value = False
                            color = true_color

                        if mask_func(row, c):
                            value = not value

                        if use_colors:
                            if value:
                                self.modules[row][c] = color
                            else:
                                self.modules[row][c] = false_color
                        else:
                            self.modules[row][c] = value

                        bit_index += 1

                row += inc
            row -= inc
            inc = -inc
Beispiel #5
0
    def map_data(self, data, mask_pattern):
        inc = -1
        row = self.modules_count - 1
        bitIndex = 7
        byteIndex = 0

        mask_func = util.mask_func(mask_pattern)

        for col in range(self.modules_count - 1, 0, -2):

            if col == 6:
                col -= 1

            while True:

                for c in range(2):

                    if self.modules[row][col - c] == None:

                        dark = False

                        if byteIndex < len(data):
                            dark = (((data[byteIndex] >> bitIndex) & 1) == 1)

                        if mask_func(row, col - c):
                            dark = not dark

                        self.modules[row][col - c] = dark
                        bitIndex -= 1

                        if bitIndex == -1:
                            byteIndex += 1
                            bitIndex = 7

                row += inc

                if row < 0 or self.modules_count <= row:
                    row -= inc
                    inc = -inc
                    break
Beispiel #6
0
    def map_data(self, data, mask_pattern):
        inc = -1
        row = self.modules_count - 1
        bitIndex = 7
        byteIndex = 0

        mask_func = util.mask_func(mask_pattern)

        for col in range(self.modules_count - 1, 0, -2):

            if col == 6:
                col -= 1

            while True:

                for c in range(2):

                    if self.modules[row][col - c] == None:

                        dark = False

                        if byteIndex < len(data):
                            dark = (((data[byteIndex] >> bitIndex) & 1) == 1)

                        if mask_func(row, col - c):
                            dark = not dark

                        self.modules[row][col - c] = dark
                        bitIndex -= 1

                        if bitIndex == -1:
                            byteIndex += 1
                            bitIndex = 7

                row += inc

                if row < 0 or self.modules_count <= row:
                    row -= inc
                    inc = -inc
                    break