From 398c7060f8a51bb83b0f5e0c2a1611d684603d2b Mon Sep 17 00:00:00 2001 From: Bryan Siepert Date: Wed, 27 Feb 2019 21:02:48 -0800 Subject: [PATCH 1/3] added monochrome, 8bpp indexed, and 32bpp ARGB BMPs --- locale/ID.po | 18 ++--- locale/circuitpython.pot | 18 ++--- locale/de_DE.po | 18 ++--- locale/en_US.po | 18 ++--- locale/es.po | 20 ++--- locale/fil.po | 20 ++--- locale/fr.po | 20 ++--- locale/it_IT.po | 20 ++--- locale/pt_BR.po | 18 ++--- shared-module/displayio/OnDiskBitmap.c | 104 +++++++++++++++++-------- shared-module/displayio/OnDiskBitmap.h | 4 +- 11 files changed, 140 insertions(+), 138 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index bfa2192220..c0b1dafdbd 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-23 10:51-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -756,11 +756,6 @@ 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 " @@ -771,13 +766,11 @@ msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "" -msgid "Only slices with step=1 (aka None) are supported" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" msgstr "" -#, c-format -msgid "" -"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " -"BMP supported %d" +msgid "Only slices with step=1 (aka None) are supported" msgstr "" msgid "Only tx supported on UART1 (GPIO2)." @@ -984,6 +977,9 @@ msgstr "Tidak dapat menemukan GCLK yang kosong" msgid "Unable to init parser" msgstr "" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "Tidak dapat memasang filesystem kembali" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 318adc7685..ea6b26c3f8 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-23 19:57-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -730,11 +730,6 @@ 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 "" @@ -745,13 +740,11 @@ msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "" -msgid "Only slices with step=1 (aka None) are supported" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" msgstr "" -#, c-format -msgid "" -"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " -"BMP supported %d" +msgid "Only slices with step=1 (aka None) are supported" msgstr "" msgid "Only tx supported on UART1 (GPIO2)." @@ -951,6 +944,9 @@ msgstr "" msgid "Unable to init parser" msgstr "" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index d9354f01ff..ff9cafc763 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-23 19:57-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -748,11 +748,6 @@ 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 " @@ -764,13 +759,11 @@ msgid "Only bit maps of 8 bit color or less are supported" msgstr "" "Es werden nur Bitmaps mit einer Farbtiefe von 8 Bit oder weniger unterstützt" -msgid "Only slices with step=1 (aka None) are supported" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" msgstr "" -#, c-format -msgid "" -"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " -"BMP supported %d" +msgid "Only slices with step=1 (aka None) are supported" msgstr "" msgid "Only tx supported on UART1 (GPIO2)." @@ -984,6 +977,9 @@ msgstr "Konnte keinen freien GCLK finden" msgid "Unable to init parser" msgstr "Parser konnte nicht gestartet werden" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "Dateisystem konnte nicht wieder eingebunden werden." diff --git a/locale/en_US.po b/locale/en_US.po index cb9d85a184..45596fb620 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-23 10:51-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -730,11 +730,6 @@ 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 "" @@ -745,13 +740,11 @@ msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "" -msgid "Only slices with step=1 (aka None) are supported" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" msgstr "" -#, c-format -msgid "" -"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " -"BMP supported %d" +msgid "Only slices with step=1 (aka None) are supported" msgstr "" msgid "Only tx supported on UART1 (GPIO2)." @@ -951,6 +944,9 @@ msgstr "" msgid "Unable to init parser" msgstr "" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "" diff --git a/locale/es.po b/locale/es.po index 06a1f10f93..996d58df66 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-23 10:51-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -770,11 +770,6 @@ 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,16 +780,14 @@ msgstr "Solo formato Windows, BMP sin comprimir soportado %d" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Solo se admiten bit maps de color de 8 bits o menos" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgstr "" + #, fuzzy 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), 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)" @@ -1003,6 +996,9 @@ msgstr "No se pudo encontrar un GCLK libre" msgid "Unable to init parser" msgstr "Incapaz de inicializar el parser" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "Incapaz de montar de nuevo el sistema de archivos" diff --git a/locale/fil.po b/locale/fil.po index 0e79f20317..af5046d7c2 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-23 10:51-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -768,11 +768,6 @@ 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,16 +778,14 @@ msgstr "Tanging Windows format, uncompressed BMP lamang ang supportado %d" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Tanging bit maps na may 8 bit color o mas mababa ang supportado" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgstr "" + #, fuzzy 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), 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)." @@ -1005,6 +998,9 @@ msgstr "Hindi mahanap ang libreng GCLK" msgid "Unable to init parser" msgstr "Hindi ma-init ang parser" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "Hindi ma-remount ang filesystem" diff --git a/locale/fr.po b/locale/fr.po index cb81f74ca7..3fde90bde7 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-23 10:51-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: 2018-12-23 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -772,11 +772,6 @@ 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,16 +782,14 @@ msgstr "Seul les BMP non-compressé au format Windows sont supportés %d" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Seules les bitmaps de 8bits par couleur ou moins sont supportées" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgstr "" + #, fuzzy 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), 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)." @@ -1016,6 +1009,9 @@ msgstr "Impossible de trouver un GCLK libre" msgid "Unable to init parser" msgstr "Impossible d'initialiser le parser" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "Impossible de remonter le système de fichiers" diff --git a/locale/it_IT.po b/locale/it_IT.po index 83664a146c..ea1a42b119 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-23 10:51-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -767,11 +767,6 @@ 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,16 +777,14 @@ msgstr "Formato solo di Windows, BMP non compresso supportato %d" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Sono supportate solo bitmap con colori a 8 bit o meno" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgstr "" + #, fuzzy 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), 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)." @@ -1003,6 +996,9 @@ msgstr "Impossibile trovare un GCLK libero" msgid "Unable to init parser" msgstr "Inizilizzazione del parser non possibile" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "Imposssibile rimontare il filesystem" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 70e7bde4a9..8477e14786 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-23 10:51-0800\n" +"POT-Creation-Date: 2019-02-28 23:07-0800\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -756,11 +756,6 @@ 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 "" @@ -771,13 +766,11 @@ msgstr "Apenas formato Windows, BMP descomprimido suportado" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Apenas bit maps de cores de 8 bit ou menos são suportados" -msgid "Only slices with step=1 (aka None) are supported" +#, c-format +msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" msgstr "" -#, c-format -msgid "" -"Only true color (24 bpp or higher), 16bpp 565 and 555, and 8bpp grayscale " -"BMP supported %d" +msgid "Only slices with step=1 (aka None) are supported" msgstr "" msgid "Only tx supported on UART1 (GPIO2)." @@ -979,6 +972,9 @@ msgstr "Não é possível encontrar GCLK livre" msgid "Unable to init parser" msgstr "" +msgid "Unable to read color palette data" +msgstr "" + msgid "Unable to remount filesystem" msgstr "Não é possível remontar o sistema de arquivos" diff --git a/shared-module/displayio/OnDiskBitmap.c b/shared-module/displayio/OnDiskBitmap.c index bc30646326..76d8fb2d14 100644 --- a/shared-module/displayio/OnDiskBitmap.c +++ b/shared-module/displayio/OnDiskBitmap.c @@ -56,42 +56,65 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self, uint16_t bits_per_pixel = bmp_header[14]; uint32_t compression = read_word(bmp_header, 15); uint32_t number_of_colors = read_word(bmp_header, 23); + + bool indexed = ((bits_per_pixel <= 8) && (number_of_colors != 0)); self->bitfield_compressed = (compression == 3); - - self->grayscale = ((bits_per_pixel == 8) && (number_of_colors == 256)); + self->bits_per_pixel = bits_per_pixel; + self->width = read_word(bmp_header, 9); + self->height = read_word(bmp_header, 11); + if (bits_per_pixel == 16){ - if (((header_size == 124) || (header_size == 56)) && (self->bitfield_compressed)) { + if (((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 + } else { // no compression or short header means 5:5:5 self->r_bitmask = 0x7c00; self->g_bitmask = 0x3e0; self->b_bitmask = 0x1f; } + } else if ((indexed) && (self->bits_per_pixel != 1)) { + uint16_t palette_size = number_of_colors * sizeof(uint32_t); + uint16_t palette_offset = 0xe + header_size; - } else if (!(header_size == 12 || header_size == 40 || header_size == 108 || header_size == 124) || - !(compression == 0)) { + self->palette_data = m_malloc(palette_size, false); + + f_rewind(&self->file->fp); + f_lseek(&self->file->fp, palette_offset); + + UINT palette_bytes_read; + if (f_read(&self->file->fp, self->palette_data, palette_size, &palette_bytes_read) != FR_OK) { + mp_raise_OSError(MP_EIO); + } + if (palette_bytes_read != palette_size) { + mp_raise_ValueError(translate("Unable to read color palette data")); + } + + + } else if (!(header_size == 12 || header_size == 40 || header_size == 108 || header_size == 124)) { mp_raise_ValueError_varg(translate("Only Windows format, uncompressed BMP supported %d"), header_size); } - 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); + if ((bits_per_pixel == 4 ) || (( bits_per_pixel == 8) && (number_of_colors == 0))) { + mp_raise_ValueError_varg(translate("Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d"), bits_per_pixel); } - self->bytes_per_pixel = bits_per_pixel / 8; - self->width = read_word(bmp_header, 9); - self->height = read_word(bmp_header, 11); - uint32_t byte_width = self->width * self->bytes_per_pixel; - self->stride = byte_width; - // Rows are word aligned. - if (self->stride % 4 != 0) { - self->stride += 4 - self->stride % 4; + + if (self->bits_per_pixel >=8){ + self->stride = (self->width * (bits_per_pixel / 8)); + // Rows are word aligned. + if (self->stride % 4 != 0) { + self->stride += 4 - self->stride % 4; + } + + } else { + uint32_t bit_stride = self->width; + if (bit_stride % 32 != 0) { + bit_stride += 32 - bit_stride % 32; + } + self->stride = (bit_stride / 8); } + } @@ -100,39 +123,54 @@ uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *s if (x < 0 || x >= self->width || y < 0 || y >= self->height) { return 0; } - uint32_t location = self->data_offset + (self->height - y) * self->stride + x * self->bytes_per_pixel; + uint32_t location; + uint8_t bytes_per_pixel = (self->bits_per_pixel / 8) ? (self->bits_per_pixel /8) : 1; + if (self->bits_per_pixel >= 8){ + location = self->data_offset + (self->height - y) * self->stride + x * bytes_per_pixel; + } else { + location = self->data_offset + (self->height - y) * self->stride + x / 8; + } // We don't cache here because the underlying FS caches sectors. f_lseek(&self->file->fp, location); UINT bytes_read; - uint32_t pixel = 0; - uint32_t result = f_read(&self->file->fp, &pixel, self->bytes_per_pixel, &bytes_read); + uint32_t pixel = 0; // this name is stale + uint32_t result = f_read(&self->file->fp, &pixel, bytes_per_pixel, &bytes_read); if (result == FR_OK) { 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); + if (self->bits_per_pixel == 1){ + uint8_t bit_offset = x%8; + tmp = ( pixel & (0x80 >> (bit_offset))) >> (7 - bit_offset); + if (tmp == 1) { + return 0x00FFFFFF; + } else { + return 0x00000000; + } + } else if (bytes_per_pixel == 1){ + blue = ((self->palette_data[pixel] & 0xFF) >> 0); + red = ((self->palette_data[pixel] & 0xFF0000) >> 16); + green = ((self->palette_data[pixel] & 0xFF00) >> 8); + tmp = (red << 16 | green << 8 | blue ); return tmp; - } else if (self->bytes_per_pixel == 2) { - if (self->bitfield_compressed){ + } else if (bytes_per_pixel == 2) { + if (self->g_bitmask == 0x07e0){ // 565 red =((pixel & self->r_bitmask) >>11); green = ((pixel & self->g_bitmask) >>5); blue = ((pixel & self->b_bitmask) >> 0); - } else { + } else { // 555 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 { + }else if ((bytes_per_pixel == 4) && (self->bitfield_compressed)){ + return pixel & 0x00FFFFFF; + } else { return pixel; } - } return 0; } diff --git a/shared-module/displayio/OnDiskBitmap.h b/shared-module/displayio/OnDiskBitmap.h index 2102863d68..28426f11b8 100644 --- a/shared-module/displayio/OnDiskBitmap.h +++ b/shared-module/displayio/OnDiskBitmap.h @@ -44,9 +44,9 @@ typedef struct { uint32_t g_bitmask; uint32_t b_bitmask; bool bitfield_compressed; - bool grayscale; pyb_file_obj_t* file; - uint8_t bytes_per_pixel; + uint8_t bits_per_pixel; + uint32_t* palette_data; } displayio_ondiskbitmap_t; #endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_ONDISKBITMAP_H From 014595bff593e51012483515adf92e21c7126f5d Mon Sep 17 00:00:00 2001 From: Bryan Siepert Date: Fri, 1 Mar 2019 07:16:14 -0800 Subject: [PATCH 2/3] fixed whitespace, clarified variable name, and updated error messages --- locale/ID.po | 9 ++++--- locale/circuitpython.pot | 9 ++++--- locale/de_DE.po | 14 +++++++--- locale/en_US.po | 9 ++++--- locale/es.po | 14 +++++++--- locale/fil.po | 14 +++++++--- locale/fr.po | 14 +++++++--- locale/it_IT.po | 14 +++++++--- locale/pt_BR.po | 14 +++++++--- shared-module/displayio/OnDiskBitmap.c | 36 +++++++++++++------------- 10 files changed, 96 insertions(+), 51 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index c0b1dafdbd..f5fadce49f 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-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -760,14 +760,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "Hanya 8 atau 16 bit mono dengan " #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" msgid "Only slices with step=1 (aka None) are supported" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index ea6b26c3f8..0808ae43e5 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-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -734,14 +734,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "" #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" msgid "Only slices with step=1 (aka None) are supported" diff --git a/locale/de_DE.po b/locale/de_DE.po index ff9cafc763..941a5d5d16 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-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -752,15 +752,18 @@ msgid "Only 8 or 16 bit mono with " msgstr "Nur 8 oder 16 bit mono mit " #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" -msgstr "Nur unkomprimiertes Windows-Format (BMP) unterstützt %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" +msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "" "Es werden nur Bitmaps mit einer Farbtiefe von 8 Bit oder weniger unterstützt" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" msgid "Only slices with step=1 (aka None) are supported" @@ -2138,3 +2141,6 @@ msgstr "y Wert außerhalb der Grenzen" msgid "zero step" msgstr "" + +#~ msgid "Only Windows format, uncompressed BMP supported %d" +#~ msgstr "Nur unkomprimiertes Windows-Format (BMP) unterstützt %d" diff --git a/locale/en_US.po b/locale/en_US.po index 45596fb620..01cbaeb510 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-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -734,14 +734,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "" #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" msgid "Only slices with step=1 (aka None) are supported" diff --git a/locale/es.po b/locale/es.po index 996d58df66..a4eceb1fb8 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-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -774,14 +774,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "Solo mono de 8 o 16 bit con " #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" -msgstr "Solo formato Windows, BMP sin comprimir soportado %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" +msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Solo se admiten bit maps de color de 8 bits o menos" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" #, fuzzy @@ -2164,5 +2167,8 @@ msgstr "address fuera de límites" msgid "zero step" msgstr "paso cero" +#~ msgid "Only Windows format, uncompressed BMP supported %d" +#~ msgstr "Solo formato Windows, BMP sin comprimir soportado %d" + #~ 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 af5046d7c2..fb6002a574 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-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -772,14 +772,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "Tanging 8 o 16 na bit mono na may " #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" -msgstr "Tanging Windows format, uncompressed BMP lamang ang supportado %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" +msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Tanging bit maps na may 8 bit color o mas mababa ang supportado" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" #, fuzzy @@ -2170,5 +2173,8 @@ msgstr "wala sa sakop ang address" msgid "zero step" msgstr "zero step" +#~ msgid "Only Windows format, uncompressed BMP supported %d" +#~ msgstr "Tanging Windows format, uncompressed BMP lamang ang supportado %d" + #~ 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 3fde90bde7..c937a4b5ba 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-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: 2018-12-23 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -776,14 +776,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "Uniquement 8 ou 16 bit mono avec " #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" -msgstr "Seul les BMP non-compressé au format Windows sont supportés %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" +msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Seules les bitmaps de 8bits par couleur ou moins sont supportées" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" #, fuzzy @@ -2194,5 +2197,8 @@ msgstr "adresse hors limites" msgid "zero step" msgstr "'step' nul" +#~ msgid "Only Windows format, uncompressed BMP supported %d" +#~ msgstr "Seul les BMP non-compressé au format Windows sont supportés %d" + #~ 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 ea1a42b119..64fb22128f 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-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -771,14 +771,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "" #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" -msgstr "Formato solo di Windows, BMP non compresso supportato %d" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" +msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Sono supportate solo bitmap con colori a 8 bit o meno" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" #, fuzzy @@ -2166,5 +2169,8 @@ msgstr "indirizzo fuori limite" msgid "zero step" msgstr "zero step" +#~ msgid "Only Windows format, uncompressed BMP supported %d" +#~ msgstr "Formato solo di Windows, BMP non compresso supportato %d" + #~ 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 8477e14786..cf46dfbc58 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-28 23:07-0800\n" +"POT-Creation-Date: 2019-03-01 07:16-0800\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -760,14 +760,17 @@ msgid "Only 8 or 16 bit mono with " msgstr "" #, c-format -msgid "Only Windows format, uncompressed BMP supported %d" -msgstr "Apenas formato Windows, BMP descomprimido suportado" +msgid "" +"Only Windows format, uncompressed BMP supported: given header size is %d" +msgstr "" msgid "Only bit maps of 8 bit color or less are supported" msgstr "Apenas bit maps de cores de 8 bit ou menos são suportados" #, c-format -msgid "Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d" +msgid "" +"Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp " +"given" msgstr "" msgid "Only slices with step=1 (aka None) are supported" @@ -2114,5 +2117,8 @@ msgstr "" msgid "zero step" msgstr "passo zero" +#~ msgid "Only Windows format, uncompressed BMP supported %d" +#~ msgstr "Apenas formato Windows, BMP descomprimido suportado" + #~ 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 76d8fb2d14..92735e53cf 100644 --- a/shared-module/displayio/OnDiskBitmap.c +++ b/shared-module/displayio/OnDiskBitmap.c @@ -93,11 +93,11 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self, } else if (!(header_size == 12 || header_size == 40 || header_size == 108 || header_size == 124)) { - mp_raise_ValueError_varg(translate("Only Windows format, uncompressed BMP supported %d"), header_size); + mp_raise_ValueError_varg(translate("Only Windows format, uncompressed BMP supported: given header size is %d"), header_size); } if ((bits_per_pixel == 4 ) || (( bits_per_pixel == 8) && (number_of_colors == 0))) { - mp_raise_ValueError_varg(translate("Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d"), bits_per_pixel); + mp_raise_ValueError_varg(translate("Only monochrome, indexed 8bpp, and 16bpp or greater BMPs supported: %d bpp given"), bits_per_pixel); } if (self->bits_per_pixel >=8){ @@ -133,8 +133,8 @@ uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *s // We don't cache here because the underlying FS caches sectors. f_lseek(&self->file->fp, location); UINT bytes_read; - uint32_t pixel = 0; // this name is stale - uint32_t result = f_read(&self->file->fp, &pixel, bytes_per_pixel, &bytes_read); + uint32_t pixel_data = 0; // this name is stale + uint32_t result = f_read(&self->file->fp, &pixel_data, bytes_per_pixel, &bytes_read); if (result == FR_OK) { uint32_t tmp = 0; uint8_t red; @@ -142,34 +142,34 @@ uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *s uint8_t blue; if (self->bits_per_pixel == 1){ uint8_t bit_offset = x%8; - tmp = ( pixel & (0x80 >> (bit_offset))) >> (7 - bit_offset); + tmp = ( pixel_data & (0x80 >> (bit_offset))) >> (7 - bit_offset); if (tmp == 1) { return 0x00FFFFFF; } else { return 0x00000000; } } else if (bytes_per_pixel == 1){ - blue = ((self->palette_data[pixel] & 0xFF) >> 0); - red = ((self->palette_data[pixel] & 0xFF0000) >> 16); - green = ((self->palette_data[pixel] & 0xFF00) >> 8); + blue = ((self->palette_data[pixel_data] & 0xFF) >> 0); + red = ((self->palette_data[pixel_data] & 0xFF0000) >> 16); + green = ((self->palette_data[pixel_data] & 0xFF00) >> 8); tmp = (red << 16 | green << 8 | blue ); return tmp; } else if (bytes_per_pixel == 2) { - if (self->g_bitmask == 0x07e0){ // 565 - red =((pixel & self->r_bitmask) >>11); - green = ((pixel & self->g_bitmask) >>5); - blue = ((pixel & self->b_bitmask) >> 0); + if (self->g_bitmask == 0x07e0) { // 565 + red =((pixel_data & self->r_bitmask) >>11); + green = ((pixel_data & self->g_bitmask) >>5); + blue = ((pixel_data & self->b_bitmask) >> 0); } else { // 555 - red =((pixel & self->r_bitmask) >>10); - green = ((pixel & self->g_bitmask) >>4); - blue = ((pixel & self->b_bitmask) >> 0); + red =((pixel_data & self->r_bitmask) >>10); + green = ((pixel_data & self->g_bitmask) >>4); + blue = ((pixel_data & self->b_bitmask) >> 0); } tmp = (red << 19 | green << 10 | blue << 3); return tmp; - }else if ((bytes_per_pixel == 4) && (self->bitfield_compressed)){ - return pixel & 0x00FFFFFF; + } else if ((bytes_per_pixel == 4) && (self->bitfield_compressed)) { + return pixel_data & 0x00FFFFFF; } else { - return pixel; + return pixel_data; } } return 0; From 76dc8e1ac861b11d01c2e82ecfdbaea761c84fd0 Mon Sep 17 00:00:00 2001 From: Bryan Siepert Date: Fri, 1 Mar 2019 07:32:46 -0800 Subject: [PATCH 3/3] fixed typo --- shared-module/displayio/OnDiskBitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/displayio/OnDiskBitmap.c b/shared-module/displayio/OnDiskBitmap.c index 92735e53cf..d710bdae03 100644 --- a/shared-module/displayio/OnDiskBitmap.c +++ b/shared-module/displayio/OnDiskBitmap.c @@ -133,7 +133,7 @@ uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *s // We don't cache here because the underlying FS caches sectors. f_lseek(&self->file->fp, location); UINT bytes_read; - uint32_t pixel_data = 0; // this name is stale + uint32_t pixel_data = 0; uint32_t result = f_read(&self->file->fp, &pixel_data, bytes_per_pixel, &bytes_read); if (result == FR_OK) { uint32_t tmp = 0;