2323`adafruit_framebuf`
2424====================================================
2525
26- CircuitPython frambuf module, based on the Python frambuf module.
26+ CircuitPython pure-python framebuf module, based on the micropython framebuf module.
2727
2828* Author(s): Kattni Rembor, Tony DiCola, original file created by Damien P. George
2929
5050MVLSB = 0 # Single bit displays (like SSD1306 OLED)
5151RGB565 = 1 # 16-bit color displays
5252GS4_HMSB = 2 # Unimplemented!
53+ MHMSB = 3 # Single bit displays like the Sharp Memory
54+
55+ class MHMSBFormat :
56+ """MHMSBFormat"""
57+ @staticmethod
58+ def set_pixel (framebuf , x , y , color ):
59+ """Set a given pixel to a color."""
60+ index = (y * framebuf .stride + x ) // 8
61+ offset = 7 - x & 0x07
62+ framebuf .buf [index ] = (framebuf .buf [index ] & ~ (0x01 << offset )) | ((color != 0 ) << offset )
63+
64+ @staticmethod
65+ def get_pixel (framebuf , x , y ):
66+ """Get the color of a given pixel"""
67+ index = (y * framebuf .stride + x ) // 8
68+ offset = 7 - x & 0x07
69+ return (framebuf .buf [index ] >> offset ) & 0x01
70+
71+ @staticmethod
72+ def fill_rect (framebuf , x , y , width , height , color ):
73+ """Draw a rectangle at the given location, size and color. The ``fill_rect`` method draws
74+ both the outline and interior."""
75+ # pylint: disable=too-many-arguments
76+ for _x in range (x , x + width ):
77+ offset = 7 - _x & 0x07
78+ for _y in range (y , y + height ):
79+ index = (_y * framebuf .stride + _x ) // 8
80+ framebuf .buf [index ] = (framebuf .buf [index ] & ~ (0x01 << offset )) \
81+ | ((color != 0 ) << offset )
5382
5483class MVLSBFormat :
5584 """MVLSBFormat"""
@@ -140,6 +169,8 @@ def __init__(self, buf, width, height, buf_format=MVLSB, stride=None):
140169 self .stride = width
141170 if buf_format == MVLSB :
142171 self .format = MVLSBFormat ()
172+ elif buf_format == MHMSB :
173+ self .format = MHMSBFormat ()
143174 elif buf_format == RGB565 :
144175 self .format = RGB565Format ()
145176 else :
@@ -209,13 +240,13 @@ def line(self, x_0, y_0, x_1, y_1, color):
209240 else :
210241 err = d_y / 2.0
211242 while y != y_1 :
212- self .pixel (x , y , 1 )
243+ self .pixel (x , y , color )
213244 err -= d_x
214245 if err < 0 :
215246 x += s_x
216247 err += d_y
217248 y += s_y
218- self .pixel (x , y , 1 )
249+ self .pixel (x , y , color )
219250
220251 def blit (self ):
221252 """blit is not yet implemented"""
@@ -227,11 +258,7 @@ def scroll(self):
227258
228259 def text (self , string , x , y , color , * ,
229260 font_name = "font5x8.bin" ):
230- """Write an ascii string to location (x, y) as the bottom left corner,
231- in a given color, in left-to-right fashion.
232- Does not handle text wrapping. You can also pass in a font_name, but
233- this has to be generated as a special binary format and placed in the
234- working directory of the main script (so, probably /)"""
261+ """text is not yet implemented"""
235262 if not self ._font or self ._font .font_name != font_name :
236263 # load the font!
237264 self ._font = BitmapFont ()
0 commit comments