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

Function main

outdated/win/gem/xpm2img.c:26–86  ·  view source on GitHub ↗
(argc, argv)

Source from the content-addressed store, hash-verified

24int initflag;
25FILE *fp;
26int
27main(argc, argv)
28int argc;
29char *argv[];
30{
31 int i;
32 int row, col, planeno;
33 int farben, planes;
34 if (argc != 3) {
35 fprintf(stderr, "usage: tile2img infile.xpm outfile.img\n");
36 exit(EXIT_FAILURE);
37 }
38 initflag = 0;
39 fp = fopen(argv[2], "wb");
40 if (!fp) {
41 printf("Error creating IMG-file %s, aborting.\n", argv[2]);
42 exit(EXIT_FAILURE);
43 }
44 fclose(fp);
45 if (fopen_xpm_file(argv[1], "r") != TRUE) {
46 printf("Error reading xpm-file %s, aborting.\n", argv[1]);
47 exit(EXIT_FAILURE);
48 }
49 Bild_daten =
50 (unsigned int **) malloc((long) height * sizeof(unsigned int *));
51 for (i = 0; i < height; i++)
52 Bild_daten[i] =
53 (unsigned int *) malloc((long) width * sizeof(unsigned int));
54 for (row = 0; row < height; row++) {
55 char *xb = xpmgetline();
56 int plane_offset;
57 if (xb == 0) {
58 printf("Error to few lines in xpm-file %s, aborting.\n", argv[1]);
59 exit(EXIT_FAILURE);
60 }
61 for (col = 0; col < width; col++) {
62 int color = xb[col];
63 if (!ttable[color].flag)
64 fprintf(stderr, "Bad image data\n");
65 Bild_daten[row][col] = ttable[color].slot;
66 }
67 }
68 if (num_colors > 256) {
69 fprintf(stderr, "ERROR: zuviele Farben\n");
70 exit(EXIT_FAILURE);
71 } else if (num_colors > 16) {
72 farben = 256;
73 planes = 8;
74 } else if (num_colors > 2) {
75 farben = 16;
76 planes = 4;
77 } else {
78 farben = 2;
79 planes = 1;
80 }
81 bitmap_to_file(XIMG, width, height, 372, 372, planes, farben, argv[2],
82 get_color, get_pixel);
83 exit(EXIT_SUCCESS);

Callers

nothing calls this directly

Calls 6

fprintfFunction · 0.85
printfFunction · 0.85
fcloseFunction · 0.85
fopen_xpm_fileFunction · 0.85
bitmap_to_fileFunction · 0.85
xpmgetlineFunction · 0.70

Tested by

no test coverage detected