+
+void wrtiles_carr(FILE *fp, const char *name, struct image *timg, int ntiles)
+{
+ int i, j, curx = 0;
+ unsigned char *ptr = timg->pixels;
+
+ fprintf(fp, "\nint %s_num_tiles = %d;\n", name, ntiles);
+ fprintf(fp, "int %s_tiles_width = %d;\n", name, timg->width);
+ fprintf(fp, "int %s_tiles_height = %d;\n", name, timg->height);
+ fprintf(fp, "int %s_tiles_bpp = %d;\n", name, timg->bpp);
+ fprintf(fp, "unsigned char %s_tiles[] = {\n", name);
+
+ for(i=0; i<timg->height; i++) {
+ for(j=0; j<timg->scansz; j++) {
+ if(curx == 0) {
+ curx = 3 + fprintf(fp, "\t%u", (unsigned int)*ptr++);
+ } else {
+ curx += fprintf(fp, ", %u", (unsigned int)*ptr++);
+ }
+ if(curx >= 80) {
+ fprintf(fp, ",\n");
+ curx = 0;
+ }
+ }
+ ptr += timg->pitch - timg->scansz;
+ }
+
+ fprintf(fp, "\n};\n\n");
+}
+
+void wrtilemap_carr(FILE *fp, const char *name, int *tmap, int xtiles, int ytiles)
+{
+ int i, sz, curx = 0;
+
+ fprintf(fp, "\nint %s_tilemap_cols = %d;\n", name, xtiles);
+ fprintf(fp, "int %s_tilemap_rows = %d;\n", name, ytiles);
+ fprintf(fp, "unsigned int %s_tilemap[] = {\n", name);
+
+ sz = xtiles * ytiles;
+ for(i=0; i<sz; i++) {
+ if(curx == 0) {
+ curx = 3 + fprintf(fp, "\t%u", (unsigned int)tmap[i]);
+ } else {
+ curx += fprintf(fp, ", %u", (unsigned int)tmap[i]);
+ }
+ if(curx >= 80) {
+ fprintf(fp, ",\n");
+ curx = 0;
+ }
+ }
+
+ fprintf(fp, "\n};\n\n");
+}
+
+void wrpalette_carr(FILE *fp, const char *name, struct cmapent *cmap, int ncol)
+{
+ int i;
+
+ fprintf(fp, "\nint %s_cmap_colors = %d;\n", name, ncol);
+ fprintf(fp, "unsigned char %s_cmap[][3] = {\n", name);
+ for(i=0; i<ncol; i++) {
+ fprintf(fp, "\t{%u, %u, %u}", cmap[i].r, cmap[i].g, cmap[i].b);
+ if(i < ncol - 1) {
+ fputs(",\n", fp);
+ } else {
+ fputc('\n', fp);
+ }
+ }
+ fprintf(fp, "};\n\n");
+}