Commit Graph

13 Commits

Author SHA1 Message Date
Jeff Epler 2556fce862 OnDiskBitmap: Fix memory corruption when using palette image
The number of palette entries set was accidentally 4x too much,
because the wrong looping variable was used.
2021-07-19 09:25:26 -05:00
Jeff Epler 9df8f235b1 OnDiskBitmap: INCOMPATIBLE CHANGE: Allow them to use palettes
Before, when an OnDiskBitmap was a paletted bitmap type, the palette
was internal to the OnDiskBitmap, and it internally performed the palette
conversion itself.  When using with a tilegrid, a ColorConverter() object
always had to be passed.

Now, an OnDiskBitmap has a "pixel_shader" property.  If the bitmap is
a paletted bitmap type, it is a (modifiable) Palette object.  Otherwise,
it is a ColorConverter() object as before. This allows palette effects
to be applied to paletted OnDiskBitmaps.

Code that used to say:
```python
face = displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter())
```
must be updated to say:
```python
face = displayio.TileGrid(odb, pixel_shader=odb.pixel_shader)
```

Compatible code for 6.x and 7.x can say
```python
face = displayio.TileGrid(odb, pixel_shader=getattr(odb, 'pixel_shader', ColorConverter())
```
2021-05-28 10:53:21 -05:00
microDev a52eb88031
run code formatting script 2021-03-15 19:27:36 +05:30
Jeff Epler f224ed1848 OnDiskBitmap: Correct handling of "0 color palette" images
Microsoft documentation says:

> If biCompression equals BI_RGB and the bitmap uses 8 bpp or less, the bitmap has a color table immediatelly following the BITMAPINFOHEADER structure. The color table consists of an array of RGBQUAD values. The size of the array is given by the biClrUsed member. If biClrUsed is zero, the array contains the maximum number of colors for the given bitdepth; that is, 2^biBitCount colors.

Formerly, we treated 0 colors as "no image palette" during construction,
but then during common_hal_displayio_ondiskbitmap_get_pixel indexed into
the palette anyway.  This could have unpredictable results.  On a pygamer,
it gave an image that was blue and black.  On magtag, it gave a crash.
2020-12-17 10:54:37 -06:00
Scott Shawcroft 72e7ffa324
More cleanup 2019-08-22 16:16:09 -07:00
Scott Shawcroft 70680d5b22
EPaper displays work mostly. 2019-08-22 14:08:33 -07:00
Scott Shawcroft c372567330
Fix off by one error in OnDiskBitmap
It resulted in the first row of pixels being pulled for out of bounds.

Fixes #1801
2019-04-17 15:17:11 -07:00
Bryan Siepert 76dc8e1ac8 fixed typo 2019-03-01 07:32:46 -08:00
Bryan Siepert 014595bff5 fixed whitespace, clarified variable name, and updated error messages 2019-03-01 07:17:50 -08:00
Bryan Siepert 398c7060f8 added monochrome, 8bpp indexed, and 32bpp ARGB BMPs 2019-02-28 23:08:12 -08:00
Bryan Siepert b81072e750 (fork rebuild) Initial support for 16bpp 555&565 and 8bpp grayscale bitmaps 2019-02-23 10:58:46 -08:00
Bryan Siepert ab2ad7ba45 adding height and width to OnDiskBitmap for #1460 2019-01-20 22:33:22 -08:00
Scott Shawcroft f21cf15c38
Add OnDiskBitmap which loads pixel data straight from disk.
Also, renamed Sprite's palette to pixel_shader so it can be
anything that produces colors based on values (including color values).
Added a ColorConverter that converts RGB888 (found in bitmaps) to
RGB565 for the display.

Fixes #1182
2018-09-12 15:25:59 -07:00