lib/ase/writer.rb in ase-1.0.3 vs lib/ase/writer.rb in ase-2.0.0

- old
+ new

@@ -20,43 +20,49 @@ # Number of blocks @file.write_ulong(color_count + (palette_count * 2)) @palettes.each do |palette_name, palette| - # Block start - @file.write_ushort 0xC001 + write_palette(palette_name, palette) + end - # Block length (title is UTF-16 encoded) - @file.write_ulong 4 + (palette_name.length * 2) + @file.write_ulong 0 # Group end block + @file.close + end - # Palette name - @file.write_string palette_name + private - palette.colors.each do |name, color| - # Color start - @file.write_ushort 1 + def write_palette(name, palette) + # Block start + @file.write_ushort 0xC001 - # Block length - @file.write_ulong 22 + (name.length * 2) + # Block length (title is UTF-16 encoded) + @file.write_ulong 4 + (name.length * 2) - # Color name - @file.write_string name + # Palette name + @file.write_string name.to_s - # Color mode - @file.write 'RGB ' + palette.colors.each do |name, color| + write_color(name, color) + end - # Colors - rgb = color.to_rgb.map { |c| c.to_f / 255 } - rgb.each { |c| @file.write [c].pack('F').reverse } - - # End of colors - @file.write_null_byte - end + @file.write_ushort 0xC002 # Group end + end - @file.write_ushort 0xC002 # Group end - @file.write_ulong 0 # Group end block - end + def write_color(name, color) + # Color start + @file.write_ushort 1 - @file.close + # Block length + @file.write_ulong 22 + (name.length * 2) + + # Color name + @file.write_string name + + # Color values + color.write!(@file) + + # End of color + @file.write_null_byte end end end \ No newline at end of file