- png_set_PLTE(png, info, png_palette, 256);
- png_set_rows(png, info, framedata);
- png_write_png(png, info, PNG_TRANSFORM_IDENTITY, NULL);
- } else {
- /*
- * Unfortunately, LBX doesn't translate nicely to PNG here.
- * LBX has a 256 colour palette _plus_ transparency.
- * We'll form an RGBA PNG to deal with this.
- */
-
- png_set_IHDR(png, info, width, height, 8,
- PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
- PNG_COMPRESSION_TYPE_DEFAULT,
- PNG_FILTER_TYPE_DEFAULT);
-
- png_write_info(png, info);
-
- for (y = 0; y < height; y++) {
- for (x = 0; x < width; x++) {
- row[4*x+0] = palette[framedata[y][x]].red;
- row[4*x+1] = palette[framedata[y][x]].green;
- row[4*x+2] = palette[framedata[y][x]].blue;
- row[4*x+3] = (mask[y][x]) ? -1 : 0;
- }
-
- png_write_row(png, row);
- }
-
- png_write_end(png, NULL);
- }
-
- png_destroy_write_struct(&png, &info);
- fclose(of);
-