1 /* aNetHack 0.0.1 tile2img.c $ANH-Date: 1432512809 2015/05/25 00:13:29 $ $ANH-Branch: master $:$ANH-Revision: 1.6 $ */
2 /* Copyright (c) aNetHack PC Development Team 1995 */
3 /* aNetHack may be freely redistributed. See license for details. */
8 * Initial Creation M.Allison 94/01/11
9 * Marvin was here Marvin 97/01/11
13 /* #include <stdlib.h> */
18 /* #define COLORS_IN_USE MAXCOLORMAPSIZE /* 256 colors */
19 #define COLORS_IN_USE 16 /* 16 colors */
21 extern char *FDECL(tilename
, (int, int));
22 static void FDECL(build_ximgtile
, (pixel(*) [TILE_X
]));
23 void get_color(unsigned int colind
, struct RGB
*rgb
);
24 void get_pixel(int x
, int y
, unsigned int *colind
);
26 #if COLORS_IN_USE == 16
27 #define MAX_X 320 /* 2 per byte, 4 bits per pixel */
35 pixel tilepixels
[TILE_Y
][TILE_X
];
37 char *tilefiles
[] = { "..\\win\\share\\monsters.txt",
38 "..\\win\\share\\objects.txt",
39 "..\\win\\share\\other.txt" };
41 unsigned int **Bild_daten
;
44 int max_tiles_in_row
= 40;
60 Fprintf(stderr
, "usage: tile2img outfile.img\n");
63 strcpy(bmpname
, argv
[1]);
66 bmpfile2
= fopen(ANETHACK_PACKED_TILEFILE
, WRBMODE
);
67 if (bmpfile2
== (FILE *) 0) {
68 Fprintf(stderr
, "Unable to open output file %s\n",
69 ANETHACK_PACKED_TILEFILE
);
75 xoffset
= yoffset
= 0;
78 fp
= fopen(bmpname
, "wb");
80 printf("Error creating tile file %s, aborting.\n", bmpname
);
85 Bild_daten
= (unsigned int **) malloc(MAX_Y
* sizeof(unsigned int *));
86 for (i
= 0; i
< MAX_Y
; i
++)
87 Bild_daten
[i
] = (unsigned int *) malloc(MAX_X
* sizeof(unsigned int));
90 if (!fopen_text_file(tilefiles
[filenum
], RDTMODE
)) {
91 Fprintf(stderr
, "usage: tile2img (from the util directory)\n");
94 num_colors
= colorsinmap
;
95 if (num_colors
> 62) {
96 Fprintf(stderr
, "too many colors (%d)\n", num_colors
);
99 while (read_text_tile(tilepixels
)) {
100 build_ximgtile(tilepixels
);
103 if (xoffset
>= MAX_X
) {
108 (void) fclose_text_file();
111 Fprintf(stderr
, "Total of %d tiles in memory.\n", tilecount
);
113 bitmap_to_file(XIMG
, MAX_X
, (tilecount
/ 20 + 1) * 16, 372, 372, 4, 16,
114 bmpname
, get_color
, get_pixel
);
116 Fprintf(stderr
, "Total of %d tiles written to %s.\n", tilecount
, bmpname
);
124 get_color(unsigned int colind
, struct RGB
*rgb
)
126 rgb
->r
= (1000L * (long) ColorMap
[CM_RED
][colind
]) / 0xFF;
127 rgb
->g
= (1000L * (long) ColorMap
[CM_GREEN
][colind
]) / 0xFF;
128 rgb
->b
= (1000L * (long) ColorMap
[CM_BLUE
][colind
]) / 0xFF;
132 get_pixel(int x
, int y
, unsigned int *colind
)
134 *colind
= Bild_daten
[y
][x
];
138 build_ximgtile(pixels
)
139 pixel (*pixels
)[TILE_X
];
141 int cur_x
, cur_y
, cur_color
;
144 for (cur_y
= 0; cur_y
< TILE_Y
; cur_y
++) {
145 for (cur_x
= 0; cur_x
< TILE_X
; cur_x
++) {
146 for (cur_color
= 0; cur_color
< num_colors
; cur_color
++) {
147 if (ColorMap
[CM_RED
][cur_color
] == pixels
[cur_y
][cur_x
].r
148 && ColorMap
[CM_GREEN
][cur_color
] == pixels
[cur_y
][cur_x
].g
149 && ColorMap
[CM_BLUE
][cur_color
] == pixels
[cur_y
][cur_x
].b
)
152 if (cur_color
>= num_colors
)
153 Fprintf(stderr
, "color not in colormap!\n");
156 Bild_daten
[y
][x
] = cur_color
;