+static void pam_format_rgba(unsigned char *rowbuf, const unsigned char *pixels,
+ unsigned char *mask, unsigned width,
+ unsigned long offset, struct lbx_colour *palette)
+{
+ unsigned x;
+
+ for (x = 0; x < width; x++) {
+ struct lbx_colour val = palette[pixels[offset+x]];
+ unsigned vis = 1 & ( mask[(offset+x)/CHAR_BIT]
+ >> ((offset+x)%CHAR_BIT) );
+
+ if (sizeof val == 4) {
+ memcpy(rowbuf+4ul*x, &val, 4);
+ } else {
+ rowbuf[4ul*x+0] = val.red;
+ rowbuf[4ul*x+1] = val.green;
+ rowbuf[4ul*x+2] = val.blue;
+ }
+ rowbuf[4ul*x+3] = -vis & 0x3f;
+ }
+}
+
+static void pam_format_rgb(unsigned char *rowbuf, const unsigned char *pixels,
+ unsigned width, unsigned long offset,
+ struct lbx_colour *palette)
+{
+ unsigned x;
+
+ for (x = 0; x < width; x++) {
+ struct lbx_colour val = palette[pixels[offset+x]];
+
+ if (sizeof val == 4) {
+ memcpy(rowbuf+3ul*x, &val, 4);
+ } else {
+ rowbuf[3ul*x+0] = val.red;
+ rowbuf[3ul*x+1] = val.green;
+ rowbuf[3ul*x+2] = val.blue;
+ }
+ }
+}
+
+static void pam_format_ga(unsigned char *rowbuf,
+ const unsigned char *pixels, const unsigned char *mask,
+ unsigned width, unsigned long offset)
+{
+ unsigned x;
+
+ for (x = 0; x < width; x++) {
+ unsigned vis = 1 & ( mask[(offset+x)/CHAR_BIT]
+ >> ((offset+x)%CHAR_BIT) );
+
+ rowbuf[2ul*x+0] = pixels[offset+x];
+ rowbuf[2ul*x+1] = -vis & 0xff;
+ }
+}
+
+static void pam_format_g(unsigned char *rowbuf, const unsigned char *pixels,
+ unsigned width, unsigned long offset)
+{
+ memcpy(rowbuf, pixels+offset, width);
+}
+