Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for rendering of bitmaps and raw color images to display.TFT #205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nickovs
Copy link

@nickovs nickovs commented Aug 29, 2018

This PR adds two new methods to the display.TFT class to support direct rendering of bitmaps and raw 24-bit colour images. Use cases for the 1 bpp images include direct rendering of fonts created using font-to-py that are stored in ROM or displaying QR codes; 1 bpp images can be scaled, clipped and draw either solid or transparent. Direct rendering of 24 bpp images can be useful for displaying sensor data from array sensors (such as low-res thermal imagers) or allow faster display of more complex colour patterns.

The method signatures for the two methods are:

tft.rawImage(x, y, width, height, buffer)

and:

tft.drawBitmap(x, y, width, height, buffer, color=None, bgcolor=None, transparent=False, topbitfirst=False, scale=1)

In both cases x and y are the coordinates of the top,left corner of the image, width and height are the dimensions of the image and buffer is an object that supports the memory buffer protocol (including bytes, bytearray and memoryview objects, among others). In the case of the rawImage() method the buffer object should contain 3*width*weight bytes representing tuples of (r,g,b) bytes organised in lines proceeding left to right, the lines ordered top to bottom. For the drawBitmap() method the buffer object is made up of rows of bits, padded to a whole number of bytes, organised left to right, the lines ordered top to bottom. If the topbitfirst flag is set then the most significant bit of each byte is draw on the left and any padding is in the less significant bits, otherwise the least significant bit is draw on the left and padding is in the more significant bits. The bits that are set are draw in the color specified by the color parameter if it is set or else the current foreground color. Bits that are zero are draw in the color given in bgcolor if it is set or else the current background color, unless the transparent flag is set in which case they are not draw at all. If an integer is give for the scale parameter then the image is scaled up by this value in both horizontal and vertical directions. If the value is a tuple of two items then these are taken as (x_scale, y_scale).

@loboris
Copy link
Owner

loboris commented Sep 1, 2018

Thank you, I'll test the PR and add it to the tft module.
Drawing bitmaps from file could probably also be useful (for big images, especially if no psRAM is used).

@nickovs
Copy link
Author

nickovs commented Sep 1, 2018

Thanks for the reply. Rendering uncompressed images from file without having to load the whole file would certainly be useful, especially for things like splash images. I'll have a look at doing that as a separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants