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

Function bm_iff_parse_body

bitmap/iff.cpp:210–291  ·  view source on GitHub ↗

the buffer pointed to by raw_data is stuffed with a pointer to decompressed pixel data

Source from the content-addressed store, hash-verified

208
209// the buffer pointed to by raw_data is stuffed with a pointer to decompressed pixel data
210int bm_iff_parse_body(CFILE *ifile, int len, iff_bitmap_header *bmheader) {
211 uint8_t *p = bmheader->raw_data;
212 int width = 0, depth = 0, done = 0;
213
214 if (bmheader->type == TYPE_PBM) {
215 width = bmheader->w;
216 depth = 1;
217 } else if (bmheader->type == TYPE_ILBM) {
218 width = (bmheader->w + 7) / 8;
219 depth = bmheader->nplanes;
220 }
221
222 if (bmheader->compression == cmpNone) // no compression
223 {
224 for (int y = 0; y < bmheader->h; y++) {
225 int x;
226
227 for (x = 0; x < width * depth; x++)
228 *p++ = cf_ReadByte(ifile);
229
230 if (bmheader->masking == mskHasMask) {
231 for (int i = 0; i < width; i++)
232 cf_ReadByte(ifile); // skip mask!
233 }
234
235 if (bmheader->w & 1)
236 cf_ReadByte(ifile);
237 }
238
239 } else if (bmheader->compression == cmpByteRun1) // compression
240 {
241 uint8_t *data_end = p + (bmheader->h * depth * width);
242 uint8_t mask = (bmheader->masking == mskHasMask);
243 int cur_width = 0, skip_mask = 0;
244 int command;
245 int plane = 0;
246
247 while (!done) {
248 if (p >= data_end) {
249 done = 1;
250 continue;
251 }
252 if (cur_width == width) {
253 plane++;
254 if ((plane == depth && !mask) || (plane == depth + 1 && mask)) {
255 skip_mask = 0;
256 plane = 0;
257 }
258
259 if (mask && plane == depth)
260 skip_mask = 1;
261
262 cur_width = 0;
263 }
264
265 command = cf_ReadByte(ifile);
266 if (command >= 0 && command <= 127) {
267 if (!skip_mask) {

Callers 1

bm_iff_parse_fileFunction · 0.85

Calls 1

cf_ReadByteFunction · 0.85

Tested by

no test coverage detected