summaryrefslogtreecommitdiff
path: root/extmod/modframebuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'extmod/modframebuf.c')
-rw-r--r--extmod/modframebuf.c70
1 files changed, 38 insertions, 32 deletions
diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c
index 07a50a2f4..ce280090f 100644
--- a/extmod/modframebuf.c
+++ b/extmod/modframebuf.c
@@ -22,8 +22,8 @@ typedef struct _mp_obj_framebuf_t {
uint8_t format;
} mp_obj_framebuf_t;
-typedef void (*setpixel_t)(const mp_obj_framebuf_t*, int, int, uint32_t);
-typedef uint32_t (*getpixel_t)(const mp_obj_framebuf_t*, int, int);
+typedef void (*setpixel_t)(const mp_obj_framebuf_t *, int, int, uint32_t);
+typedef uint32_t (*getpixel_t)(const mp_obj_framebuf_t *, int, int);
typedef void (*fill_rect_t)(const mp_obj_framebuf_t *, int, int, int, int, uint32_t);
typedef struct _mp_framebuf_p_t {
@@ -47,20 +47,20 @@ typedef struct _mp_framebuf_p_t {
STATIC void mono_horiz_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
size_t index = (x + y * fb->stride) >> 3;
int offset = fb->format == FRAMEBUF_MHMSB ? x & 0x07 : 7 - (x & 0x07);
- ((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
+ ((uint8_t *)fb->buf)[index] = (((uint8_t *)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
}
STATIC uint32_t mono_horiz_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
size_t index = (x + y * fb->stride) >> 3;
int offset = fb->format == FRAMEBUF_MHMSB ? x & 0x07 : 7 - (x & 0x07);
- return (((uint8_t*)fb->buf)[index] >> (offset)) & 0x01;
+ return (((uint8_t *)fb->buf)[index] >> (offset)) & 0x01;
}
STATIC void mono_horiz_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
int reverse = fb->format == FRAMEBUF_MHMSB;
int advance = fb->stride >> 3;
while (w--) {
- uint8_t *b = &((uint8_t*)fb->buf)[(x >> 3) + y * advance];
+ uint8_t *b = &((uint8_t *)fb->buf)[(x >> 3) + y * advance];
int offset = reverse ? x & 7 : 7 - (x & 7);
for (int hh = h; hh; --hh) {
*b = (*b & ~(0x01 << offset)) | ((col != 0) << offset);
@@ -75,16 +75,16 @@ STATIC void mono_horiz_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int
STATIC void mvlsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
size_t index = (y >> 3) * fb->stride + x;
uint8_t offset = y & 0x07;
- ((uint8_t*)fb->buf)[index] = (((uint8_t*)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
+ ((uint8_t *)fb->buf)[index] = (((uint8_t *)fb->buf)[index] & ~(0x01 << offset)) | ((col != 0) << offset);
}
STATIC uint32_t mvlsb_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
- return (((uint8_t*)fb->buf)[(y >> 3) * fb->stride + x] >> (y & 0x07)) & 0x01;
+ return (((uint8_t *)fb->buf)[(y >> 3) * fb->stride + x] >> (y & 0x07)) & 0x01;
}
STATIC void mvlsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
while (h--) {
- uint8_t *b = &((uint8_t*)fb->buf)[(y >> 3) * fb->stride + x];
+ uint8_t *b = &((uint8_t *)fb->buf)[(y >> 3) * fb->stride + x];
uint8_t offset = y & 0x07;
for (int ww = w; ww; --ww) {
*b = (*b & ~(0x01 << offset)) | ((col != 0) << offset);
@@ -97,15 +97,15 @@ STATIC void mvlsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, in
// Functions for RGB565 format
STATIC void rgb565_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
- ((uint16_t*)fb->buf)[x + y * fb->stride] = col;
+ ((uint16_t *)fb->buf)[x + y * fb->stride] = col;
}
STATIC uint32_t rgb565_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
- return ((uint16_t*)fb->buf)[x + y * fb->stride];
+ return ((uint16_t *)fb->buf)[x + y * fb->stride];
}
STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
- uint16_t *b = &((uint16_t*)fb->buf)[x + y * fb->stride];
+ uint16_t *b = &((uint16_t *)fb->buf)[x + y * fb->stride];
while (h--) {
for (int ww = w; ww; --ww) {
*b++ = col;
@@ -117,7 +117,7 @@ STATIC void rgb565_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, i
// Functions for GS2_HMSB format
STATIC void gs2_hmsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
- uint8_t *pixel = &((uint8_t*)fb->buf)[(x + y * fb->stride) >> 2];
+ uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride) >> 2];
uint8_t shift = (x & 0x3) << 1;
uint8_t mask = 0x3 << shift;
uint8_t color = (col & 0x3) << shift;
@@ -125,14 +125,14 @@ STATIC void gs2_hmsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_
}
STATIC uint32_t gs2_hmsb_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
- uint8_t pixel = ((uint8_t*)fb->buf)[(x + y * fb->stride) >> 2];
+ uint8_t pixel = ((uint8_t *)fb->buf)[(x + y * fb->stride) >> 2];
uint8_t shift = (x & 0x3) << 1;
return (pixel >> shift) & 0x3;
}
STATIC void gs2_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
- for (int xx=x; xx < x+w; xx++) {
- for (int yy=y; yy < y+h; yy++) {
+ for (int xx = x; xx < x + w; xx++) {
+ for (int yy = y; yy < y + h; yy++) {
gs2_hmsb_setpixel(fb, xx, yy, col);
}
}
@@ -141,7 +141,7 @@ STATIC void gs2_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w,
// Functions for GS4_HMSB format
STATIC void gs4_hmsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
- uint8_t *pixel = &((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1];
+ uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1];
if (x % 2) {
*pixel = ((uint8_t)col & 0x0f) | (*pixel & 0xf0);
@@ -152,15 +152,15 @@ STATIC void gs4_hmsb_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_
STATIC uint32_t gs4_hmsb_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
if (x % 2) {
- return ((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1] & 0x0f;
+ return ((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1] & 0x0f;
}
- return ((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1] >> 4;
+ return ((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1] >> 4;
}
STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
col &= 0x0f;
- uint8_t *pixel_pair = &((uint8_t*)fb->buf)[(x + y * fb->stride) >> 1];
+ uint8_t *pixel_pair = &((uint8_t *)fb->buf)[(x + y * fb->stride) >> 1];
uint8_t col_shifted_left = col << 4;
uint8_t col_pixel_pair = col_shifted_left | col;
int pixel_count_till_next_line = (fb->stride - w) >> 1;
@@ -192,16 +192,16 @@ STATIC void gs4_hmsb_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w,
// Functions for GS8 format
STATIC void gs8_setpixel(const mp_obj_framebuf_t *fb, int x, int y, uint32_t col) {
- uint8_t *pixel = &((uint8_t*)fb->buf)[(x + y * fb->stride)];
+ uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride)];
*pixel = col & 0xff;
}
STATIC uint32_t gs8_getpixel(const mp_obj_framebuf_t *fb, int x, int y) {
- return ((uint8_t*)fb->buf)[(x + y * fb->stride)];
+ return ((uint8_t *)fb->buf)[(x + y * fb->stride)];
}
STATIC void gs8_fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, uint32_t col) {
- uint8_t *pixel = &((uint8_t*)fb->buf)[(x + y * fb->stride)];
+ uint8_t *pixel = &((uint8_t *)fb->buf)[(x + y * fb->stride)];
while (h--) {
memset(pixel, col, w);
pixel += fb->stride;
@@ -287,7 +287,7 @@ STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, cons
STATIC const mp_obj_type_t mp_type_framebuf;
// Helper to ensure we have the native super class instead of a subclass.
-static mp_obj_framebuf_t* native_framebuf(mp_obj_t framebuf_obj) {
+static mp_obj_framebuf_t *native_framebuf(mp_obj_t framebuf_obj) {
mp_obj_t native_framebuf = mp_instance_cast_to_native_base(framebuf_obj, &mp_type_framebuf);
mp_obj_assert_native_inited(native_framebuf);
return MP_OBJ_TO_PTR(native_framebuf);
@@ -384,9 +384,9 @@ STATIC mp_obj_t framebuf_rect(size_t n_args, const mp_obj_t *args) {
mp_int_t col = mp_obj_get_int(args[5]);
fill_rect(self, x, y, w, 1, col);
- fill_rect(self, x, y + h- 1, w, 1, col);
+ fill_rect(self, x, y + h - 1, w, 1, col);
fill_rect(self, x, y, 1, h, col);
- fill_rect(self, x + w- 1, y, 1, h, col);
+ fill_rect(self, x + w - 1, y, 1, h, col);
return mp_const_none;
}
@@ -423,9 +423,15 @@ STATIC mp_obj_t framebuf_line(size_t n_args, const mp_obj_t *args) {
bool steep;
if (dy > dx) {
mp_int_t temp;
- temp = x1; x1 = y1; y1 = temp;
- temp = dx; dx = dy; dy = temp;
- temp = sx; sx = sy; sy = temp;
+ temp = x1;
+ x1 = y1;
+ y1 = temp;
+ temp = dx;
+ dx = dy;
+ dy = temp;
+ temp = sx;
+ sx = sy;
+ sy = temp;
steep = true;
} else {
steep = false;
@@ -473,7 +479,7 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) {
(y >= self->height) ||
(-x >= source->width) ||
(-y >= source->height)
- ) {
+ ) {
// Out of bounds, no-op.
return mp_const_none;
}
@@ -547,7 +553,7 @@ STATIC mp_obj_t framebuf_text(size_t n_args, const mp_obj_t *args) {
// loop over chars
for (; *str; ++str) {
// get char and make sure its in range of font
- int chr = *(uint8_t*)str;
+ int chr = *(uint8_t *)str;
if (chr < 32 || chr > 127) {
chr = 127;
}
@@ -590,7 +596,7 @@ STATIC const mp_obj_type_t mp_type_framebuf = {
.name = MP_QSTR_FrameBuffer,
.make_new = framebuf_make_new,
.buffer_p = { .get_buffer = framebuf_get_buffer },
- .locals_dict = (mp_obj_dict_t*)&framebuf_locals_dict,
+ .locals_dict = (mp_obj_dict_t *)&framebuf_locals_dict,
};
// this factory function is provided for backwards compatibility with old FrameBuffer1 class
@@ -633,7 +639,7 @@ STATIC MP_DEFINE_CONST_DICT(framebuf_module_globals, framebuf_module_globals_tab
const mp_obj_module_t mp_module_framebuf = {
.base = { &mp_type_module },
- .globals = (mp_obj_dict_t*)&framebuf_module_globals,
+ .globals = (mp_obj_dict_t *)&framebuf_module_globals,
};
#endif // MICROPY_PY_FRAMEBUF