| 1 |
package palgen |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
"image/color" |
| 6 |
"os" |
| 7 |
) |
| 8 |
|
| 9 |
// ACT converts a given palette to the Photoshop ACT Palette Format (.act) |
| 10 |
// There is no header, just either 768 or 772 bytes of color data. |
| 11 |
// 256 * 3 = 768. The four extra bytes can be 16-bit color count + 16 bit transparent color index. |
| 12 |
func ACT(pal color.Palette) []byte { |
| 13 |
var buf bytes.Buffer |
| 14 |
// Output the colors |
| 15 |
for _, c := range pal { |
| 16 |
cn := c.(color.RGBA) |
| 17 |
buf.WriteByte(cn.R) |
| 18 |
buf.WriteByte(cn.G) |
| 19 |
buf.WriteByte(cn.B) |
| 20 |
} |
| 21 |
// Return the generated string |
| 22 |
return buf.Bytes() |
| 23 |
} |
| 24 |
|
| 25 |
// SaveACT can save a palette to file in the Photoship ACT Palette Format (.act) |
| 26 |
func SaveACT(pal color.Palette, filename string) error { |
| 27 |
return os.WriteFile(filename, ACT(pal), 0644) |
| 28 |
} |