Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- image = ChunkyPNG::Image.from_file('source.png')
- bytes = Array.new(0)
- bytes = []
- done = ""
- image.to_alpha_channel_stream.split("").each { |byte| bytes << byte.to_s.unpack('B*')[0][0] }
- (0..image.to_alpha_channel_stream.length/8).each {|n| bits = bytes.shift(8); done << bits.join.to_i(2); }
- File.open("alpha_bitplane.bin", 'wb') { |file| file.write(done) }
- puts "Wrote #{done.length} bytes: alpha_bitplane.bin"
- bytes = []
- done = ""
- red = image.to_rgb_stream.unpack('axx'*(image.to_rgb_stream.length/3)).join
- red.split("").each { |byte| bytes << byte.to_s.unpack('B*')[0][0] }
- (0..image.to_rgb_stream.length/24).each {|n| bits = bytes.shift(8); done << bits.join.to_i(2); }
- File.open("red_bitplane.bin", 'wb') { |file| file.write(done) }
- puts "Wrote #{done.length} bytes: red_bitplane.bin"
- bytes = []
- done = ""
- green = image.to_rgb_stream.unpack('xax'*(image.to_rgb_stream.length/3)).join
- green.split("").each { |byte| bytes << byte.to_s.unpack('B*')[0][0] }
- (0..image.to_rgb_stream.length/24).each {|n| bits = bytes.shift(8); done << bits.join.to_i(2); }
- File.open("green_bitplane.bin", 'wb') { |file| file.write(done) }
- puts "Wrote #{done.length} bytes: green_bitplane.bin"
- bytes = []
- done = ""
- blue = image.to_rgb_stream.unpack('xxa'*(image.to_rgb_stream.length/3)).join
- blue.split("").each { |byte| bytes << byte.to_s.unpack('B*')[0][0] }
- (0..image.to_rgb_stream.length/24).each {|n| bits = bytes.shift(8); done << bits.join.to_i(2); }
- File.open("blue_bitplane.bin", 'wb') { |file| file.write(done) }
- puts "Wrote #{done.length} bytes: blue_bitplane.bin"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement