MCPcopy Create free account
hub / github.com/NetHack/NetHack / xpm_write

Function xpm_write

win/X11/tile2x11.c:129–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127
128#ifdef USE_XPM
129static int
130xpm_write(FILE *fp)
131{
132 unsigned long i, j;
133 unsigned n;
134
135 if (header.ncolors > 64) {
136 Fprintf(stderr, "Sorry, only configured for up to 64 colors\n");
137 exit(1);
138 /* All you need to do is add more char per color - below */
139 }
140
141 Fprintf(fp, "/* XPM */\n");
142 Fprintf(fp, "static char *nhtiles[] = {\n");
143 Fprintf(fp, "\"%lu %lu %lu %d\",\n", header.tile_width * header.per_row,
144 (header.tile_height * header.ntiles) / header.per_row,
145 header.ncolors, 1 /* char per color */);
146 for (i = 0; i < header.ncolors; i++)
147 Fprintf(fp, "\"%c c #%02x%02x%02x\",\n",
148 (char) (i + '0'), /* just one char per color */
149 x11_colormap[i][0], x11_colormap[i][1], x11_colormap[i][2]);
150
151 n = 0;
152 for (i = 0; i < (header.tile_height * header.ntiles) / header.per_row;
153 i++) {
154 Fprintf(fp, "\"");
155 for (j = 0; j < header.tile_width * header.per_row; j++) {
156 /* just one char per color */
157 fputc(tile_bytes[n++] + '0', fp);
158 }
159
160 Fprintf(fp, "\",\n");
161 }
162
163 return fprintf(fp, "};\n") >= 0;
164}
165#endif /* USE_XPM */
166
167int

Callers 1

mainFunction · 0.85

Calls 1

fprintfFunction · 0.85

Tested by

no test coverage detected