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

Function ReadImageFile

sys/amiga/winchar.c:183–253  ·  view source on GitHub ↗

* Read a single BMAP IFF file into a BitMap. * Returns the BitMapHeader; *bmp receives the bitmap. * Caller frees via FreeImageFile(). */

Source from the content-addressed store, hash-verified

181 * Caller frees via FreeImageFile().
182 */
183BitMapHeader
184ReadImageFile(const char *filename, struct BitMap **bmp)
185{
186 BitMapHeader *bmhd, bmhds;
187 int j, np;
188 struct IFFHandle *iff;
189 struct StoredProperty *prop;
190
191 IFFParseBase = OpenLibrary("iffparse.library", 0L);
192 if (!IFFParseBase)
193 panic("No iffparse.library");
194
195 iff = AllocIFF();
196 if (!iff)
197 panic("can't start IFF processing");
198
199 iff->iff_Stream = Open(filename, MODE_OLDFILE);
200 if (iff->iff_Stream == 0)
201 panic("Can't open %s", filename);
202
203 InitIFFasDOS(iff);
204 OpenIFF(iff, IFFF_READ);
205 PropChunk(iff, ID_BMAP, ID_BMHD);
206 PropChunk(iff, ID_BMAP, ID_CMAP);
207 PropChunk(iff, ID_BMAP, ID_PDAT);
208 StopChunk(iff, ID_BMAP, ID_PLNE);
209 if ((j = ParseIFF(iff, IFFPARSE_SCAN)) != 0)
210 panic("ParseIFF failed on %s, code %d",
211 filename, j);
212
213 prop = FindProp(iff, ID_BMAP, ID_BMHD);
214 if (!prop)
215 panic("No BMHD chunk in %s", filename);
216 bmhd = (BitMapHeader *) prop->sp_Data;
217 np = bmhd->nPlanes;
218
219 /* Load CMAP into palette arrays if present */
220 prop = FindProp(iff, ID_BMAP, ID_CMAP);
221 if (prop) {
222 unsigned char *cmap = prop->sp_Data;
223 for (j = 0; j < (1L << np) * 3; j += 3) {
224 amii_initmap[j / 3] =
225 amiv_init_map[j / 3] =
226 ((cmap[j+0] >> 4) << 8)
227 | ((cmap[j+1] >> 4) << 4)
228 | (cmap[j+2] >> 4);
229 }
230 }
231
232 /* Load PDAT if present */
233 prop = FindProp(iff, ID_BMAP, ID_PDAT);
234 if (prop)
235 pictdata = *(struct PDAT *) prop->sp_Data;
236
237 *bmp = MyAllocBitMap(bmhd->w, bmhd->h,
238 np, MEMF_CHIP | MEMF_CLEAR);
239 if (!*bmp)
240 panic("Can't allocate bitmap for %s", filename);

Callers 2

ReadTileImageFilesFunction · 0.85
amii_outripFunction · 0.85

Calls 2

MyAllocBitMapFunction · 0.85
panicFunction · 0.70

Tested by

no test coverage detected