def __init__(self, width, height):
        self._width = width
        self._height = height

        self._bitmap = bitmap.Bitmap(self._width, self._height)
        self._icons = []
        self.selected = None
Beispiel #2
0
def getBM(bitmap_file):
    with open(bitmap_file, 'rb') as fh:
        bm = bitmap.Bitmap()
        bm.parse_file_header(fh)
        bm.parse_picture_header(fh)
        bm.parse_picture_data(fh)
    return bm
Beispiel #3
0
def display_image(display, convert_bmp='image.bmp'):
    import bitmap
    http_get('http://api.gerfficient.com/img/esp_image')
    if convert():
        Pin(2).low()
        display.draw_bitmap(bitmap.Bitmap(convert_bmp))
        os.remove('tmp')
        Pin(2).high()
    def __init__(self, ssd_display, width=None, height=None, top=0, left=0):
        self.ssd_display = ssd_display
        self.width = width if width is not None else ssd_display.cols
        self.height = height if height is not None else ssd_display.rows

        self._bitmap = bitmap.Bitmap(self.width, self.height)
        self.top = top
        self.left = left
        self._item = None
        self._items = []
Beispiel #5
0
def swapColors():
    args = parse_config()
    bitmap_file = args.bitmap_file
    with open(bitmap_file, 'rb') as fh:
        bm = bitmap.Bitmap()
        bm.parse_file_header(fh)
        bm.parse_picture_header(fh)
    bm.data.swapColors()
    with open("../swap.bmp", 'wb') as fh:
        bm.write(fh)
 def create_bitmap(self):
     image = util.text.image(self._text,
                             self._font_file,
                             self._font_size,
                             self._width,
                             self._height,
                             expand=True,
                             margin=self._margin)
     self._bitmap = bitmap.Bitmap(*image.size[:])
     self._bitmap.draw_image(image)
Beispiel #7
0
    def _FramesFromMp4(self, mp4_file):
        def GetDimensions(video):
            proc = subprocess.Popen(['avconv', '-i', video],
                                    stderr=subprocess.PIPE)
            dimensions = None
            output = ''
            for line in proc.stderr.readlines():
                output += line
                if 'Video:' in line:
                    dimensions = line.split(',')[2]
                    dimensions = map(int, dimensions.split()[0].split('x'))
                    break
            proc.communicate()
            assert dimensions, (
                'Failed to determine video dimensions. output=%s' % output)
            return dimensions

        def GetFrameTimestampMs(stderr):
            """Returns the frame timestamp in integer milliseconds from the dump log.

      The expected line format is:
      '  dts=1.715  pts=1.715\n'

      We have to be careful to only read a single timestamp per call to avoid
      deadlock because avconv interleaves its writes to stdout and stderr.
      """
            while True:
                line = ''
                next_char = ''
                while next_char != '\n':
                    next_char = stderr.read(1)
                    line += next_char
                if 'pts=' in line:
                    return int(1000 * float(line.split('=')[-1]))

        dimensions = GetDimensions(mp4_file)
        frame_length = dimensions[0] * dimensions[1] * 3
        frame_data = bytearray(frame_length)

        # Use rawvideo so that we don't need any external library to parse frames.
        proc = subprocess.Popen([
            'avconv', '-i', mp4_file, '-vcodec', 'rawvideo', '-pix_fmt',
            'rgb24', '-dump', '-loglevel', 'debug', '-f', 'rawvideo', '-'
        ],
                                stderr=subprocess.PIPE,
                                stdout=subprocess.PIPE)
        while True:
            num_read = proc.stdout.readinto(frame_data)
            if not num_read:
                raise StopIteration
            assert num_read == len(
                frame_data), 'Unexpected frame size: %d' % num_read
            yield (GetFrameTimestampMs(proc.stderr),
                   bitmap.Bitmap(3, dimensions[0], dimensions[1], frame_data))
Beispiel #8
0
    def __init__(self):
        self.bitmap_snake_1 = bitmap.Bitmap()
        self.bitmap_snake_2 = bitmap.Bitmap()
        self.player_1_port = ''
        self.player_2_port = ''
        self.dx, self.dy = 0, 1
        self.snake1_start_pos = _choose_random_pos()
        self.snake2_start_pos = _choose_random_pos()
        self.player_1_connected = False
        self.player_2_connected = False
        self.num_of_player = 0

        self.rows, self.cols = 32, 32
        self.snake_size = 20
        self.snake1 = single_snake.Snake(self.snake1_start_pos, self.rows,
                                         self.cols)
        self.snake2 = single_snake.Snake(self.snake2_start_pos, self.rows,
                                         self.cols)
        self.apple = _choose_random_pos()
        while self.apple == self.snake1_start_pos or self.apple == self.snake2_start_pos:
            self.apple = _choose_random_pos()

        self.game_over = False
Beispiel #9
0
    def __init__(self, ssd_display, item_list):
        self.ssd_display = ssd_display
        self.item_list = item_list

        self._bitmap = bitmap.Bitmap(ssd_display.cols, ssd_display.rows)
        self._items = []

        self.item_height = 16
        self.item_width = ssd_display.cols

        self.items_per_page = ssd_display.rows / self.item_height
        self.current_page = 0

        self.selected_index = 0
        self.page_start_index = 0

        # Create a new TextItem class that can be modified without affecting other menus
        self.TextItem = type('TextItem', TextItem.__bases__,
                             dict(TextItem.__dict__))
        self.TextItem.adjust_margin()
        self.TextItem.set_indent(5)

        self._create_items()
 def GetBitmap(self):
     return bitmap.Bitmap(pil=self.image)
Beispiel #11
0
 def __init__(self, size, functions):
     self.functions = functions
     self.bitset = bitmap.Bitmap(size)
    def __init__(self, width, height):
        self._width = width
        self._height = height

        self._bitmap = bitmap.Bitmap(self._width, self._height)
        self._percent = 0.0
Beispiel #13
0
def test_no_argument_constructor():
    bitmap.Bitmap()
Beispiel #14
0
 def test_bitmap_is_instantiable(self):
     bitmap.Bitmap('../data/mandel.bmp')
Beispiel #15
0
def bmp():
    return BMP(bitmap.Bitmap('../data/mandel.bmp'))
Beispiel #16
0
#!/usr/bin/env python

import bitmap

bmp = bitmap.Bitmap()
bmp.from_buf(open("boobs.bmp", "r").read())
print len(bmp.pixels)