# SPDX-License-Identifier: LGPL-3.0-or-later # Copyright (C) 2021 Francesco Gazzetta """Image gallery ~~~~~~~~~~~~~~~~~~~~~~~~~ An application that shows images stored in the filesystem. .. figure:: res/screenshots/GalleryApp.png :width: 179 The images have to be uploaded in the "gallery" directory. The images have to be encoded as BMP RGB565 data in big endian byte order. To encode them, you can use GIMP (File → Export, select the BMP format, set "R5 G6 B5" in "Advanced Options"), or ImageMagick: .. code-block:: sh convert -define bmp:subtype=RGB565 my_image.png my_image.bmp And to upload: .. code-block:: sh ./tools/wasptool --binary --upload my_image.bmp --as gallery/my_image """ import wasp import icons from apps.system.pager import PagerApp class GalleryApp(): NAME = 'Gallery' # 2-bit RLE, 96x64, generated from res/gallery_icon.png, 370 bytes ICON = ( b'\x02' b'`@' b'\x1e@\x81d= 2147483648: height = 4294967296 - height bottom_up = False else: bottom_up = True if width > 240 or height > 240: # check size <= 240x240 self._invalid_file(filename) return file.seek(0x1C) bit_count = int.from_bytes(file.read(2), 'little') if bit_count != 16: # check 16 bpp self._invalid_file(filename) return compression = int.from_bytes(file.read(4), 'little') if compression != 3: # check bitmask mode self._invalid_file(filename) return file.seek(0x36) bitmask = file.read(4), file.read(4), file.read(4) if bitmask != (b'\x00\xF8\x00\x00', b'\xE0\x07\x00\x00', b'\x1F\x00\x00\x00'): # check bitmask RGB565 self._invalid_file(filename) return display.set_window((240 - width) // 2, 0, width, height) file.seek(data_offset) # We don't have enough memory to load the entire image at once, so # we stream it from flash memory to the display buf = display.linebuffer[:2*width] for y in reversed(range(0, height)): if bottom_up: file.seek(data_offset + y * width * 2) file.readinto(buf) for x in range(0, width): buf[x*2], buf[x*2+1] = buf[x*2+1], buf[x*2] display.write_data(buf) file.close()