Created
March 29, 2013 09:49
-
-
Save southwolf/5269921 to your computer and use it in GitHub Desktop.
Pebble font resource to pbm(the most close format I can think of to the pebble res) converter **Faulty**
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Image | |
attr_accessor :width, :height, :bitmap | |
end | |
img = Image.new | |
hexmap = nil | |
File.open('font1', 'rb') do |f| | |
data = f.read | |
img.width = data[0].ord | |
img.height = data[1].ord | |
img.bitmap = "" | |
hexmap = data[8..-1].unpack("H*")[0] # hex string. Caution when begin with ZERO. cannot use to_i(16).to_s(2)!! | |
end | |
hexmap.each_char do |c| | |
bin = c.to_i(16).to_s(2) | |
(4 - bin.length).times { bin = "0" + bin } | |
img.bitmap = img.bitmap + bin | |
end | |
File.open('img1.pbm', 'wb') do |o| | |
o.puts('P1') | |
o.puts("#{img.width} #{img.height}") | |
img.bitmap.each_char.with_index do |c,i| | |
o.write(c) | |
if((i+1) % img.width == 0) | |
o.puts | |
else | |
o.write(' ') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment