/* Convert the tiles in the file to our format of bytes. */ static unsigned long convert_tiles(unsigned char **tb_ptr, long unsigned int total) /* pointer to a tile byte pointer */ /* total tiles so far */ { unsigned char *tb = *tb_ptr; unsigned long count = 0; pixel tile[TILE_Y][TILE_X]; int x, y; while (read_text_tile(tile)) { count++; total++; for (y = 0; y < TILE_Y; y++) { for (x = 0; x < TILE_X; 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; } return count; }
main(int argc, char **argv) { int colors; struct { long nplanes; long pbytes; long across; long down; long npics; long xsize; long ysize; } pdat; long pbytes; /* Bytes of data in a plane */ int i, cnt; BitMapHeader bmhd; struct IFFHandle *iff; long camg = HIRES | LACE; int tiles = 0; char **planes; if (argc != 3) { fprintf(stderr, "Usage: %s source destination\n", argv[0]); exit(1); } #if defined(_DCC) || defined(__GNUC__) IFFParseBase = OpenLibrary("iffparse.library", 0); if (!IFFParseBase) { error("unable to open iffparse.library"); exit(1); } #endif /* First, count the files in the file */ if (fopen_text_file(argv[1], "r") != TRUE) { perror(argv[1]); return (1); } nplanes = 0; i = colorsinmap - 1; /*IFFScreen.Colors - 1; */ while (i != 0) { nplanes++; i >>= 1; } planes = malloc(nplanes * sizeof(char *)); if (planes == 0) { error("can not allocate planes pointer"); exit(1); } while (read_text_tile(pixels) == TRUE) ++tiles; fclose_text_file(); IFFScreen.Width = COLS * TILE_X; IFFScreen.Height = ROWS * TILE_Y; pbytes = (COLS * ROWS * TILE_X + 15) / 16 * 2 * TILE_Y; for (i = 0; i < nplanes; ++i) { planes[i] = calloc(1, pbytes); if (planes[i] == 0) { error("can not allocate planes pointer"); exit(1); } } /* Now, process it */ if (fopen_text_file(argv[1], "r") != TRUE) { perror(argv[1]); return (1); } iff = AllocIFF(); if (!iff) { error("Can not allocate IFFHandle"); return (1); } iff->iff_Stream = Open(argv[2], MODE_NEWFILE); if (!iff->iff_Stream) { error("Can not open output file"); return (1); } InitIFFasDOS(iff); OpenIFF(iff, IFFF_WRITE); PushChunk(iff, ID_BMAP, ID_FORM, IFFSIZE_UNKNOWN); bmhd.w = IFFScreen.Width; bmhd.h = IFFScreen.Height; bmhd.x = 0; bmhd.y = 0; bmhd.nPlanes = nplanes; bmhd.masking = 0; bmhd.compression = 0; bmhd.reserved1 = 0; bmhd.transparentColor = 0; bmhd.xAspect = 100; bmhd.yAspect = 100; bmhd.pageWidth = TILE_X; bmhd.pageHeight = TILE_Y; PushChunk(iff, ID_BMAP, ID_BMHD, sizeof(bmhd)); WriteChunkBytes(iff, &bmhd, sizeof(bmhd)); PopChunk(iff); PushChunk(iff, ID_BMAP, ID_CAMG, sizeof(camg)); WriteChunkBytes(iff, &camg, sizeof(camg)); PopChunk(iff); /* We need to reorder the colors to get reasonable default pens but * we also need to know where some of the colors are - so go find out. */ map_colors(); cmap = malloc((colors = (1L << nplanes)) * sizeof(AmiColorMap)); for (i = 0; i < colors; ++i) { cmap[colrmap[i]].r = ColorMap[CM_RED][i]; cmap[colrmap[i]].g = ColorMap[CM_GREEN][i]; cmap[colrmap[i]].b = ColorMap[CM_BLUE][i]; } PushChunk(iff, ID_BMAP, ID_CMAP, IFFSIZE_UNKNOWN); for (i = 0; i < colors; ++i) WriteChunkBytes(iff, &cmap[i], 3); PopChunk(iff); cnt = 0; while (read_text_tile(pixels) == TRUE) { packwritebody(pixels, planes, cnt); if (cnt % 20 == 0) printf("%d..", cnt); ++cnt; fflush(stdout); } pdat.nplanes = nplanes; pdat.pbytes = pbytes; pdat.xsize = TILE_X; pdat.ysize = TILE_Y; pdat.across = COLS; pdat.down = ROWS; pdat.npics = cnt; PushChunk(iff, ID_BMAP, ID_PDAT, IFFSIZE_UNKNOWN); WriteChunkBytes(iff, &pdat, sizeof(pdat)); PopChunk(iff); PushChunk(iff, ID_BMAP, ID_PLNE, IFFSIZE_UNKNOWN); for (i = 0; i < nplanes; ++i) WriteChunkBytes(iff, planes[i], pbytes); PopChunk(iff); CloseIFF(iff); Close(iff->iff_Stream); FreeIFF(iff); printf("\n%d tiles converted\n", cnt); #if defined(_DCC) || defined(__GNUC__) CloseLibrary(IFFParseBase); #endif exit(0); }
int main(int argc, char *argv[]) { int i; if (argc != 2) { Fprintf(stderr, "usage: tile2img outfile.img\n"); exit(EXIT_FAILURE); } else strcpy(bmpname, argv[1]); #ifdef OBSOLETE bmpfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE); if (bmpfile2 == (FILE *)0) { Fprintf(stderr, "Unable to open output file %s\n", NETHACK_PACKED_TILEFILE); exit(EXIT_FAILURE); } #endif tilecount = 0; xoffset = yoffset = 0; initflag = 0; filenum = 0; fp = fopen(bmpname,"wb"); if (!fp) { printf("Error creating tile file %s, aborting.\n",bmpname); exit(1); } fclose(fp); Bild_daten=(unsigned int **)malloc(MAX_Y*sizeof(unsigned int *)); for(i=0;i<MAX_Y;i++) Bild_daten[i]=(unsigned int *)malloc(MAX_X*sizeof(unsigned int)); while (filenum < 3) { if (!fopen_text_file(tilefiles[filenum], RDTMODE)) { Fprintf(stderr, "usage: tile2img (from the util directory)\n"); exit(EXIT_FAILURE); } num_colors = colorsinmap; if (num_colors > 62) { Fprintf(stderr, "too many colors (%d)\n", num_colors); exit(EXIT_FAILURE); } while (read_text_tile(tilepixels)) { build_ximgtile(tilepixels); tilecount++; xoffset += TILE_X; if (xoffset >= MAX_X) { yoffset += TILE_Y; xoffset = 0; } } (void) fclose_text_file(); ++filenum; } Fprintf(stderr, "Total of %d tiles in memory.\n",tilecount); bitmap_to_file(XIMG, MAX_X, (tilecount/20+1)*16, 372, 372, 4, 16, bmpname, get_color, get_pixel ) ; Fprintf(stderr, "Total of %d tiles written to %s.\n",tilecount, bmpname); exit(EXIT_SUCCESS); /*NOTREACHED*/ return 0; }