Files
edgetx-gx12/util/xbm2lbm.rb
T
mihlit@mihlit.cz 14676ab361 make sure splash start and end markers have correct position
Compiler can change position of start/end splash markers or even optimize-out
them completely, because they are not used in the fw. 
Make them part of the splash data block, so their possition is always correct.
util/xbm2lbm was changed together with other c "images" to make it consitent.
2012-02-02 22:48:15 +00:00

52 lines
857 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("%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
}
}
}
end
main(ARGV[0])