1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
from pkg_resources import parse_version
from .kaitaistruct import __version__ as ks_version, KaitaiStruct, KaitaiStream, BytesIO
from enum import Enum
import collections
if parse_version(ks_version) < parse_version('0.7'):
raise Exception("Incompatible Kaitai Struct Python API: 0.7 or later is required, but you have %s" % (ks_version))
class Bmp(KaitaiStruct):
class Compressions(Enum):
rgb = 0
rle8 = 1
rle4 = 2
bitfields = 3
jpeg = 4
png = 5
cmyk = 11
cmyk_rle8 = 12
cmyk_rle4 = 13
SEQ_FIELDS = ["file_hdr", "len_dib_header", "dib_header"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['file_hdr']['start'] = self._io.pos()
self.file_hdr = self._root.FileHeader(self._io, self, self._root)
self.file_hdr._read()
self._debug['file_hdr']['end'] = self._io.pos()
self._debug['len_dib_header']['start'] = self._io.pos()
self.len_dib_header = self._io.read_s4le()
self._debug['len_dib_header']['end'] = self._io.pos()
self._debug['dib_header']['start'] = self._io.pos()
_on = self.len_dib_header
if _on == 104:
self._raw_dib_header = self._io.read_bytes((self.len_dib_header - 4))
io = KaitaiStream(BytesIO(self._raw_dib_header))
self.dib_header = self._root.BitmapCoreHeader(io, self, self._root)
self.dib_header._read()
elif _on == 12:
self._raw_dib_header = self._io.read_bytes((self.len_dib_header - 4))
io = KaitaiStream(BytesIO(self._raw_dib_header))
self.dib_header = self._root.BitmapCoreHeader(io, self, self._root)
self.dib_header._read()
elif _on == 40:
self._raw_dib_header = self._io.read_bytes((self.len_dib_header - 4))
io = KaitaiStream(BytesIO(self._raw_dib_header))
self.dib_header = self._root.BitmapInfoHeader(io, self, self._root)
self.dib_header._read()
elif _on == 124:
self._raw_dib_header = self._io.read_bytes((self.len_dib_header - 4))
io = KaitaiStream(BytesIO(self._raw_dib_header))
self.dib_header = self._root.BitmapCoreHeader(io, self, self._root)
self.dib_header._read()
else:
self.dib_header = self._io.read_bytes((self.len_dib_header - 4))
self._debug['dib_header']['end'] = self._io.pos()
class FileHeader(KaitaiStruct):
"""
.. seealso::
Source - https://msdn.microsoft.com/en-us/library/dd183374.aspx
"""
SEQ_FIELDS = ["magic", "len_file", "reserved1", "reserved2", "ofs_bitmap"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['magic']['start'] = self._io.pos()
self.magic = self._io.ensure_fixed_contents(b"\x42\x4D")
self._debug['magic']['end'] = self._io.pos()
self._debug['len_file']['start'] = self._io.pos()
self.len_file = self._io.read_u4le()
self._debug['len_file']['end'] = self._io.pos()
self._debug['reserved1']['start'] = self._io.pos()
self.reserved1 = self._io.read_u2le()
self._debug['reserved1']['end'] = self._io.pos()
self._debug['reserved2']['start'] = self._io.pos()
self.reserved2 = self._io.read_u2le()
self._debug['reserved2']['end'] = self._io.pos()
self._debug['ofs_bitmap']['start'] = self._io.pos()
self.ofs_bitmap = self._io.read_s4le()
self._debug['ofs_bitmap']['end'] = self._io.pos()
class BitmapCoreHeader(KaitaiStruct):
"""
.. seealso::
Source - https://msdn.microsoft.com/en-us/library/dd183372.aspx
"""
SEQ_FIELDS = ["image_width", "image_height", "num_planes", "bits_per_pixel"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['image_width']['start'] = self._io.pos()
self.image_width = self._io.read_u2le()
self._debug['image_width']['end'] = self._io.pos()
self._debug['image_height']['start'] = self._io.pos()
self.image_height = self._io.read_u2le()
self._debug['image_height']['end'] = self._io.pos()
self._debug['num_planes']['start'] = self._io.pos()
self.num_planes = self._io.read_u2le()
self._debug['num_planes']['end'] = self._io.pos()
self._debug['bits_per_pixel']['start'] = self._io.pos()
self.bits_per_pixel = self._io.read_u2le()
self._debug['bits_per_pixel']['end'] = self._io.pos()
class BitmapInfoHeader(KaitaiStruct):
"""
.. seealso::
Source - https://msdn.microsoft.com/en-us/library/dd183376.aspx
"""
SEQ_FIELDS = ["image_width", "image_height", "num_planes", "bits_per_pixel", "compression", "len_image", "x_px_per_m", "y_px_per_m", "num_colors_used", "num_colors_important"]
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._debug = collections.defaultdict(dict)
def _read(self):
self._debug['image_width']['start'] = self._io.pos()
self.image_width = self._io.read_u4le()
self._debug['image_width']['end'] = self._io.pos()
self._debug['image_height']['start'] = self._io.pos()
self.image_height = self._io.read_u4le()
self._debug['image_height']['end'] = self._io.pos()
self._debug['num_planes']['start'] = self._io.pos()
self.num_planes = self._io.read_u2le()
self._debug['num_planes']['end'] = self._io.pos()
self._debug['bits_per_pixel']['start'] = self._io.pos()
self.bits_per_pixel = self._io.read_u2le()
self._debug['bits_per_pixel']['end'] = self._io.pos()
self._debug['compression']['start'] = self._io.pos()
self.compression = KaitaiStream.resolve_enum(self._root.Compressions, self._io.read_u4le())
self._debug['compression']['end'] = self._io.pos()
self._debug['len_image']['start'] = self._io.pos()
self.len_image = self._io.read_u4le()
self._debug['len_image']['end'] = self._io.pos()
self._debug['x_px_per_m']['start'] = self._io.pos()
self.x_px_per_m = self._io.read_u4le()
self._debug['x_px_per_m']['end'] = self._io.pos()
self._debug['y_px_per_m']['start'] = self._io.pos()
self.y_px_per_m = self._io.read_u4le()
self._debug['y_px_per_m']['end'] = self._io.pos()
self._debug['num_colors_used']['start'] = self._io.pos()
self.num_colors_used = self._io.read_u4le()
self._debug['num_colors_used']['end'] = self._io.pos()
self._debug['num_colors_important']['start'] = self._io.pos()
self.num_colors_important = self._io.read_u4le()
self._debug['num_colors_important']['end'] = self._io.pos()
@property
def image(self):
if hasattr(self, '_m_image'):
return self._m_image if hasattr(self, '_m_image') else None
_pos = self._io.pos()
self._io.seek(self.file_hdr.ofs_bitmap)
self._debug['_m_image']['start'] = self._io.pos()
self._m_image = self._io.read_bytes_full()
self._debug['_m_image']['end'] = self._io.pos()
self._io.seek(_pos)
return self._m_image if hasattr(self, '_m_image') else None
|