# API Documentation

digraph inheritance179f995d97 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "luma.core.device.device" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for display driver classes"]; "luma.core.mixin.capabilities" -> "luma.core.device.device" [arrowsize=0.5,style="setlinewidth(0.5)"]; "luma.core.device.dummy" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Pseudo-device that acts like a physical display, except that it does nothing"]; "luma.core.device.device" -> "luma.core.device.dummy" [arrowsize=0.5,style="setlinewidth(0.5)"]; "luma.core.device.linux_framebuffer" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Pseudo-device that acts like a physical display, except that it renders"]; "luma.core.device.device" -> "luma.core.device.linux_framebuffer" [arrowsize=0.5,style="setlinewidth(0.5)"]; "luma.core.device.parallel_device" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Wrapper class to manage communications with devices that can operate in"]; "luma.core.device.device" -> "luma.core.device.parallel_device" [arrowsize=0.5,style="setlinewidth(0.5)"]; "luma.core.mixin.capabilities" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="This class should be 'mixed-in' to any :py:class:`luma.core.device.device`"]; "luma.core.virtual.character" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Abstraction that wraps a device, this class provides a ``text`` property"]; "luma.core.virtual.history" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Wraps a device (or emulator) to provide a facility to be able to make a"]; "luma.core.mixin.capabilities" -> "luma.core.virtual.history" [arrowsize=0.5,style="setlinewidth(0.5)"]; "luma.core.virtual.hotspot" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="A hotspot (`a place of more than usual interest, activity, or popularity`)"]; "luma.core.mixin.capabilities" -> "luma.core.virtual.hotspot" [arrowsize=0.5,style="setlinewidth(0.5)"]; "luma.core.virtual.sevensegment" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Abstraction that wraps a device, this class provides a ``text`` property"]; "luma.core.virtual.snapshot" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="A snapshot is a `type of` hotspot, but only updates once in a given"]; "luma.core.virtual.hotspot" -> "luma.core.virtual.snapshot" [arrowsize=0.5,style="setlinewidth(0.5)"]; "luma.core.virtual.terminal" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Provides a terminal-like interface to a device (or a device-like object"]; "luma.core.virtual.viewport" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="The viewport offers a positionable window into a larger resolution pseudo-display,"]; "luma.core.mixin.capabilities" -> "luma.core.virtual.viewport" [arrowsize=0.5,style="setlinewidth(0.5)"]; "luma.emulator.device.asciiart" [URL="#luma.emulator.device.asciiart",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Pseudo-device that acts like a physical display, except that it converts the"]; "luma.emulator.device.emulator" -> "luma.emulator.device.asciiart" [arrowsize=0.5,style="setlinewidth(0.5)"]; "luma.emulator.device.asciiblock" [URL="#luma.emulator.device.asciiblock",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Pseudo-device that acts like a physical display, except that it converts"]; "luma.emulator.device.emulator" -> "luma.emulator.device.asciiblock" [arrowsize=0.5,style="setlinewidth(0.5)"]; "luma.emulator.device.capture" [URL="#luma.emulator.device.capture",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Pseudo-device that acts like a physical display, except that it writes the"]; "luma.emulator.device.emulator" -> "luma.emulator.device.capture" [arrowsize=0.5,style="setlinewidth(0.5)"]; "luma.emulator.device.emulator" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Base class for emulated display driver classes"]; "luma.core.device.device" -> "luma.emulator.device.emulator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "luma.emulator.device.gifanim" [URL="#luma.emulator.device.gifanim",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Pseudo-device that acts like a physical display, except that it collects"]; "luma.emulator.device.emulator" -> "luma.emulator.device.gifanim" [arrowsize=0.5,style="setlinewidth(0.5)"]; "luma.emulator.device.pygame" [URL="#luma.emulator.device.pygame",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Pseudo-device that acts like a physical display, except that it renders"]; "luma.emulator.device.emulator" -> "luma.emulator.device.pygame" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

## `luma.emulator.device`

class luma.emulator.device.asciiart(width=128, height=64, rotate=0, mode='RGB', transform='scale2x', scale=2, **kwargs)

  Bases: `luma.emulator.device.emulator`

  Pseudo-device that acts like a physical display, except that it converts the image to display into an ASCII-art representation and downscales colors to match the xterm-256 color scheme. Supports 24-bit color depth.

  This device takes hold of the terminal window (using curses), and any output for sysout and syserr is captured and stored, and is replayed when the cleanup method is called.

  Loosely based on https://github.com/ajalt/pyasciigen/blob/master/asciigen.py

  New in version 0.2.0.

  capabilities(width, height, rotate, mode='1')

    Assigns attributes such as `width`, `height`, `size` and `bounding_box` correctly oriented from the supplied parameters.

    Parameters

      - width (int) – The device width.

      - height (int) – The device height.

      - rotate (int) – An integer value of 0 (default), 1, 2 or 3 only, where 0 is no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3 represents 270° rotation.

      - mode (str) – The supported color model, one of `"1"`, `"RGB"` or `"RGBA"` only.

  cleanup()

    Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

    If `persist` is `True`, the device will not be switched off.

    This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

  clear()

    Initializes the device memory with an empty (blank) image.

  command(*cmd)

    Sends a command or sequence of commands through to the delegated serial interface.

  contrast(value)

    Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

    Parameters

      level (int) – Desired contrast level in the range of 0-255.

  data(data)

    Sends a data byte or sequence of data bytes through to the delegated serial interface.

  display(image)

    Takes a `PIL.Image` and renders it to the current terminal as ASCII-art.

  hide()

    Switches the display mode OFF, putting the device in low-power sleep mode.

  preprocess(image)

    Provides a preprocessing facility (which may be overridden) whereby the supplied image is rotated according to the device’s rotate capability. If this method is overridden, it is important to call the `super` method.

    Parameters

      image (PIL.Image.Image) – An image to pre-process.

    Returns

      A new processed image.

    Return type

      PIL.Image.Image

  show()

    Sets the display mode ON, waking the device out of a prior low-power sleep mode.

  to_surface(image, alpha=1.0)

    Converts a `PIL.Image` into a `pygame.Surface`, transforming it according to the `transform` and `scale` constructor arguments.

class luma.emulator.device.asciiblock(width=128, height=64, rotate=0, mode='RGB', transform='scale2x', scale=2, **kwargs)

  Bases: `luma.emulator.device.emulator`

  Pseudo-device that acts like a physical display, except that it converts the image pixels to display into colored ASCII half-blocks (ASCII code 220, ‘▄’), where the upper part background is used for one pixel, and the lower part foreground is used for the pixel on the next row. As most terminal display characters are in ratio 2:1, the half-block appears square.

  Inspired by Command Line Curiosities - Making the Terminal Sing by Hamza Haiken

  New in version 1.1.0.

  capabilities(width, height, rotate, mode='1')

    Assigns attributes such as `width`, `height`, `size` and `bounding_box` correctly oriented from the supplied parameters.

    Parameters

      - width (int) – The device width.

      - height (int) – The device height.

      - rotate (int) – An integer value of 0 (default), 1, 2 or 3 only, where 0 is no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3 represents 270° rotation.

      - mode (str) – The supported color model, one of `"1"`, `"RGB"` or `"RGBA"` only.

  cleanup()

    Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

    If `persist` is `True`, the device will not be switched off.

    This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

  clear()

    Initializes the device memory with an empty (blank) image.

  command(*cmd)

    Sends a command or sequence of commands through to the delegated serial interface.

  contrast(value)

    Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

    Parameters

      level (int) – Desired contrast level in the range of 0-255.

  data(data)

    Sends a data byte or sequence of data bytes through to the delegated serial interface.

  display(image)

    Takes a `PIL.Image` and renders it to the current terminal as ASCII-blocks.

  hide()

    Switches the display mode OFF, putting the device in low-power sleep mode.

  preprocess(image)

    Provides a preprocessing facility (which may be overridden) whereby the supplied image is rotated according to the device’s rotate capability. If this method is overridden, it is important to call the `super` method.

    Parameters

      image (PIL.Image.Image) – An image to pre-process.

    Returns

      A new processed image.

    Return type

      PIL.Image.Image

  show()

    Sets the display mode ON, waking the device out of a prior low-power sleep mode.

  to_surface(image, alpha=1.0)

    Converts a `PIL.Image` into a `pygame.Surface`, transforming it according to the `transform` and `scale` constructor arguments.

class luma.emulator.device.capture(width=128, height=64, rotate=0, mode='RGB', transform='scale2x', scale=2, file_template='luma_{0:06}.png', **kwargs)

  Bases: `luma.emulator.device.emulator`

  Pseudo-device that acts like a physical display, except that it writes the image to a numbered PNG file when the `display()` method is called. Supports 24-bit color depth.

  capabilities(width, height, rotate, mode='1')

    Assigns attributes such as `width`, `height`, `size` and `bounding_box` correctly oriented from the supplied parameters.

    Parameters

      - width (int) – The device width.

      - height (int) – The device height.

      - rotate (int) – An integer value of 0 (default), 1, 2 or 3 only, where 0 is no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3 represents 270° rotation.

      - mode (str) – The supported color model, one of `"1"`, `"RGB"` or `"RGBA"` only.

  cleanup()

    Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

    If `persist` is `True`, the device will not be switched off.

    This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

  clear()

    Initializes the device memory with an empty (blank) image.

  command(*cmd)

    Sends a command or sequence of commands through to the delegated serial interface.

  contrast(value)

    Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

    Parameters

      level (int) – Desired contrast level in the range of 0-255.

  data(data)

    Sends a data byte or sequence of data bytes through to the delegated serial interface.

  display(image)

    Takes a `PIL.Image` and dumps it to a numbered PNG file.

  hide()

    Switches the display mode OFF, putting the device in low-power sleep mode.

  preprocess(image)

    Provides a preprocessing facility (which may be overridden) whereby the supplied image is rotated according to the device’s rotate capability. If this method is overridden, it is important to call the `super` method.

    Parameters

      image (PIL.Image.Image) – An image to pre-process.

    Returns

      A new processed image.

    Return type

      PIL.Image.Image

  show()

    Sets the display mode ON, waking the device out of a prior low-power sleep mode.

  to_surface(image, alpha=1.0)

    Converts a `PIL.Image` into a `pygame.Surface`, transforming it according to the `transform` and `scale` constructor arguments.

class luma.emulator.device.gifanim(width=128, height=64, rotate=0, mode='RGB', transform='scale2x', scale=2, filename='luma_anim.gif', duration=0.01, loop=0, max_frames=None, **kwargs)

  Bases: `luma.emulator.device.emulator`

  Pseudo-device that acts like a physical display, except that it collects the images when the `display()` method is called, and on exit, assembles them into an animated GIF image. Supports 24-bit color depth, albeit with an indexed color palette.

  capabilities(width, height, rotate, mode='1')

    Assigns attributes such as `width`, `height`, `size` and `bounding_box` correctly oriented from the supplied parameters.

    Parameters

      - width (int) – The device width.

      - height (int) – The device height.

      - rotate (int) – An integer value of 0 (default), 1, 2 or 3 only, where 0 is no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3 represents 270° rotation.

      - mode (str) – The supported color model, one of `"1"`, `"RGB"` or `"RGBA"` only.

  cleanup()

    Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

    If `persist` is `True`, the device will not be switched off.

    This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

  clear()

    Initializes the device memory with an empty (blank) image.

  command(*cmd)

    Sends a command or sequence of commands through to the delegated serial interface.

  contrast(value)

    Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

    Parameters

      level (int) – Desired contrast level in the range of 0-255.

  data(data)

    Sends a data byte or sequence of data bytes through to the delegated serial interface.

  display(image)

    Takes an image, scales it according to the nominated transform, and stores it for later building into an animated GIF.

  hide()

    Switches the display mode OFF, putting the device in low-power sleep mode.

  preprocess(image)

    Provides a preprocessing facility (which may be overridden) whereby the supplied image is rotated according to the device’s rotate capability. If this method is overridden, it is important to call the `super` method.

    Parameters

      image (PIL.Image.Image) – An image to pre-process.

    Returns

      A new processed image.

    Return type

      PIL.Image.Image

  show()

    Sets the display mode ON, waking the device out of a prior low-power sleep mode.

  to_surface(image, alpha=1.0)

    Converts a `PIL.Image` into a `pygame.Surface`, transforming it according to the `transform` and `scale` constructor arguments.

  write_animation()

class luma.emulator.device.pygame(width=128, height=64, rotate=0, mode='RGB', transform='scale2x', scale=2, frame_rate=60, **kwargs)

  Bases: `luma.emulator.device.emulator`

  Pseudo-device that acts like a physical display, except that it renders to a displayed window. The frame rate is limited to 60FPS (much faster than a Raspberry Pi can achieve, but this can be overridden as necessary). Supports 24-bit color depth.

  `pygame` is used to render the emulated display window, and it’s event loop is checked to see if the ESC key was pressed or the window was dismissed: if so `sys.exit()` is called.

  capabilities(width, height, rotate, mode='1')

    Assigns attributes such as `width`, `height`, `size` and `bounding_box` correctly oriented from the supplied parameters.

    Parameters

      - width (int) – The device width.

      - height (int) – The device height.

      - rotate (int) – An integer value of 0 (default), 1, 2 or 3 only, where 0 is no rotation, 1 is rotate 90° clockwise, 2 is 180° rotation and 3 represents 270° rotation.

      - mode (str) – The supported color model, one of `"1"`, `"RGB"` or `"RGBA"` only.

  cleanup()

    Attempt to switch the device off or put into low power mode (this helps prolong the life of the device), clear the screen and close resources associated with the underlying serial interface.

    If `persist` is `True`, the device will not be switched off.

    This is a managed function, which is called when the python processs is being shutdown, so shouldn’t usually need be called directly in application code.

  clear()

    Initializes the device memory with an empty (blank) image.

  command(*cmd)

    Sends a command or sequence of commands through to the delegated serial interface.

  contrast(value)

    Switches the display contrast to the desired level, in the range 0-255. Note that setting the level to a low (or zero) value will not necessarily dim the display to nearly off. In other words, this method is NOT suitable for fade-in/out animation.

    Parameters

      level (int) – Desired contrast level in the range of 0-255.

  data(data)

    Sends a data byte or sequence of data bytes through to the delegated serial interface.

  display(image)

    Takes a `PIL.Image` and renders it to a pygame display surface.

  hide()

    Switches the display mode OFF, putting the device in low-power sleep mode.

  preprocess(image)

    Provides a preprocessing facility (which may be overridden) whereby the supplied image is rotated according to the device’s rotate capability. If this method is overridden, it is important to call the `super` method.

    Parameters

      image (PIL.Image.Image) – An image to pre-process.

    Returns

      A new processed image.

    Return type

      PIL.Image.Image

  show()

    Sets the display mode ON, waking the device out of a prior low-power sleep mode.

  to_surface(image, alpha=1.0)

    Converts a `PIL.Image` into a `pygame.Surface`, transforming it according to the `transform` and `scale` constructor arguments.

## `luma.emulator.render`

class luma.emulator.render.transformer(pygame, width, height, scale)

  Bases: `object`

  Helper class used to dispatch transformation operations.

  identity(surface)

    Fast scale operation that does not sample the results

  led_matrix(surface)

    Transforms the input surface into an LED matrix (1 pixel = 1 LED)

  none(surface)

    No-op transform - used when `scale` = 1

  scale2x(surface)

    Scales using the AdvanceMAME Scale2X algorithm which does a ‘jaggie-less’ scale of bitmap graphics.

  seven_segment(surface)
  smoothscale(surface)

    Smooth scaling using MMX or SSE extensions if available