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
|
# File 'lib/imageruby-bmp.rb', line 64
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
|