|
32 | 32 | __version__ = "0.0.0-auto.0" |
33 | 33 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad.git" |
34 | 34 |
|
35 | | -def load(f, *, bitmap=None, palette=None): |
36 | | - f.seek(10) |
37 | | - data_start = int.from_bytes(f.read(4), 'little') |
| 35 | +def load(file, *, bitmap=None, palette=None): |
| 36 | + """Loads a bmp image from the open ``file``. |
| 37 | +
|
| 38 | + Returns tuple of bitmap object and palette object. |
| 39 | +
|
| 40 | + :param object bitmap: Type to store bitmap data. Must have API similar to `displayio.Bitmap`. |
| 41 | + Will be skipped if None |
| 42 | + :param object palette: Type to store the palette. Must have API similar to |
| 43 | + `displayio.Palette`. Will be skipped if None""" |
| 44 | + file.seek(10) |
| 45 | + data_start = int.from_bytes(file.read(4), 'little') |
38 | 46 | # f.seek(14) |
39 | | - # bmp_header_length = int.from_bytes(f.read(4), 'little') |
| 47 | + # bmp_header_length = int.from_bytes(file.read(4), 'little') |
40 | 48 | # print(bmp_header_length) |
41 | | - f.seek(18) |
42 | | - width = int.from_bytes(f.read(4), 'little') |
43 | | - height = int.from_bytes(f.read(4), 'little') |
44 | | - f.seek(28) |
45 | | - color_depth = int.from_bytes(f.read(2), 'little') |
46 | | - f.seek(46) |
47 | | - colors = int.from_bytes(f.read(4), 'little') |
48 | | - |
49 | | - compute_palette = False |
| 49 | + file.seek(18) |
| 50 | + width = int.from_bytes(file.read(4), 'little') |
| 51 | + height = int.from_bytes(file.read(4), 'little') |
| 52 | + file.seek(28) |
| 53 | + color_depth = int.from_bytes(file.read(2), 'little') |
| 54 | + file.seek(46) |
| 55 | + colors = int.from_bytes(file.read(4), 'little') |
| 56 | + |
50 | 57 | if colors == 0 and color_depth >= 16: |
51 | 58 | raise NotImplementedError("True color BMP unsupported") |
52 | 59 | else: |
53 | 60 | if colors == 0: |
54 | 61 | colors = 2 ** color_depth |
55 | 62 | from . import indexed |
56 | | - return indexed.load(f, width, height, data_start, colors, color_depth, bitmap=bitmap, palette=palette) |
| 63 | + return indexed.load(file, width, height, data_start, colors, color_depth, bitmap=bitmap, |
| 64 | + palette=palette) |
0 commit comments