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
|
# File 'lib/imageruby-bmp.rb', line 25
def decode(data, image_class)
= data[0..13]
= data[14..54]
magic = [0..1]
unless magic == "BM"
raise UnableToDecodeException
end
pixeldata_offset = [10..13].unpack("L").first
width = [4..7].unpack("L").first
height = [8..11].unpack("L").first
image = image_class.new(width,height)
padding_size = ( 4 - (width * 3 % 4) ) % 4
width_array_len = width*3 + padding_size
height.times do |y|
offset = pixeldata_offset+(height-y-1)*width_array_len
index = (y*width)*3
image.pixel_data[index..index+width*3] = data[offset..offset+width*3]
end
image
end
|