MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / bm_iff_parse_delta

Function bm_iff_parse_delta

bitmap/iff.cpp:302–365  ·  view source on GitHub ↗

modify passed bitmap

Source from the content-addressed store, hash-verified

300
301// modify passed bitmap
302int bm_iff_parse_delta(CFILE *ifile, int len, iff_bitmap_header *bmheader) {
303 uint8_t *p = bmheader->raw_data;
304 int y;
305 int32_t chunk_end = cftell(ifile) + len;
306
307 cf_ReadInt(ifile); // longword, seems to be equal to 4. Don't know what it is
308
309 for (y = 0; y < bmheader->h; y++) {
310 uint8_t n_items;
311 int cnt = bmheader->w;
312 uint8_t code;
313
314 n_items = cf_ReadByte(ifile);
315
316 while (n_items--) {
317 code = cf_ReadByte(ifile);
318
319 if (code == 0) {
320 uint8_t rep, val;
321
322 rep = cf_ReadByte(ifile);
323 val = cf_ReadByte(ifile);
324
325 cnt -= rep;
326 if (cnt == -1)
327 rep--;
328 while (rep--)
329 *p++ = val;
330 } else if (code > 0x80) { // skip
331 cnt -= (code - 0x80);
332 p += (code - 0x80);
333 if (cnt == -1)
334 p--;
335 } else { // literal
336 cnt -= code;
337 if (cnt == -1)
338 code--;
339
340 while (code--)
341 *p++ = cf_ReadByte(ifile);
342
343 if (cnt == -1)
344 cf_ReadByte(ifile);
345 }
346 }
347
348 if (cnt == -1) {
349 if (!bmheader->w & 1)
350 return IFF_CORRUPT;
351 } else if (cnt)
352 return IFF_CORRUPT;
353 }
354
355 if (cftell(ifile) == chunk_end - 1) // pad
356 cf_ReadByte(ifile);
357
358 if (cftell(ifile) != chunk_end) {
359 Int3();

Callers 1

bm_iff_parse_fileFunction · 0.85

Calls 3

cftellFunction · 0.85
cf_ReadIntFunction · 0.85
cf_ReadByteFunction · 0.85

Tested by

no test coverage detected