Modified gif2c.rb to output GIFs matching the current code in effect_animation.h.
This commit is contained in:
parent
ce0c834326
commit
71c524b2cf
@ -75,7 +75,7 @@ colors = []
|
||||
frames.each do |frame|
|
||||
frame.columns.times do |x|
|
||||
frame.rows.times do |y|
|
||||
color = frame.pixel_color(x, y).to_color(Magick::AllCompliance, true, 8, true)
|
||||
color = frame.pixel_color(x, y).to_color(Magick::AllCompliance, true, 8, true)[1,8].to_i(16)
|
||||
colors << color
|
||||
end
|
||||
end
|
||||
@ -84,19 +84,19 @@ colors = colors.uniq
|
||||
|
||||
STDERR.puts " Found #{colors.count} colors."
|
||||
|
||||
transparent = colors.select{|c| c.end_with? "00"}
|
||||
transparent = colors.select{|c| c & 0xFF == 0}
|
||||
|
||||
STDERR.puts "#{transparent.count} color(s) being transparent."
|
||||
|
||||
# color[0] is "keep the color from the previous frame"
|
||||
# color[1] is "background color"
|
||||
colors = (["#00000012", "#00000013"] + (colors - transparent)).uniq
|
||||
colors = ([0x00000012, 0x00000013] + (colors - transparent)).uniq
|
||||
STDERR.puts "Using #{colors.count} colors."
|
||||
raise "Number of colors has to be 255 or less!" if colors.count>255
|
||||
|
||||
STDERR.puts
|
||||
puts
|
||||
puts "uint32_t #{name}_colors[] = {#{colors.map{|c| "0x" + c[1, 6]}.join(", ")}};"
|
||||
puts "uint8_t animation_#{name}_colors[] PROGMEM = {#{colors[2..-1].map{|c| [c>>24 & 0xFF, c>>16 & 0xFF, c>>8 & 0xFF]}.flatten.join(", ")}};"
|
||||
|
||||
p_frame = nil
|
||||
frames_data = []
|
||||
@ -106,7 +106,7 @@ frames.each_with_index do |frame, index|
|
||||
if index==0 # first frame
|
||||
frame.rows.times do |y|
|
||||
frame.columns.times do |x|
|
||||
color = frame.pixel_color(x, y).to_color(Magick::AllCompliance, true, 8, true)
|
||||
color = frame.pixel_color(x, y).to_color(Magick::AllCompliance, true, 8, true)[1,8].to_i(16)
|
||||
if transparent.include? color
|
||||
data << 1
|
||||
else
|
||||
@ -117,8 +117,8 @@ frames.each_with_index do |frame, index|
|
||||
else
|
||||
frame.rows.times do |y|
|
||||
frame.columns.times do |x|
|
||||
color = frame.pixel_color(x, y).to_color(Magick::AllCompliance, true, 8, true)
|
||||
p_color = p_frame.pixel_color(x, y).to_color(Magick::AllCompliance, true, 8, true)
|
||||
color = frame.pixel_color(x, y).to_color(Magick::AllCompliance, true, 8, true)[1,8].to_i(16)
|
||||
p_color = p_frame.pixel_color(x, y).to_color(Magick::AllCompliance, true, 8, true)[1,8].to_i(16)
|
||||
|
||||
if color==p_color
|
||||
data << 0
|
||||
@ -143,16 +143,16 @@ end
|
||||
|
||||
data = frames_data.map{|d| compress(d, true)}
|
||||
|
||||
puts "uint8_t #{name}_data[] PROGMEM = {\n #{data.map{|d| d.join(",")}.join(",\n ")}\n};"
|
||||
puts "uint16_t #{name}_delays[] = {#{times.join(",")}};"
|
||||
puts "uint8_t animation_#{name}_data[] PROGMEM = {\n #{data.map{|d| d.join(",")}.join(",\n ")}\n};"
|
||||
puts "uint16_t animation_#{name}_delays[] = {#{times.join(",")}};"
|
||||
s=0
|
||||
puts "uint16_t #{name}_offsets[] = {#{(data.map{|d| t=s; s+=d.count; t} + [s]).join(",")}};"
|
||||
puts "uint16_t animation_#{name}_offsets[] = {#{(data.map{|d| t=s; s+=d.count; t} + [s]).join(",")}};"
|
||||
|
||||
puts "AnimationData #{name} = {&#{name}_colors[0], &#{name}_data[0], &#{name}_offsets[0], &#{name}_delays[0], #{individual_frame_times}, #{colors.count}, #{frames_data.count}, #{frames.first.columns}, #{frames.first.rows}};"
|
||||
puts "AnimationData animation_#{name} = {&animation_#{name}_colors[0], &animation_#{name}_data[0], &animation_#{name}_offsets[0], &animation_#{name}_delays[0], #{individual_frame_times}, #{colors.count-2}, #{frames_data.count}, #{frames.first.columns}, #{frames.first.rows}};"
|
||||
puts
|
||||
STDERR.puts
|
||||
STDERR.puts "Space usage:"
|
||||
STDERR.puts " Colors: %6d bytes." % [s1=colors.count * 4] # colors are 3-bytes, but we have to use uint32_t, which takes up 4 bytes.
|
||||
STDERR.puts " Colors: %6d bytes." % [s1=(colors.count-2) * 3] # colors are 3-bytes, but we have to use uint32_t, which takes up 4 bytes.
|
||||
STDERR.puts " Data: %6d bytes." % [s2=data.flatten.count]
|
||||
STDERR.puts " Delays: %6d bytes." % [s5=times.count * 3 + 1]
|
||||
STDERR.puts " Offsets: %6d bytes." % [s3=data.count * 2]
|
||||
|
Loading…
Reference in New Issue
Block a user