test_bmp_indexed_load.py
1 # The MIT License (MIT) 2 # 3 # Copyright (c) 2019 Matt Land 4 # 5 # Permission is hereby granted, free of charge, to any person obtaining a copy 6 # of this software and associated documentation files (the "Software"), to deal 7 # in the Software without restriction, including without limitation the rights 8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 # copies of the Software, and to permit persons to whom the Software is 10 # furnished to do so, subject to the following conditions: 11 # 12 # The above copyright notice and this permission notice shall be included in 13 # all copies or substantial portions of the Software. 14 # 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 # THE SOFTWARE. 22 """ 23 `adafruit_imageload.tests.test_bmp_indexed_load` 24 ==================================================== 25 26 * Author(s): Matt Land 27 28 """ 29 30 import os 31 from unittest import TestCase 32 from adafruit_imageload import load 33 from .displayio_shared_bindings import Bitmap_C_Interface, Palette_C_Interface 34 35 36 class TestBmpIndexedLoad(TestCase): 37 def test_order_bgra_to_rgba(self): 38 test_file = os.path.join( 39 os.path.dirname(__file__), "..", "examples", "images", "4bit.bmp" 40 ) 41 42 bitmap, palette = load( 43 filename=test_file, bitmap=Bitmap_C_Interface, palette=Palette_C_Interface 44 ) 45 self.assertTrue(isinstance(bitmap, Bitmap_C_Interface), bitmap) 46 self.assertEqual(16, bitmap.colors) 47 self.assertEqual(15, bitmap.width) 48 self.assertEqual(17, bitmap.height) 49 50 bitmap.validate() 51 # uncomment line below to see a string representation of the object 52 # self.fail(str(bitmap)) 53 self.assertEqual(5, bitmap[0]) # check first row 54 self.assertEqual(5, bitmap[11, 1]) # check second row 55 56 self.assertEqual(16, palette.num_colors) 57 palette.validate() 58 # make sure bye order swapped 59 self.assertTrue(palette[4] in [b"\x9d\x00\xff\x00", b"\x9d\x00\xff"]) 60 # uncomment line below to see a string representation of the object 61 # self.fail(str(palette))