Commit Graph

6 Commits

Author SHA1 Message Date
Jeff Epler f4e68e8fae
use mp_get_stream_raise, it's more specific 2021-11-20 08:53:04 -05:00
Jeff Epler e733876574 dither in x/y, not i/j
The easiest thing to implement was to use the i/j numbers, but they were not
directly related to image x/y coordinates.  This may slow things down a tiny
little bit, but it looks much better.
2021-10-27 16:52:56 -05:00
Jeff Epler ef4623dfae gifio: Add dithered output
It's not a great dither, but we're low on CPU time sooo
2021-10-27 10:54:31 -05:00
Jeff Epler dc00226143 gifio: write block data directly into output buffer 2021-10-27 09:38:07 -05:00
Jeff Epler 7d6ac96001 GifWriter: improve efficiency
* Increase colorspace conversion efficiency.
   This not only avoids a function call, it avoids the time-consuming
   switch statement in conver_pixel (replacing it with a single
   conditional on the byteswap flag + accounting for BGR/RGB during
   palette creation)

 * Buffer all the bytes of a single frame together.  By reducing
   low level write calls we get a decent speed increase even though
   it increases data-shuffling a bit.

Together with some other changes that enable "double buffered" camera
capture, this gets me to 8.8fps capturing QVGA (320x240) gifs and
11fps capturing 240x240 square gifs.
2021-10-26 11:11:28 -05:00
Jeff Epler c34b6f757f Implement gifio.GifWriter
This involves:
 * Adding a new "L8" colorspace for colorconverters
 * factoring out displayio_colorconverter_convert_pixel
 * Making a minimal "colorspace only" version of displayio for the
   unix port (testing purposes)
 * fixing an error message

I only tested writing B&W animated images, with the following script:
```python
import displayio
import gifio

with gifio.GifWriter("foo.gif", 64, 64, displayio.Colorspace.L8) as g:
    for i in range(0, 256, 14):
        data = bytes([i, 255-i] * 32 + [255-i, i] * 32) * 32
        print("add_frame")
        g.add_frame(data)

# expected to raise an error, buffer is not big enough
with gifio.GifWriter("/dev/null", 64, 64, displayio.Colorspace.L8) as g:
    g.add_frame(bytes([3,3,3]))
```
2021-10-26 08:54:18 -05:00