Exemplo n.º 1
0
def test_seven_segment():
    with open(get_reference_image("seven_segment.png"), "rb") as fp:
        ref = Image.open(fp)
        chars = [
            # Alphabet with omissions
            0x00, 0x01, 0x08, 0x02, 0x7e, 0x30, 0x6d, 0x79, 0x33, 0x5b, 0x5f,
            0x70, 0x7f, 0x7b, 0x7d, 0x1f, 0x0d, 0x3d, 0x6f, 0x47, 0x7b, 0x17,
            0x10, 0x18, 0x06, 0x15, 0x1d, 0x67, 0x73, 0x05, 0x5b, 0x0f, 0x1c,
            0x1c, 0x3b, 0x6d, 0x77, 0x7f, 0x4e, 0x7e, 0x4f, 0x47, 0x5e, 0x37,
            0x30, 0x38, 0x0e, 0x76, 0x7e, 0x67, 0x73, 0x46, 0x5b, 0x0f, 0x3e,
            0x3e, 0x3b, 0x6d, 0x80, 0x80
        ]
        device = dummy(width=len(chars), height=8)
        with canvas(device) as draw:
            for x in range(len(chars)):
                val = chars[x]
                for y in range(8):
                    mask = 1 << y
                    if val & mask != 0:
                        draw.point((device.width - x, y), fill="white")
        surface = to_pygame_surface(device.image)
        tf = transformer(pygame, device.width, device.height, 16)
        im = to_pillow_img(tf.seven_segment(surface))
        bbox = ImageChops.difference(ref, im).getbbox()
        assert bbox is None
Exemplo n.º 2
0
def test_identity():
    with open(get_reference_image("identity.png"), "rb") as fp:
        ref = Image.open(fp)
        surface = baseline_im()
        tf = transformer(pygame, 128, 64, 2)
        im = to_pillow_img(tf.identity(surface))
        bbox = ImageChops.difference(ref, im).getbbox()
        assert bbox is None
Exemplo n.º 3
0
def test_led_matrix():
    with open(get_reference_image("led_matrix.png"), "rb") as fp:
        ref = Image.open(fp)
        device = dummy(width=40, height=24)
        with canvas(device) as draw:
            draw.rectangle(device.bounding_box, outline="white")
            draw.text((5, 2), "Hello", fill="white")
            draw.text((5, 10), "World", fill="white")
        surface = to_pygame_surface(device.image)
        tf = transformer(pygame, device.width, device.height, 16)
        im = to_pillow_img(tf.led_matrix(surface))
        bbox = ImageChops.difference(ref, im).getbbox()
        assert bbox is None
Exemplo n.º 4
0
 def __init__(self, width, height, rotate, mode, transform, scale):
     super(emulator, self).__init__(serial_interface=noop())
     try:
         import pygame
     except ImportError:
         raise RuntimeError("Emulator requires pygame to be installed")
     self._pygame = pygame
     self.capabilities(width, height, rotate, mode)
     self.scale = 1 if transform == "none" else scale
     self._transform = getattr(transformer(pygame, width, height, scale),
                               "none" if scale == 1 else transform)
     self._contrast = 1.0
     self._last_image = None
     self.segment_mapper = regular