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
|
# File 'lib/parsers/bmp_parser.rb', line 9
def call(io)
io = FormatParser::IOConstraint.new(io)
magic_number, _file_size, _reserved1, _reserved2, = safe_read(io, 14).unpack('A2Vv2V')
return unless VALID_BMP == magic_number
return unless == PIXEL_ARRAY_OFFSET
= safe_read(io, 40)
, width, height, _planes, _bits_per_pixel,
_compression_method, _image_size, horizontal_res,
vertical_res, _n_colors, _i_colors = .unpack('Vl<2v2V2l<2V2')
data_order = height < 0 ? :inverse : :normal
FormatParser::Image.new(
format: :bmp,
width_px: width,
height_px: height.abs,
color_mode: :rgb,
intrinsics: {
vertical_resolution: vertical_res,
horizontal_resolution: horizontal_res,
data_order: data_order
}
)
end
|