#!/usr/bin/env ruby

lines = File.read("palette.ppm").split("\n")
lines = lines.select { |l| l[0] != "#" }

raise "Not an ASCII ppm" if lines.shift != "P3"
raise "Incorrect dimensions" unless lines.shift == "1 256"
raise "Incorrect maxval" unless lines.shift == "255"
raise "Too many lines left" unless lines.size == 768

puts <<EOF
package data

import "image/color"

var (
	Transparent = color.RGBA{R: 0, G: 0, B: 0, A: 0}

	ColorPalette = color.Palette{
		Transparent,
EOF

lines.shift(3) # Ignore idx 0

255.times do
  r, g, b = lines.shift(3).map(&:to_i)

  puts "\t\tcolor.RGBA{R: #{r}, G: #{g}, B: #{b}, A: 255},"
end

puts <<EOF
	}
)
EOF
