1 /* SCCS Id: @(#)tile2bmp.c 3.2 95/09/06 */
2 /* Copyright (c) NetHack PC Development Team 1995 */
3 /* NetHack 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 */
22 extern char *FDECL(tilename, (int, int));
23 static void FDECL(build_ximgtile,(pixel (*)[TILE_X]));
24 void get_color(unsigned int colind, struct RGB *rgb);
25 void get_pixel(int x, int y, unsigned int *colind);
28 #define MAX_X 320 /* 2 per byte, 4 bits per pixel */
36 pixel tilepixels[TILE_Y][TILE_X];
38 char *tilefiles[] = { "..\\win\\share\\monsters.txt",
39 "..\\win\\share\\objects.txt",
40 "..\\win\\share\\other.txt"};
42 unsigned int **Bild_daten;
45 int max_tiles_in_row = 40;
61 Fprintf(stderr, "usage: tile2img outfile.img\n");
64 strcpy(bmpname, argv[1]);
67 bmpfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE);
68 if (bmpfile2 == (FILE *)0) {
69 Fprintf(stderr, "Unable to open output file %s\n",
70 NETHACK_PACKED_TILEFILE);
76 xoffset = yoffset = 0;
79 fp = fopen(bmpname,"wb");
81 printf("Error creating tile file %s, aborting.\n",bmpname);
86 Bild_daten=(unsigned int **)malloc(MAX_Y*sizeof(unsigned int *));
88 Bild_daten[i]=(unsigned int *)malloc(MAX_X*sizeof(unsigned int));
91 if (!fopen_text_file(tilefiles[filenum], RDTMODE)) {
93 "usage: tile2img (from the util directory)\n");
96 num_colors = colorsinmap;
97 if (num_colors > 62) {
98 Fprintf(stderr, "too many colors (%d)\n", num_colors);
101 while (read_text_tile(tilepixels)) {
102 build_ximgtile(tilepixels);
105 if (xoffset >= MAX_X) {
110 (void) fclose_text_file();
113 Fprintf(stderr, "Total of %d tiles in memory.\n",tilecount);
115 bitmap_to_file(XIMG, MAX_X, (tilecount/20+1)*16, 372, 372, 4, 16, bmpname, get_color, get_pixel ) ;
117 Fprintf(stderr, "Total of %d tiles written to %s.\n",tilecount, bmpname);
124 void get_color(unsigned int colind, struct RGB *rgb){
125 rgb->r=(1000L*(long)ColorMap[CM_RED][colind])/0xFF;
126 rgb->g=(1000L*(long)ColorMap[CM_GREEN][colind])/0xFF;
127 rgb->b=(1000L*(long)ColorMap[CM_BLUE][colind])/0xFF;
130 void get_pixel(int x, int y, unsigned int *colind){
131 *colind=Bild_daten[y][x];
135 build_ximgtile(pixels)
136 pixel (*pixels)[TILE_X];
138 int cur_x, cur_y, cur_color;
141 for (cur_y = 0; cur_y < TILE_Y; cur_y++) {
142 for (cur_x = 0; cur_x < TILE_X; cur_x++) {
143 for (cur_color = 0; cur_color < num_colors; cur_color++) {
144 if (ColorMap[CM_RED][cur_color] == pixels[cur_y][cur_x].r &&
145 ColorMap[CM_GREEN][cur_color] == pixels[cur_y][cur_x].g &&
146 ColorMap[CM_BLUE][cur_color] == pixels[cur_y][cur_x].b)
149 if (cur_color >= num_colors)
150 Fprintf(stderr, "color not in colormap!\n");
153 Bild_daten[y][x] =cur_color;