Exemplo n.º 1
0
def decode(fileobj):
    try:
        decoder = BMPDecoder(fileobj)
    except:
        fileobj.seek(0)
        return None
    return decoder.get_image()
Exemplo n.º 2
0
 def test_24bit_bmp_decoding(self):
     with open(_get_filepath('black-white-24bit.bmp'), 'rb') as fobj:
         decoder = BMPDecoder(fobj)
         img = decoder.get_image()
     self.assertEqual(img.width, 2)
     self.assertEqual(img.height, 2)
     self.assertEqual(img.palette, None)
     self.assertEqual(decoder.bits_per_pixel, 24)
     self.assertEqual(img.get_color(0, 0), Black)
     self.assertEqual(img.get_color(1, 1), Black)
     self.assertEqual(img.get_color(0, 1), White)
     self.assertEqual(img.get_color(1, 0), White)
Exemplo n.º 3
0
 def test_1bit_bmp_red_white_decoding(self):
     with open(_get_filepath('red-white.bmp'), 'rb') as fobj:
         decoder = BMPDecoder(fobj)
         img = decoder.get_image()
     self.assertEqual(img.width, 2)
     self.assertEqual(img.height, 2)
     self.assertNotEqual(img.palette, None)
     self.assertEqual(decoder.bits_per_pixel, 1)
     self.assertEqual(img.get_color(0, 0), Red)
     self.assertEqual(img.get_color(1, 1), Red)
     self.assertEqual(img.get_color(0, 1), White)
     self.assertEqual(img.get_color(1, 0), White)
Exemplo n.º 4
0
 def test_32bit_bmp_decoding_colorful(self):
     with open(_get_filepath('red-green-blue-black-32bit.bmp'), 'rb') as fobj:
         decoder = BMPDecoder(fobj)
         img = decoder.get_image()
     self.assertEqual(img.width, 2)
     self.assertEqual(img.height, 2)
     self.assertEqual(img.palette, None)
     self.assertEqual(decoder.bits_per_pixel, 32)
     self.assertEqual(img.get_color(0, 0), Red)
     self.assertEqual(img.get_color(1, 0), Lime)
     self.assertEqual(img.get_color(0, 1), Blue)
     self.assertEqual(img.get_color(1, 1), Black)