From b81072e7501045bfa5e8e5b74631dfe01327af2b Mon Sep 17 00:00:00 2001 From: Bryan Siepert Date: Sat, 23 Feb 2019 10:58:46 -0800 Subject: [PATCH 1/3] (fork rebuild) Initial support for 16bpp 555&565 and 8bpp grayscale bitmaps --- locale/ID.po | 11 ++++- locale/circuitpython.pot | 11 ++++- locale/de_DE.po | 11 ++++- locale/en_US.po | 11 ++++- locale/es.po | 16 +++++-- locale/fil.po | 16 +++++-- locale/fr.po | 16 +++++-- locale/it_IT.po | 16 +++++-- locale/pt_BR.po | 16 +++++-- shared-module/displayio/OnDiskBitmap.c | 63 ++++++++++++++++++++++---- shared-module/displayio/OnDiskBitmap.h | 5 ++ 11 files changed, 160 insertions(+), 32 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index 7e3a6c7981..bfa2192220 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-22 15:26-0800\n" +"POT-Creation-Date: 2019-02-23 10:51-0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -756,6 +756,11 @@ msgstr "" msgid "Odd parity is not supported" msgstr "Parity ganjil tidak didukung" +#, c-format +msgid "" +"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" +msgstr "" + msgid "Only 8 or 16 bit mono with " msgstr "Hanya 8 atau 16 bit mono dengan " @@ -770,7 +775,9 @@ msgid "Only slices with step=1 (aka None) are supported" msgstr "" #, c-format -msgid "Only true color (24 bpp or higher) BMP supported %x" +msgid "" +"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " +"BMP supported %d" msgstr "" msgid "Only tx supported on UART1 (GPIO2)." diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 226a3a6fa3..c36a10a4ca 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-22 15:26-0800\n" +"POT-Creation-Date: 2019-02-23 10:51-0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -730,6 +730,11 @@ msgstr "" msgid "Odd parity is not supported" msgstr "" +#, c-format +msgid "" +"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" +msgstr "" + msgid "Only 8 or 16 bit mono with " msgstr "" @@ -744,7 +749,9 @@ msgid "Only slices with step=1 (aka None) are supported" msgstr "" #, c-format -msgid "Only true color (24 bpp or higher) BMP supported %x" +msgid "" +"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " +"BMP supported %d" msgstr "" msgid "Only tx supported on UART1 (GPIO2)." diff --git a/locale/de_DE.po b/locale/de_DE.po index aff3c14f83..9da46fbea6 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-22 15:26-0800\n" +"POT-Creation-Date: 2019-02-23 10:51-0800\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -745,6 +745,11 @@ msgstr "" msgid "Odd parity is not supported" msgstr "Eine ungerade Parität wird nicht unterstützt" +#, c-format +msgid "" +"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" +msgstr "" + msgid "Only 8 or 16 bit mono with " msgstr "Nur 8 oder 16 bit mono mit " @@ -759,7 +764,9 @@ msgid "Only slices with step=1 (aka None) are supported" msgstr "" #, c-format -msgid "Only true color (24 bpp or higher) BMP supported %x" +msgid "" +"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " +"BMP supported %d" msgstr "" msgid "Only tx supported on UART1 (GPIO2)." diff --git a/locale/en_US.po b/locale/en_US.po index c6bc8c5afd..cb9d85a184 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-22 15:26-0800\n" +"POT-Creation-Date: 2019-02-23 10:51-0800\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -730,6 +730,11 @@ msgstr "" msgid "Odd parity is not supported" msgstr "" +#, c-format +msgid "" +"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" +msgstr "" + msgid "Only 8 or 16 bit mono with " msgstr "" @@ -744,7 +749,9 @@ msgid "Only slices with step=1 (aka None) are supported" msgstr "" #, c-format -msgid "Only true color (24 bpp or higher) BMP supported %x" +msgid "" +"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " +"BMP supported %d" msgstr "" msgid "Only tx supported on UART1 (GPIO2)." diff --git a/locale/es.po b/locale/es.po index 46b9435e50..06a1f10f93 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-22 15:26-0800\n" +"POT-Creation-Date: 2019-02-23 10:51-0800\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -770,6 +770,11 @@ msgstr "" msgid "Odd parity is not supported" msgstr "Paridad impar no soportada" +#, c-format +msgid "" +"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" +msgstr "" + msgid "Only 8 or 16 bit mono with " msgstr "Solo mono de 8 o 16 bit con " @@ -785,8 +790,10 @@ msgid "Only slices with step=1 (aka None) are supported" msgstr "solo se admiten segmentos con step=1 (alias None)" #, c-format -msgid "Only true color (24 bpp or higher) BMP supported %x" -msgstr "Solo color verdadero (24 bpp o superior) BMP admitido %x" +msgid "" +"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " +"BMP supported %d" +msgstr "" msgid "Only tx supported on UART1 (GPIO2)." msgstr "Solo tx soportada en UART1 (GPIO2)" @@ -2160,3 +2167,6 @@ msgstr "address fuera de límites" msgid "zero step" msgstr "paso cero" + +#~ msgid "Only true color (24 bpp or higher) BMP supported %x" +#~ msgstr "Solo color verdadero (24 bpp o superior) BMP admitido %x" diff --git a/locale/fil.po b/locale/fil.po index 3dc70c6267..0e79f20317 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-22 15:26-0800\n" +"POT-Creation-Date: 2019-02-23 10:51-0800\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -768,6 +768,11 @@ msgstr "" msgid "Odd parity is not supported" msgstr "Odd na parity ay hindi supportado" +#, c-format +msgid "" +"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" +msgstr "" + msgid "Only 8 or 16 bit mono with " msgstr "Tanging 8 o 16 na bit mono na may " @@ -783,8 +788,10 @@ msgid "Only slices with step=1 (aka None) are supported" msgstr "ang mga slices lamang na may hakbang = 1 (aka None) ang sinusuportahan" #, c-format -msgid "Only true color (24 bpp or higher) BMP supported %x" -msgstr "Dapat true color (24 bpp o mas mataas) BMP lamang ang supportado %x" +msgid "" +"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " +"BMP supported %d" +msgstr "" msgid "Only tx supported on UART1 (GPIO2)." msgstr "Tanging suportado ang TX sa UART1 (GPIO2)." @@ -2166,3 +2173,6 @@ msgstr "wala sa sakop ang address" msgid "zero step" msgstr "zero step" + +#~ msgid "Only true color (24 bpp or higher) BMP supported %x" +#~ msgstr "Dapat true color (24 bpp o mas mataas) BMP lamang ang supportado %x" diff --git a/locale/fr.po b/locale/fr.po index 98911d64df..cb81f74ca7 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-22 15:26-0800\n" +"POT-Creation-Date: 2019-02-23 10:51-0800\n" "PO-Revision-Date: 2018-12-23 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -772,6 +772,11 @@ msgstr "" msgid "Odd parity is not supported" msgstr "parité impaire non supportée" +#, c-format +msgid "" +"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" +msgstr "" + msgid "Only 8 or 16 bit mono with " msgstr "Uniquement 8 ou 16 bit mono avec " @@ -787,8 +792,10 @@ msgid "Only slices with step=1 (aka None) are supported" msgstr "seuls les slices avec 'step=1' (cad None) sont supportées" #, c-format -msgid "Only true color (24 bpp or higher) BMP supported %x" -msgstr "Seul les BMP 24bits ou plus sont supportés %x" +msgid "" +"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " +"BMP supported %d" +msgstr "" msgid "Only tx supported on UART1 (GPIO2)." msgstr "Seul le tx est supporté sur l'UART1 (GPIO2)." @@ -2190,3 +2197,6 @@ msgstr "adresse hors limites" msgid "zero step" msgstr "'step' nul" + +#~ msgid "Only true color (24 bpp or higher) BMP supported %x" +#~ msgstr "Seul les BMP 24bits ou plus sont supportés %x" diff --git a/locale/it_IT.po b/locale/it_IT.po index 55c6c065e5..83664a146c 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-22 15:26-0800\n" +"POT-Creation-Date: 2019-02-23 10:51-0800\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -767,6 +767,11 @@ msgstr "" msgid "Odd parity is not supported" msgstr "operazione I2C non supportata" +#, c-format +msgid "" +"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" +msgstr "" + msgid "Only 8 or 16 bit mono with " msgstr "" @@ -782,8 +787,10 @@ msgid "Only slices with step=1 (aka None) are supported" msgstr "solo slice con step=1 (aka None) sono supportate" #, c-format -msgid "Only true color (24 bpp or higher) BMP supported %x" -msgstr "Solo BMP true color (24 bpp o superiore) sono supportati %x" +msgid "" +"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " +"BMP supported %d" +msgstr "" msgid "Only tx supported on UART1 (GPIO2)." msgstr "Solo tx supportato su UART1 (GPIO2)." @@ -2162,3 +2169,6 @@ msgstr "indirizzo fuori limite" msgid "zero step" msgstr "zero step" + +#~ msgid "Only true color (24 bpp or higher) BMP supported %x" +#~ msgstr "Solo BMP true color (24 bpp o superiore) sono supportati %x" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 6b08dcef00..70e7bde4a9 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-02-22 15:26-0800\n" +"POT-Creation-Date: 2019-02-23 10:51-0800\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -756,6 +756,11 @@ msgstr "" msgid "Odd parity is not supported" msgstr "I2C operação não suportada" +#, c-format +msgid "" +"Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x" +msgstr "" + msgid "Only 8 or 16 bit mono with " msgstr "" @@ -770,8 +775,10 @@ msgid "Only slices with step=1 (aka None) are supported" msgstr "" #, c-format -msgid "Only true color (24 bpp or higher) BMP supported %x" -msgstr "Apenas cores verdadeiras (24 bpp ou maior) BMP suportadas" +msgid "" +"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " +"BMP supported %d" +msgstr "" msgid "Only tx supported on UART1 (GPIO2)." msgstr "Apenas TX suportado no UART1 (GPIO2)." @@ -2110,3 +2117,6 @@ msgstr "" msgid "zero step" msgstr "passo zero" + +#~ msgid "Only true color (24 bpp or higher) BMP supported %x" +#~ msgstr "Apenas cores verdadeiras (24 bpp ou maior) BMP suportadas" diff --git a/shared-module/displayio/OnDiskBitmap.c b/shared-module/displayio/OnDiskBitmap.c index aa2ca3e103..bc30646326 100644 --- a/shared-module/displayio/OnDiskBitmap.c +++ b/shared-module/displayio/OnDiskBitmap.c @@ -38,13 +38,13 @@ static uint32_t read_word(uint16_t* bmp_header, uint16_t index) { void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self, pyb_file_obj_t* file) { // Load the wave self->file = file; - uint16_t bmp_header[24]; + uint16_t bmp_header[69]; f_rewind(&self->file->fp); UINT bytes_read; - if (f_read(&self->file->fp, bmp_header, 48, &bytes_read) != FR_OK) { + if (f_read(&self->file->fp, bmp_header, 138, &bytes_read) != FR_OK) { mp_raise_OSError(MP_EIO); } - if (bytes_read != 48 || + if (bytes_read != 138 || memcmp(bmp_header, "BM", 2) != 0) { mp_raise_ValueError(translate("Invalid BMP file")); } @@ -53,15 +53,35 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self, self->data_offset = read_word(bmp_header, 5); uint32_t header_size = read_word(bmp_header, 7); + uint16_t bits_per_pixel = bmp_header[14]; uint32_t compression = read_word(bmp_header, 15); - if (!(header_size == 12 || header_size == 40 || header_size == 108 || header_size == 124) || + uint32_t number_of_colors = read_word(bmp_header, 23); + self->bitfield_compressed = (compression == 3); + + self->grayscale = ((bits_per_pixel == 8) && (number_of_colors == 256)); + if (bits_per_pixel == 16){ + if (((header_size == 124) || (header_size == 56)) && (self->bitfield_compressed)) { + self->r_bitmask = read_word(bmp_header, 27); + self->g_bitmask = read_word(bmp_header, 29); + self->b_bitmask = read_word(bmp_header, 31); + + if (!((self->r_bitmask == 0xf800) && (self->g_bitmask == 0x07e0) && (self->b_bitmask == 0x001f))){ + mp_raise_ValueError_varg(translate("Only 16bpp RGB 565 supported for bitfield compressed BMPs; R:%x G:%x B:%x"), + self->r_bitmask, self->g_bitmask, self->b_bitmask); + } + } else if (header_size == 40){ // no bitmasks means 5:5:5 + self->r_bitmask = 0x7c00; + self->g_bitmask = 0x3e0; + self->b_bitmask = 0x1f; + } + + } else if (!(header_size == 12 || header_size == 40 || header_size == 108 || header_size == 124) || !(compression == 0)) { mp_raise_ValueError_varg(translate("Only Windows format, uncompressed BMP supported %d"), header_size); } - // TODO(tannewt): Support bitfield compressed colors since RGB565 can be produced by the GIMP. - uint16_t bits_per_pixel = bmp_header[14]; - if (bits_per_pixel < 24) { - mp_raise_ValueError_varg(translate("Only true color (24 bpp or higher) BMP supported %x"), bits_per_pixel); + + if (bits_per_pixel < 16 && !(self->grayscale)) { + mp_raise_ValueError_varg(translate("Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale BMP supported %d"), bits_per_pixel); } self->bytes_per_pixel = bits_per_pixel / 8; self->width = read_word(bmp_header, 9); @@ -87,7 +107,32 @@ uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *s uint32_t pixel = 0; uint32_t result = f_read(&self->file->fp, &pixel, self->bytes_per_pixel, &bytes_read); if (result == FR_OK) { - return pixel; + uint32_t tmp = 0; + uint8_t red; + uint8_t green; + uint8_t blue; + if (self->grayscale){ + red = pixel; + green = pixel; + blue = pixel; + tmp = (red << 16 | green << 8 | blue); + return tmp; + } else if (self->bytes_per_pixel == 2) { + if (self->bitfield_compressed){ + red =((pixel & self->r_bitmask) >>11); + green = ((pixel & self->g_bitmask) >>5); + blue = ((pixel & self->b_bitmask) >> 0); + } else { + red =((pixel & self->r_bitmask) >>10); + green = ((pixel & self->g_bitmask) >>4); + blue = ((pixel & self->b_bitmask) >> 0); + } + tmp = (red << 19 | green << 10 | blue << 3); + return tmp; + }else { + return pixel; + } + } return 0; } diff --git a/shared-module/displayio/OnDiskBitmap.h b/shared-module/displayio/OnDiskBitmap.h index 31d6c95501..2102863d68 100644 --- a/shared-module/displayio/OnDiskBitmap.h +++ b/shared-module/displayio/OnDiskBitmap.h @@ -40,6 +40,11 @@ typedef struct { uint16_t height; uint16_t data_offset; uint16_t stride; + uint32_t r_bitmask; + uint32_t g_bitmask; + uint32_t b_bitmask; + bool bitfield_compressed; + bool grayscale; pyb_file_obj_t* file; uint8_t bytes_per_pixel; } displayio_ondiskbitmap_t; From 3843e96edc8d338492574570caee24f398036b93 Mon Sep 17 00:00:00 2001 From: Bryan Siepert Date: Sat, 23 Feb 2019 19:47:58 -0800 Subject: [PATCH 2/3] Tweaking German hallowing build for size --- ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk index e41e2ebd90..0669939260 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk @@ -16,3 +16,6 @@ CHIP_FAMILY = samd21 FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_BusDevice FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel + +# To keep the build small +CFLAGS_INLINE_LIMIT = 50 From 3afcd3f5bc418fb9daa3838915557bd2c1a05f03 Mon Sep 17 00:00:00 2001 From: Bryan Siepert Date: Sat, 23 Feb 2019 20:18:22 -0800 Subject: [PATCH 3/3] another/different size tweak for the DE hallowing build --- ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk index 0669939260..222a217b30 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk @@ -18,4 +18,4 @@ FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel # To keep the build small -CFLAGS_INLINE_LIMIT = 50 +CIRCUITPY_I2CSLAVE = 0