X11 wide tilemap support
- support X11 tile files (with or without XPM) that are 40 tiles wide - rearrange some X11 code to share more code between XPM & non-XPM options - clean out some deprecated X11/winmap.c #ifdefs - update Qt code minimally to handle such an XPM file
This commit is contained in:
+42
-26
@@ -15,7 +15,7 @@
|
||||
|
||||
|
||||
x11_header header;
|
||||
unsigned char tile_bytes[TILE_X*TILE_Y*MAX_GLYPH];
|
||||
unsigned char tile_bytes[TILE_X*TILE_Y*(MAX_GLYPH+TILES_PER_ROW)];
|
||||
unsigned char *curr_tb = tile_bytes;
|
||||
unsigned char x11_colormap[MAXCOLORMAPSIZE][3];
|
||||
|
||||
@@ -44,8 +44,9 @@ pix_to_colormap(pix)
|
||||
|
||||
/* Convert the tiles in the file to our format of bytes. */
|
||||
static unsigned long
|
||||
convert_tiles(tb_ptr)
|
||||
convert_tiles(tb_ptr, total)
|
||||
unsigned char **tb_ptr; /* pointer to a tile byte pointer */
|
||||
unsigned long total; /* total tiles so far */
|
||||
{
|
||||
unsigned char *tb = *tb_ptr;
|
||||
unsigned long count = 0;
|
||||
@@ -54,12 +55,20 @@ convert_tiles(tb_ptr)
|
||||
|
||||
while (read_text_tile(tile)) {
|
||||
count++;
|
||||
for (y = 0; y < TILE_Y; y++)
|
||||
total++;
|
||||
for (y = 0; y < TILE_Y; y++) {
|
||||
for (x = 0; x < TILE_X; x++)
|
||||
*tb++ = pix_to_colormap(tile[y][x]);
|
||||
tb[x] = pix_to_colormap(tile[y][x]);
|
||||
tb += TILE_X * header.per_row;
|
||||
}
|
||||
|
||||
/* repoint at the upper-left corner of the next tile */
|
||||
*tb_ptr += TILE_X;
|
||||
if (header.per_row == 1 || (total % header.per_row) == 0)
|
||||
*tb_ptr += TILE_X * (TILE_Y - 1) * header.per_row;
|
||||
tb = *tb_ptr;
|
||||
}
|
||||
|
||||
*tb_ptr = tb; /* update return val */
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -108,9 +117,9 @@ process_file(fname)
|
||||
if (!fopen_text_file(fname, RDTMODE)) {
|
||||
Fprintf(stderr, "can't open file \"%s\"\n", fname);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
merge_text_colormap();
|
||||
count = convert_tiles(&curr_tb);
|
||||
count = convert_tiles(&curr_tb, header.ntiles);
|
||||
Fprintf(stderr, "%s: %lu tiles\n", fname, count);
|
||||
header.ntiles += count;
|
||||
fclose_text_file();
|
||||
@@ -122,7 +131,7 @@ static int
|
||||
xpm_write(fp)
|
||||
FILE *fp;
|
||||
{
|
||||
int i,j,n;
|
||||
int i, j, n;
|
||||
|
||||
if (header.ncolors > 64) {
|
||||
Fprintf(stderr, "Sorry, only configured for up to 64 colors\n");
|
||||
@@ -130,34 +139,32 @@ FILE *fp;
|
||||
/* All you need to do is add more char per color - below */
|
||||
}
|
||||
|
||||
fprintf(fp, "/* XPM */\n");
|
||||
fprintf(fp, "static char* nhtiles[] = {\n");
|
||||
fprintf(fp, "\"%lu %lu %lu %d\",\n",
|
||||
header.tile_width,
|
||||
header.tile_height*header.ntiles,
|
||||
Fprintf(fp, "/* XPM */\n");
|
||||
Fprintf(fp, "static char* nhtiles[] = {\n");
|
||||
Fprintf(fp, "\"%lu %lu %lu %d\",\n",
|
||||
header.tile_width*header.per_row,
|
||||
(header.tile_height*header.ntiles)/header.per_row,
|
||||
header.ncolors,
|
||||
1 /* char per color */);
|
||||
for (i = 0; i < header.ncolors; i++)
|
||||
fprintf(fp, "\"%c c #%02x%02x%02x\",\n",
|
||||
Fprintf(fp, "\"%c c #%02x%02x%02x\",\n",
|
||||
i+'0', /* just one char per color */
|
||||
x11_colormap[i][0],
|
||||
x11_colormap[i][1],
|
||||
x11_colormap[i][2]);
|
||||
|
||||
n=0;
|
||||
for (i = 0; i < header.tile_height*header.ntiles; i++) {
|
||||
fprintf(fp, "\"");
|
||||
for (j = 0; j < header.tile_width; j++) {
|
||||
n = 0;
|
||||
for (i = 0; i < (header.tile_height*header.ntiles)/header.per_row; i++) {
|
||||
Fprintf(fp, "\"");
|
||||
for (j = 0; j < header.tile_width*header.per_row; j++) {
|
||||
/* just one char per color */
|
||||
fputc(tile_bytes[n++]+'0', fp);
|
||||
}
|
||||
if (j==header.tile_width-1)
|
||||
fprintf(fp, "\"\n");
|
||||
else
|
||||
fprintf(fp, "\",\n");
|
||||
|
||||
Fprintf(fp, "\",\n");
|
||||
}
|
||||
|
||||
return fprintf(fp, "};\n")>=0;
|
||||
return fprintf(fp, "};\n") >= 0;
|
||||
}
|
||||
#endif /* USE_XPM */
|
||||
|
||||
@@ -169,11 +176,12 @@ main(argc, argv)
|
||||
FILE *fp;
|
||||
int i;
|
||||
|
||||
header.version = 1;
|
||||
header.version = 2; /* version 1 had no per_row field */
|
||||
header.ncolors = 0;
|
||||
header.tile_width = TILE_X;
|
||||
header.tile_height = TILE_Y;
|
||||
header.ntiles = 0; /* updated as we read in files */
|
||||
header.per_row = TILES_PER_ROW;
|
||||
|
||||
if (argc == 1) {
|
||||
Fprintf(stderr, "usage: %s txt_file1 [txt_file2 ...]\n", argv[0]);
|
||||
@@ -184,12 +192,20 @@ main(argc, argv)
|
||||
if (!fp) {
|
||||
Fprintf(stderr, "can't open output file\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* don't leave garbage at end of partial row */
|
||||
(void) memset((genericptr_t)tile_bytes, 0, sizeof(tile_bytes));
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
process_file(argv[i]);
|
||||
Fprintf(stderr, "Total tiles: %ld\n", header.ntiles);
|
||||
|
||||
/* round size up to the end of the row */
|
||||
if ((header.ntiles % header.per_row) != 0) {
|
||||
header.ntiles += header.per_row - (header.ntiles % header.per_row);
|
||||
}
|
||||
|
||||
#ifdef USE_XPM
|
||||
if (xpm_write(fp) == 0) {
|
||||
Fprintf(stderr, "can't write XPM file\n");
|
||||
@@ -199,7 +215,7 @@ main(argc, argv)
|
||||
if (fwrite((char *)&header, sizeof(x11_header), 1, fp) == 0) {
|
||||
Fprintf(stderr, "can't open output header\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (fwrite((char *)x11_colormap, 1, header.ncolors*3, fp) == 0) {
|
||||
Fprintf(stderr, "can't write output colormap\n");
|
||||
|
||||
Reference in New Issue
Block a user