diff --git a/apps/code/catalog.de.i18n b/apps/code/catalog.de.i18n index 5ead158750a..e4c90ddb155 100644 --- a/apps/code/catalog.de.i18n +++ b/apps/code/catalog.de.i18n @@ -46,6 +46,8 @@ PythonCount = "Zählt die Vorkommen von x" PythonDegrees = "x von Bogenmaß in Grad umrechnen" PythonDivMod = "Quotient und Rest" PythonDrawCircle = "Zeichne einen Kreis" +PythonDrawImage = "Zeichne ein Bild" +PythonImageSize = "Bildgröße zurückgeben [b,h]" PythonDrawLine = "Eine Linie zeichnen" PythonDrawString = "Text bei Pixel (x,y) darstellen" PythonErf = "Fehlerfunktion" diff --git a/apps/code/catalog.en.i18n b/apps/code/catalog.en.i18n index 62a9400577f..359e7773622 100644 --- a/apps/code/catalog.en.i18n +++ b/apps/code/catalog.en.i18n @@ -46,6 +46,8 @@ PythonCount = "Count the occurrences of x" PythonDegrees = "Convert x from radians to degrees" PythonDivMod = "Quotient and remainder" PythonDrawCircle = "Draw a circle" +PythonDrawImage = "Draw an image" +PythonImageSize = "Return image size [w,h]" PythonDrawLine = "Draw a line" PythonDrawString = "Display a text from pixel (x,y)" PythonErf = "Error function" diff --git a/apps/code/catalog.es.i18n b/apps/code/catalog.es.i18n index 883b47cf481..d9fa02a2aae 100644 --- a/apps/code/catalog.es.i18n +++ b/apps/code/catalog.es.i18n @@ -46,6 +46,8 @@ PythonCount = "Count the occurrences of x" PythonDegrees = "Convert x from radians to degrees" PythonDivMod = "Quotient and remainder" PythonDrawCircle = "Draw a circle" +PythonDrawImage = "Draw an image" +PythonImageSize = "Return image size [w,h]" PythonDrawLine = "Draw a line" PythonDrawString = "Display a text from pixel (x,y)" PythonErf = "Error function" diff --git a/apps/code/catalog.fr.i18n b/apps/code/catalog.fr.i18n index 99377015773..4087368959a 100644 --- a/apps/code/catalog.fr.i18n +++ b/apps/code/catalog.fr.i18n @@ -46,6 +46,8 @@ PythonCount = "Compte les occurrences de x" PythonDegrees = "Conversion de radians en degrés" PythonDivMod = "Quotient et reste" PythonDrawCircle = "Trace un cercle" +PythonDrawImage = "Dessine une image" +PythonImageSize = "Retourne la taille de l'image [w,h]" PythonDrawLine = "Trace une ligne" PythonDrawString = "Affiche un texte au pixel (x,y)" PythonErf = "Fonction d'erreur" diff --git a/apps/code/catalog.hu.i18n b/apps/code/catalog.hu.i18n index 6242e4dc35a..630c90a0b18 100644 --- a/apps/code/catalog.hu.i18n +++ b/apps/code/catalog.hu.i18n @@ -46,6 +46,8 @@ PythonCount = "Számolja az x elöfordulását" PythonDegrees = "x konvertálása radiánokrol fokokra" PythonDivMod = "Hányados és maradék" PythonDrawCircle = "Rajzolj egy kört" +PythonDrawImage = "Rajzolj egy képet" +PythonImageSize = "Visszatérés képmérete [w,h]" PythonDrawLine = "Húzzon egy vonalat " PythonDrawString = "Szöveg megjelenítése (x, y)-en" PythonErf = "Hiba funkció" diff --git a/apps/code/catalog.it.i18n b/apps/code/catalog.it.i18n index d8a24f355b9..3306bcabbc2 100644 --- a/apps/code/catalog.it.i18n +++ b/apps/code/catalog.it.i18n @@ -46,6 +46,8 @@ PythonCount = "Conta le ricorrenze di x" PythonDegrees = "Conversione di radianti in gradi" PythonDivMod = "Quoziente e resto" PythonDrawCircle = "Disegnare un cerchio" +PythonDrawImage = "Disegna un'immagine" +PythonImageSize = "Restituisci la dimensione dell'immagine [l,h]" PythonDrawLine = "Disegna una linea" PythonDrawString = "Visualizza il testo dal pixel x,y" PythonErf = "Funzione d'errore" diff --git a/apps/code/catalog.nl.i18n b/apps/code/catalog.nl.i18n index 876073d95b9..a4f29a3aa47 100644 --- a/apps/code/catalog.nl.i18n +++ b/apps/code/catalog.nl.i18n @@ -46,6 +46,8 @@ PythonCount = "Tel voorkomen van x" PythonDegrees = "Zet x om van radialen naar graden" PythonDivMod = "Quotiënt en rest" PythonDrawCircle = "Teken een cirkel" +PythonDrawImage = "Teken een afbeelding" +PythonImageSize = "Retour afbeeldingsgrootte [b,h]" PythonDrawLine = "Teken een lijn" PythonDrawString = "Geef een tekst weer van pixel (x,y)" PythonErf = "Error functie" diff --git a/apps/code/catalog.pt.i18n b/apps/code/catalog.pt.i18n index 155aa785f56..482153b29ba 100644 --- a/apps/code/catalog.pt.i18n +++ b/apps/code/catalog.pt.i18n @@ -46,6 +46,8 @@ PythonCount = "Contar as ocorrências de x" PythonDegrees = "Converter x de radianos para graus" PythonDivMod = "Quociente e resto" PythonDrawCircle = "Desenha um círculo" +PythonDrawImage = "Desenhe uma imagem" +PythonImageSize = "Tamanho da imagem de retorno [w,h]" PythonDrawLine = "Desenhe uma linha" PythonDrawString = "Mostrar o texto do pixel (x,y)" PythonErf = "Função erro" diff --git a/apps/code/catalog.universal.i18n b/apps/code/catalog.universal.i18n index ca6e19c4576..65c5329adcb 100644 --- a/apps/code/catalog.universal.i18n +++ b/apps/code/catalog.universal.i18n @@ -65,6 +65,8 @@ PythonCommandFabs = "fabs(x)" PythonCommandFillCircle = "fill_circle(x,y,r,color)" PythonCommandFillPolygon = "fill_polygon([(x1,y1),...],color)" PythonCommandFillRect = "fill_rect(x,y,width,height,color)" +PythonCommandDrawImage = "draw_image(image,x,y,width,height)" +PythonCommandImageSize = "image_size(image)" PythonCommandFloat = "float(x)" PythonCommandFloor = "floor(x)" PythonCommandFmod = "fmod(a,b)" diff --git a/apps/code/python_toolbox.cpp b/apps/code/python_toolbox.cpp index 1f75378d332..bcb673fb25b 100644 --- a/apps/code/python_toolbox.cpp +++ b/apps/code/python_toolbox.cpp @@ -374,6 +374,8 @@ const ToolboxMessageTree KandinskyModuleChildren[] = { ToolboxMessageTree::Leaf(I18n::Message::PythonCommandDrawString, I18n::Message::PythonDrawString), ToolboxMessageTree::Leaf(I18n::Message::PythonCommandDrawLine, I18n::Message::PythonDrawLine), ToolboxMessageTree::Leaf(I18n::Message::PythonCommandDrawCircle, I18n::Message::PythonDrawCircle), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandDrawImage, I18n::Message::PythonDrawImage), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandImageSize, I18n::Message::PythonImageSize), ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFillRect, I18n::Message::PythonFillRect), ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFillCircle, I18n::Message::PythonFillCircle), ToolboxMessageTree::Leaf(I18n::Message::PythonCommandFillPolygon, I18n::Message::PythonFillPolygon), diff --git a/python/port/genhdr/qstrdefs.in.h b/python/port/genhdr/qstrdefs.in.h index 3fae92b55b0..84a89ca9a20 100644 --- a/python/port/genhdr/qstrdefs.in.h +++ b/python/port/genhdr/qstrdefs.in.h @@ -399,6 +399,8 @@ Q(color) Q(draw_line) Q(draw_string) Q(draw_circle) +Q(draw_image) +Q(image_size) Q(fill_rect) Q(fill_circle) Q(fill_polygon) diff --git a/python/port/mod/kandinsky/modkandinsky.cpp b/python/port/mod/kandinsky/modkandinsky.cpp index 63e48320933..4ca0204bd35 100644 --- a/python/port/mod/kandinsky/modkandinsky.cpp +++ b/python/port/mod/kandinsky/modkandinsky.cpp @@ -1,14 +1,24 @@ extern "C" { #include "modkandinsky.h" #include +#include } -#include +#ifdef HOME_DISPLAY_EXTERNALS +#include +#endif +#include #include #include #include "port.h" #include - +struct OBMHeader +{ + uint32_t signature; //Normally it is 32145 + int32_t width; + int32_t height; + const KDColor image_data; +}; static mp_obj_t TupleForKDColor(KDColor c) { mp_obj_tuple_t * t = static_cast(MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL))); t->items[0] = MP_OBJ_NEW_SMALL_INT(c.red()); @@ -95,6 +105,56 @@ mp_obj_t modkandinsky_draw_circle(size_t n_args, const mp_obj_t * args) { KDIonContext::sharedContext()->drawCircle(center, r, color); return mp_const_none; } +mp_obj_t modkandinsky_draw_image(size_t n_args, const mp_obj_t * args) { + #ifdef HOME_DISPLAY_EXTERNALS + const char * image = mp_obj_str_get_str(args[0]); + mp_int_t x = mp_obj_get_int(args[1]); + mp_int_t y = mp_obj_get_int(args[2]); + mp_int_t width = mp_obj_get_int(args[3]); + mp_int_t height = mp_obj_get_int(args[4]); + + + if (width < 0) { + width = -width; + x = x - width; + } + if (height < 0) { + height = -height; + y = y - height; + } + int index = External::Archive::indexFromName(image); + if (index > -1) { + External::Archive::File image; + External::Archive::fileAtIndex(index, image); + OBMHeader* h = (OBMHeader*)image.data; + MicroPython::ExecutionEnvironment::currentExecutionEnvironment()->displaySandbox(); + KDIonContext::sharedContext()->fillRectWithPixels(KDRect(x, y, width, height), &(h->image_data), nullptr); + } + #endif + return mp_const_none; +} + +mp_obj_t modkandinsky_image_size(size_t n_args, const mp_obj_t * args) { + #ifdef HOME_DISPLAY_EXTERNALS + const char * image = mp_obj_str_get_str(args[0]); + int index = External::Archive::indexFromName(image); + if (index > -1) { + External::Archive::File image; + External::Archive::fileAtIndex(index, image); + OBMHeader* h = (OBMHeader*)image.data; + mp_obj_t sizeList = mp_obj_new_list(0, NULL); + mp_obj_list_append(sizeList, &(h->width)); + mp_obj_list_append(sizeList, &(h->height)); + mp_obj_t size[2]; + size[0] = mp_obj_new_int((h->width)); + size[1] = mp_obj_new_int((h->height)); + return mp_obj_new_tuple(2, size); + } + #endif + return mp_const_none; + +} + mp_obj_t modkandinsky_fill_rect(size_t n_args, const mp_obj_t * args) { mp_int_t x = mp_obj_get_int(args[0]); diff --git a/python/port/mod/kandinsky/modkandinsky.h b/python/port/mod/kandinsky/modkandinsky.h index 3ce71155adb..ec9ea1d9dbb 100644 --- a/python/port/mod/kandinsky/modkandinsky.h +++ b/python/port/mod/kandinsky/modkandinsky.h @@ -6,6 +6,8 @@ mp_obj_t modkandinsky_set_pixel(mp_obj_t x, mp_obj_t y, mp_obj_t color); mp_obj_t modkandinsky_draw_string(size_t n_args, const mp_obj_t *args); mp_obj_t modkandinsky_draw_line(size_t n_args, const mp_obj_t *args); mp_obj_t modkandinsky_draw_circle(size_t n_args, const mp_obj_t *args); +mp_obj_t modkandinsky_draw_image(size_t n_args, const mp_obj_t *args); +mp_obj_t modkandinsky_image_size(size_t n_args, const mp_obj_t *args); mp_obj_t modkandinsky_fill_rect(size_t n_args, const mp_obj_t *args); mp_obj_t modkandinsky_fill_circle(size_t n_args, const mp_obj_t *args); mp_obj_t modkandinsky_fill_polygon(size_t n_args, const mp_obj_t *args); diff --git a/python/port/mod/kandinsky/modkandinsky_table.c b/python/port/mod/kandinsky/modkandinsky_table.c index 033dbf5b673..a884561b565 100644 --- a/python/port/mod/kandinsky/modkandinsky_table.c +++ b/python/port/mod/kandinsky/modkandinsky_table.c @@ -8,6 +8,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_draw_line_obj, 5, 5, mod STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_draw_circle_obj, 4, 4, modkandinsky_draw_circle); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_fill_rect_obj, 5, 5, modkandinsky_fill_rect); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_fill_circle_obj, 4, 4, modkandinsky_fill_circle); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_draw_image_obj, 5, 5, modkandinsky_draw_image); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_image_size_obj, 1, 1, modkandinsky_image_size); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_fill_polygon_obj, 2, 2, modkandinsky_fill_polygon); STATIC MP_DEFINE_CONST_FUN_OBJ_0(modkandinsky_wait_vblank_obj, modkandinsky_wait_vblank); STATIC MP_DEFINE_CONST_FUN_OBJ_0(modkandinsky_get_palette_obj, modkandinsky_get_palette); @@ -20,6 +22,8 @@ STATIC const mp_rom_map_elem_t modkandinsky_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_draw_string), (mp_obj_t)&modkandinsky_draw_string_obj }, { MP_ROM_QSTR(MP_QSTR_draw_line), (mp_obj_t)&modkandinsky_draw_line_obj }, { MP_ROM_QSTR(MP_QSTR_draw_circle), (mp_obj_t)&modkandinsky_draw_circle_obj }, + { MP_ROM_QSTR(MP_QSTR_draw_image), (mp_obj_t)&modkandinsky_draw_image_obj }, + { MP_ROM_QSTR(MP_QSTR_image_size), (mp_obj_t)&modkandinsky_image_size_obj }, { MP_ROM_QSTR(MP_QSTR_fill_rect), (mp_obj_t)&modkandinsky_fill_rect_obj }, { MP_ROM_QSTR(MP_QSTR_fill_circle), (mp_obj_t)&modkandinsky_fill_circle_obj }, { MP_ROM_QSTR(MP_QSTR_fill_polygon), (mp_obj_t)&modkandinsky_fill_polygon_obj },