Skip to content
Snippets Groups Projects
Commit 48264c5f authored by pippin's avatar pippin
Browse files

st3m,mp: change st3m_gfx_fb to return stride, width and height

parent 88361ab0
No related branches found
No related tags found
No related merge requests found
...@@ -77,9 +77,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_ctx_obj, mp_ctx); ...@@ -77,9 +77,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_ctx_obj, mp_ctx);
STATIC mp_obj_t mp_fb(mp_obj_t mode_in) { STATIC mp_obj_t mp_fb(mp_obj_t mode_in) {
int mode = mp_obj_get_int(mode_in); int mode = mp_obj_get_int(mode_in);
int size = 240 * 240 * st3m_gfx_bpp(mode) / 8; int stride, width, height;
if (mode == st3m_gfx_palette) size = 256 * 3; void *fb = st3m_gfx_fb(mode, &stride, &width, &height);
return mp_obj_new_bytearray_by_ref(size, st3m_gfx_fb(mode)); int size = height * stride;
return mp_obj_new_bytearray_by_ref(size, fb);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_fb_obj, mp_fb); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_fb_obj, mp_fb);
......
...@@ -218,6 +218,9 @@ void st3m_gfx_set_default_mode(st3m_gfx_mode mode) { ...@@ -218,6 +218,9 @@ void st3m_gfx_set_default_mode(st3m_gfx_mode mode) {
default_mode &= ~st3m_gfx_low_latency; default_mode &= ~st3m_gfx_low_latency;
else if (mode & st3m_gfx_direct_ctx) else if (mode & st3m_gfx_direct_ctx)
default_mode &= ~st3m_gfx_direct_ctx; default_mode &= ~st3m_gfx_direct_ctx;
} else if ((mode & (1|2|4|8|16|32)) == mode) {
default_mode &= ~(1|2|4|8|16|32);
default_mode |= mode;
} else if (mode == st3m_gfx_2x) { } else if (mode == st3m_gfx_2x) {
default_mode &= ~st3m_gfx_4x; default_mode &= ~st3m_gfx_4x;
default_mode |= st3m_gfx_2x; default_mode |= st3m_gfx_2x;
...@@ -335,19 +338,32 @@ st3m_gfx_mode st3m_gfx_set_mode(st3m_gfx_mode mode) { ...@@ -335,19 +338,32 @@ st3m_gfx_mode st3m_gfx_set_mode(st3m_gfx_mode mode) {
st3m_gfx_mode st3m_gfx_get_mode(void) { return _st3m_gfx_mode; } st3m_gfx_mode st3m_gfx_get_mode(void) { return _st3m_gfx_mode; }
uint8_t *st3m_gfx_fb(st3m_gfx_mode mode) { uint8_t *st3m_gfx_fb(st3m_gfx_mode mode, int *stride, int *width, int *height) {
st3m_gfx_mode set_mode = _st3m_gfx_mode ? _st3m_gfx_mode : default_mode; st3m_gfx_mode set_mode = _st3m_gfx_mode ? _st3m_gfx_mode : default_mode;
int bpp = st3m_gfx_bpp(set_mode);
if (mode == st3m_gfx_palette) { if (mode == st3m_gfx_palette) {
if (stride) *stride = 3;
if (width) *width = 1;
if (height) *height = 256;
return st3m_pal; return st3m_pal;
} else if (mode == st3m_gfx_default) { } else if (mode == st3m_gfx_default) {
if (st3m_gfx_bpp(set_mode) <= 16) return (uint8_t *)st3m_fb; if (stride) *stride = 240 * bpp / 8;
if (width) *width = 240;
if (height) *height = 240;
if (bpp <= 16) return (uint8_t *)st3m_fb;
return st3m_osd_fb; return st3m_osd_fb;
} else if (mode == st3m_gfx_osd) { } else if (mode == st3m_gfx_osd) {
if (stride) *stride = 240 * bpp / 8;
if (width) *width = 240;
if (height) *height = 240;
if (st3m_gfx_bpp(set_mode) <= 16) return st3m_osd_fb; if (st3m_gfx_bpp(set_mode) <= 16) return st3m_osd_fb;
return (uint8_t *)st3m_fb; return (uint8_t *)st3m_fb;
} }
if (st3m_gfx_bpp(set_mode) <= 16) return (uint8_t *)st3m_fb; if (stride) *stride = 240 * bpp / 8;
if (width) *width = 240;
if (height) *height = 240;
if (bpp <= 16) return (uint8_t *)st3m_fb;
return st3m_osd_fb; return st3m_osd_fb;
} }
......
...@@ -76,7 +76,7 @@ Ctx *st3m_gfx_ctx(st3m_gfx_mode mode); ...@@ -76,7 +76,7 @@ Ctx *st3m_gfx_ctx(st3m_gfx_mode mode);
// get the framebuffer associated with graphics mode // get the framebuffer associated with graphics mode
// if you ask for st3m_gfx_default you get the current modes fb // if you ask for st3m_gfx_default you get the current modes fb
// and if you ask for st3m_gfx_osd you get the current modes overlay fb // and if you ask for st3m_gfx_osd you get the current modes overlay fb
uint8_t *st3m_gfx_fb(st3m_gfx_mode mode); uint8_t *st3m_gfx_fb(st3m_gfx_mode mode, int *stride, int *width, int *height);
// get the bits per pixel for a given mode // get the bits per pixel for a given mode
int st3m_gfx_bpp(st3m_gfx_mode mode); int st3m_gfx_bpp(st3m_gfx_mode mode);
......
...@@ -169,10 +169,10 @@ def run_main() -> None: ...@@ -169,10 +169,10 @@ def run_main() -> None:
[ [
MenuItemBack(), MenuItemBack(),
MenuItemAction( MenuItemAction(
"RGB565_BS", lambda: sys_display.set_default_mode(16 + sys_display.osd) "RGB565_BS", lambda: sys_display.set_default_mode(16)
), ),
MenuItemAction( MenuItemAction(
"RGB888", lambda: sys_display.set_default_mode(24 + sys_display.osd) "RGB888", lambda: sys_display.set_default_mode(24)
), ),
MenuItemAction( MenuItemAction(
"RGB332", "RGB332",
...@@ -181,7 +181,7 @@ def run_main() -> None: ...@@ -181,7 +181,7 @@ def run_main() -> None:
), ),
), ),
MenuItemAction( MenuItemAction(
"gray", lambda: sys_display.set_default_mode(8 + sys_display.osd) "gray", lambda: sys_display.set_default_mode(8)
), ),
MenuItemAction( MenuItemAction(
"sepia", "sepia",
...@@ -237,7 +237,7 @@ def run_main() -> None: ...@@ -237,7 +237,7 @@ def run_main() -> None:
"force mode", lambda: sys_display.set_default_mode(sys_display.force) "force mode", lambda: sys_display.set_default_mode(sys_display.force)
), ),
MenuItemAction( MenuItemAction(
"force mode off", "force mode off (apps can change graphics mode)",
lambda: sys_display.set_default_mode( lambda: sys_display.set_default_mode(
sys_display.unset + sys_display.force sys_display.unset + sys_display.force
), ),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment