+static inline unsigned scale6to8(unsigned x)
+{
+ assert(x <= 0x3f);
+
+ return x*0xff / 0x3f;
+}
+
+/* Scale the 18-bit LBX palette into a 24-bit PNG palette. */
+static void fill_png_palette(png_color *out, const struct lbx_colour *in)
+{
+ for (unsigned i = 0; i < 256; i++) {
+ out[i] = (struct png_color_struct) {
+ .red = scale6to8(in[i].red),
+ .green = scale6to8(in[i].green),
+ .blue = scale6to8(in[i].blue),
+ };
+ }
+}
+