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

Function bitmap_to_img

outdated/win/gem/bitmfile.c:50–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48typedef struct RGB XIMG_RGB;
49
50int
51bitmap_to_img(FILE_TYP typ, int ww, int wh, unsigned int pixw,
52 unsigned int pixh, unsigned int planes, unsigned int colors,
53 const char *filename,
54 void (*get_color)(unsigned int colind, struct RGB *rgb),
55 void (*get_pixel)(int x, int y, unsigned int *colind))
56{
57 int file, error, cnt;
58 IMG_HEADER header;
59 XIMG_HEADER xheader;
60 XIMG_RGB xrgb;
61 IMG_MODE mode;
62 UBYTE *line_buf, *write_buf;
63 register UBYTE *startpnt, *bufpnt;
64 unsigned int colind, line_len, line, bit;
65 register unsigned int byte;
66 register UBYTE count;
67
68 /* fill in (X) IMG-Header */
69
70 header.img_version = 1;
71 header.img_headlen = (UWORD) sizeof(header) / 2;
72 if (typ == XIMG)
73 header.img_headlen +=
74 (UWORD)(sizeof(xheader) + colors * sizeof(xrgb)) / 2;
75
76 header.img_nplanes = planes;
77 header.img_patlen = 2;
78 header.img_pixw = pixw;
79 header.img_pixh = pixh;
80 header.img_w = ww;
81 header.img_h = wh;
82
83 xheader.img_ximg = XIMG_MAGIC;
84 xheader.img_colmodel = RGB;
85
86 /* calculate linelength, allocate buffer. */
87
88 line_len = (ww + 7) / 8;
89
90 line_buf = malloc((size_t) planes * line_len);
91 if (line_buf == NULL)
92 return (ENOMEM);
93
94 /* Worst case: the bufferd line could grow to max. 3 times the length */
95 /* of the original!
96 */
97
98 write_buf = malloc((size_t) 3 * line_len);
99 if (write_buf == NULL) {
100 free(line_buf);
101 return (ENOMEM);
102 };
103
104 /* open file */
105
106 file = open(filename, O_WRONLY | O_CREAT | O_TRUNC);
107 if (file < 0) {

Callers 1

bitmap_to_fileFunction · 0.85

Calls 5

openFunction · 0.85
writeFunction · 0.85
closeFunction · 0.85
get_colorFunction · 0.70
get_pixelFunction · 0.70

Tested by

no test coverage detected