Files
edgetx-gx12/util/xbm2lbm.rb
T
2011-12-13 19:13:00 +00:00

54 lines
940 B
Ruby

#! /usr/bin/env ruby
require 'pp'
def main(xbm)
base=xbm.sub(/\.xbm/,"")
cols,rows=1,1
if base.sub! /_(\d+)x(\d+)/,""
rows,cols = $1.to_i,$2.to_i
end
File.read(xbm)=~/_width\s+(\d+).*_height\s+(\d+).*\{(.*)\}/m
w,h,bits=$1.to_i,$2.to_i,$3
bits=eval "["+bits+"]"
#pp w,h,bits
wb=(w+7)/8
hb=(h+7)/8
out=Array.new(w*hb,0)
#pp out
h.times{|yp| yb=yp/8; msk= 1 << (yp%8)
w.times{|xp| xb=xp/8; msk2=1 << (xp%8)
out[yb*w+xp]|=msk if bits[wb*yp+xb]&msk2 != 0
}
}
#pp out
#prog_uchar img_4sticks_18x8[] = {
##include "sticks_lcd.h"
#};
File.open("#{base}.lbm","w"){|f|
col=0
f.printf("prog_uchar APM %s[] = {\n",base.sub(/.*\//,""))
f.printf("%d,%d,\n",w/cols,h/rows)
rows.times{|row|
(hb/rows).times{|yb| yb
w.times{|xp|
f.printf("0x%02x,",out[row*w + yb*w + xp])
}
f.puts
}
}
f.printf("};\n")
}
end
main(ARGV[0])