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
|
# File 'lib/imageruby-bmp-c.rb', line 43
def encode(image, format, output)
unless format == :bmp
raise UnableToEncodeException
end
width = image.width
height = image.height
totalsize = 56 + width * height * 3
output << (totalsize)
output << (image)
output << "\000\000"
padding_size = ( 4 - (width * 3 % 4) ) % 4
padding = "\000" * padding_size
height.times do |y|
index = ((height-y-1)*width)*3
output << image.pixel_data[index..index+width*3-1]
output << padding
end
end
|